瀏覽代碼

obs-ffmpeg: Fix AVFrame handling in FFmpeg output

Fix an issue in the way AVFrames were handled in the FFmpeg
encoder plugin, which could lead to tearing in the encoded
video due to data races in the AVFrame and AVBuffer.

This is fixed by calling av_frame_make_writable which ensures
the frame and its associated buffer are writable. If its not,
it will copy the AVFrame, create a new AVBuffer for it and
decrease the refcount of the old AVFrame and AVBuffer.
This way OBS always ends up with a usable buffer to write into
which is not still used by the encoder while avoiding a copy
when unnecessary.
Marvin Scholz 5 年之前
父節點
當前提交
9ef263f81a
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      plugins/obs-ffmpeg/obs-ffmpeg-output.c

+ 9 - 0
plugins/obs-ffmpeg/obs-ffmpeg-output.c

@@ -699,6 +699,15 @@ static void receive_video(void *param, struct video_data *frame)
 	if (!data->start_timestamp)
 		data->start_timestamp = frame->timestamp;
 
+	ret = av_frame_make_writable(data->vframe);
+	if (ret < 0) {
+		blog(LOG_WARNING,
+		     "receive_video: Error obtaining writable "
+		     "AVFrame: %s",
+		     av_err2str(ret));
+		//FIXME: stop the encode with an error
+		return;
+	}
 	if (!!data->swscale)
 		sws_scale(data->swscale, (const uint8_t *const *)frame->data,
 			  (const int *)frame->linesize, 0, data->config.height,