Skip to content

Commit 44b1612

Browse files
committed
avcodec/videotoolbox: fix decoding of some hevc videos
See https://s3.amazonaws.com/tmm1/videotoolbox/germany-hevc-zdf.ts Although videotoolbox_buffer_create() sets frame->hw_frames_ctx, by the time videotoolbox_postproc_frame() is called, some frames randomly have frame->hw_frames_ctx == NULL. I don't really understand what's going on, and why this only affects some frames and only in some hevc videos. This patch attempts to detect the missing hw_frames_ctx and reset it in the post_process callback. This is obviously a huge hack, but it does fix playback of the affected samples.
1 parent e0734f7 commit 44b1612

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libavcodec/videotoolbox.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static int videotoolbox_buffer_copy(VTContext *vtctx,
7373

7474
static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
7575
{
76+
VTContext *vtctx = ((AVCodecContext *)avctx)->internal->hwaccel_priv_data;
7677
CVPixelBufferRef ref = *(CVPixelBufferRef *)frame->buf[0]->data;
7778

7879
if (!ref) {
@@ -83,6 +84,11 @@ static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
8384

8485
frame->data[3] = (uint8_t*)ref;
8586

87+
if (!frame->hw_frames_ctx)
88+
frame->hw_frames_ctx = av_buffer_ref(vtctx->cached_hw_frames_ctx);
89+
if (!frame->hw_frames_ctx)
90+
return AVERROR(ENOMEM);
91+
8692
return 0;
8793
}
8894

0 commit comments

Comments
 (0)