Skip to content

Commit 5f2bb79

Browse files
derrodRytoEX
authored andcommitted
obs-ffmpeg: Fix HDR metadata not being written when using FFmpeg 6.1+
1 parent 0cc6068 commit 5f2bb79

File tree

3 files changed

+72
-70
lines changed

3 files changed

+72
-70
lines changed

plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ static void create_video_stream(struct ffmpeg_mux *ffm)
491491
#endif
492492
ffm->video_stream->avg_frame_rate = av_inv_q(context->time_base);
493493

494+
if (ffm->output->oformat->flags & AVFMT_GLOBALHEADER)
495+
context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
496+
497+
avcodec_parameters_from_context(ffm->video_stream->codecpar, context);
498+
494499
const int max_luminance = ffm->params.max_luminance;
495500
if (max_luminance > 0) {
496501
size_t content_size;
@@ -538,11 +543,6 @@ static void create_video_stream(struct ffmpeg_mux *ffm)
538543
#endif
539544
}
540545

541-
if (ffm->output->oformat->flags & AVFMT_GLOBALHEADER)
542-
context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
543-
544-
avcodec_parameters_from_context(ffm->video_stream->codecpar, context);
545-
546546
ffm->video_ctx = context;
547547
}
548548

plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,38 @@ static bool create_video_stream(struct ffmpeg_output *stream,
156156
}
157157
if (!new_stream(data, &data->video, name))
158158
return false;
159+
160+
context = avcodec_alloc_context3(NULL);
161+
context->codec_type = codec->type;
162+
context->codec_id = codec->id;
163+
context->bit_rate = (int64_t)data->config.video_bitrate * 1000;
164+
context->width = data->config.scale_width;
165+
context->height = data->config.scale_height;
166+
context->coded_width = data->config.scale_width;
167+
context->coded_height = data->config.scale_height;
168+
context->time_base = (AVRational){ovi.fps_den, ovi.fps_num};
169+
context->gop_size = data->config.gop_size;
170+
context->pix_fmt = data->config.format;
171+
context->color_range = data->config.color_range;
172+
context->color_primaries = data->config.color_primaries;
173+
context->color_trc = data->config.color_trc;
174+
context->colorspace = data->config.colorspace;
175+
context->chroma_sample_location = determine_chroma_location(
176+
data->config.format, data->config.colorspace);
177+
context->thread_count = 0;
178+
179+
data->video->time_base = context->time_base;
180+
#if LIBAVFORMAT_VERSION_MAJOR < 59
181+
data->video->codec->time_base = context->time_base;
182+
#endif
183+
data->video->avg_frame_rate = av_inv_q(context->time_base);
184+
185+
data->video_ctx = context;
186+
data->config.width = data->config.scale_width;
187+
data->config.height = data->config.scale_height;
188+
189+
avcodec_parameters_from_context(data->video->codecpar, context);
190+
159191
const bool pq = data->config.color_trc == AVCOL_TRC_SMPTE2084;
160192
const bool hlg = data->config.color_trc == AVCOL_TRC_ARIB_STD_B67;
161193
if (pq || hlg) {
@@ -207,36 +239,6 @@ static bool create_video_stream(struct ffmpeg_output *stream,
207239
(uint8_t *)mastering, sizeof(*mastering), 0);
208240
#endif
209241
}
210-
context = avcodec_alloc_context3(NULL);
211-
context->codec_type = codec->type;
212-
context->codec_id = codec->id;
213-
context->bit_rate = (int64_t)data->config.video_bitrate * 1000;
214-
context->width = data->config.scale_width;
215-
context->height = data->config.scale_height;
216-
context->coded_width = data->config.scale_width;
217-
context->coded_height = data->config.scale_height;
218-
context->time_base = (AVRational){ovi.fps_den, ovi.fps_num};
219-
context->gop_size = data->config.gop_size;
220-
context->pix_fmt = data->config.format;
221-
context->color_range = data->config.color_range;
222-
context->color_primaries = data->config.color_primaries;
223-
context->color_trc = data->config.color_trc;
224-
context->colorspace = data->config.colorspace;
225-
context->chroma_sample_location = determine_chroma_location(
226-
data->config.format, data->config.colorspace);
227-
context->thread_count = 0;
228-
229-
data->video->time_base = context->time_base;
230-
#if LIBAVFORMAT_VERSION_MAJOR < 59
231-
data->video->codec->time_base = context->time_base;
232-
#endif
233-
data->video->avg_frame_rate = av_inv_q(context->time_base);
234-
235-
data->video_ctx = context;
236-
data->config.width = data->config.scale_width;
237-
data->config.height = data->config.scale_height;
238-
239-
avcodec_parameters_from_context(data->video->codecpar, context);
240242

