From 41f07913e5cc962afbb93539ba0c946cf659cf9d Mon Sep 17 00:00:00 2001 From: pkv Date: Thu, 14 Mar 2024 23:42:44 +0100 Subject: [PATCH] deps/media-playback: Fix hardware decoding of streams Fixes issue #10369. Since the update to FFmpeg 6.1, streams to a Media Source are broken if hardware decoding is enabled (both RTMP or SRT have been reported). The video is black although the audio is decoded fine. The manual copy of metadata introduced in commit [1] does not work any more for some unfathomable reasons. As a fix we call instead the av_frame_copy_props function used in FFmpeg app in a similar context (hardware decoding) [2]. The metadata are copied without issues. There is no need to guard the use of that function since it was introduced 9 years ago in avutil/frame.c. [1] https://github.com/obsproject/obs-studio/commit/22fde5cdcd1c784cd60b8a8cd50af02e7e537182 [2] https://github.com/FFmpeg/FFmpeg/master/fftools/ffmpeg_dec.c Signed-off-by: pkv --- deps/media-playback/media-playback/decode.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/deps/media-playback/media-playback/decode.c b/deps/media-playback/media-playback/decode.c index ec81e3bd0..86f2b689b 100644 --- a/deps/media-playback/media-playback/decode.c +++ b/deps/media-playback/media-playback/decode.c @@ -338,15 +338,12 @@ static int decode_packet(struct mp_decode *d, int *got_frame) } int err = av_hwframe_transfer_data(d->sw_frame, d->hw_frame, 0); + if (err == 0) { + err = av_frame_copy_props(d->sw_frame, d->hw_frame); + } if (err) { ret = 0; *got_frame = false; - } else { - d->sw_frame->color_range = d->hw_frame->color_range; - d->sw_frame->color_primaries = - d->hw_frame->color_primaries; - d->sw_frame->color_trc = d->hw_frame->color_trc; - d->sw_frame->colorspace = d->hw_frame->colorspace; } }