241243
return true;
242244
}

plugins/obs-ffmpeg/obs-ffmpeg-output.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,41 @@ static bool create_video_stream(struct ffmpeg_data *data)
200200
data->config.video_encoder))
201201
return false;
202202

203+
closest_format = data->config.format;
204+
if (data->vcodec->pix_fmts) {
205+
const int has_alpha = closest_format == AV_PIX_FMT_BGRA;
206+
closest_format = avcodec_find_best_pix_fmt_of_list(
207+
data->vcodec->pix_fmts, closest_format, has_alpha,
208+
NULL);
209+
}
210+
211+
context = avcodec_alloc_context3(data->vcodec);
212+
context->bit_rate = (int64_t)data->config.video_bitrate * 1000;
213+
context->width = data->config.scale_width;
214+
context->height = data->config.scale_height;
215+
context->time_base = (AVRational){ovi.fps_den, ovi.fps_num};
216+
context->framerate = (AVRational){ovi.fps_num, ovi.fps_den};
217+
context->gop_size = data->config.gop_size;
218+
context->pix_fmt = closest_format;
219+
context->color_range = data->config.color_range;
220+
context->color_primaries = data->config.color_primaries;
221+
context->color_trc = data->config.color_trc;
222+
context->colorspace = data->config.colorspace;
223+
context->chroma_sample_location = determine_chroma_location(
224+
closest_format, data->config.colorspace);
225+
context->thread_count = 0;
226+
227+
data->video->time_base = context->time_base;
228+
data->video->avg_frame_rate = (AVRational){ovi.fps_num, ovi.fps_den};
229+
230+
if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
231+
context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
232+
233+
data->video_ctx = context;
234+
235+
if (!open_video_codec(data))
236+
return false;
237+
203238
const enum AVColorTransferCharacteristic trc = data->config.color_trc;
204239
const bool pq = trc == AVCOL_TRC_SMPTE2084;
205240
const bool hlg = trc == AVCOL_TRC_ARIB_STD_B67;
@@ -253,41 +288,6 @@ static bool create_video_stream(struct ffmpeg_data *data)
253288
#endif
254289
}
255290

256-
closest_format = data->config.format;
257-
if (data->vcodec->pix_fmts) {
258-
const int has_alpha = closest_format == AV_PIX_FMT_BGRA;
259-
closest_format = avcodec_find_best_pix_fmt_of_list(
260-
data->vcodec->pix_fmts, closest_format, has_alpha,
261-
NULL);
262-
}
263-
264-
context = avcodec_alloc_context3(data->vcodec);
265-
context->bit_rate = (int64_t)data->config.video_bitrate * 1000;
266-
context->width = data->config.scale_width;
267-
context->height = data->config.scale_height;
268-
context->time_base = (AVRational){ovi.fps_den, ovi.fps_num};
269-
context->framerate = (AVRational){ovi.fps_num, ovi.fps_den};
270-
context->gop_size = data->config.gop_size;
271-
context->pix_fmt = closest_format;
272-
context->color_range = data->config.color_range;
273-
context->color_primaries = data->config.color_primaries;
274-
context->color_trc = data->config.color_trc;
275-
context->colorspace = data->config.colorspace;
276-
context->chroma_sample_location = determine_chroma_location(
277-
closest_format, data->config.colorspace);
278-
context->thread_count = 0;
279-
280-
data->video->time_base = context->time_base;
281-
data->video->avg_frame_rate = (AVRational){ovi.fps_num, ovi.fps_den};
282-
283-
if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
284-
context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
285-
286-
data->video_ctx = context;
287-
288-
if (!open_video_codec(data))
289-
return false;
290-
291291
if (context->pix_fmt != data->config.format ||
292292
data->config.width != data->config.scale_width ||
293293
data->config.height != data->config.scale_height) {

0 commit comments

Comments
 (0)