Fix for http://f265.org/bugs/ticket/1
We didn't port the B frame bugfix properly from cli.c.
Thanks,
Laurent
diff --git a/cli/cli.c b/cli/cli.c
index 7ad9e26..ec01f81 100644
--- a/cli/cli.c
+++ b/cli/cli.c
@@ -354,6 +354,7 @@ int read_nonyuv_frame(video_data *v)
#elif defined F265_USE_NEW_LIBAV
int byte_used = avcodec_decode_video2(ifd->codec_ctx, ifd->frame, &frame_flag, &packet);
#endif
+
/* We're done if the codec outputted a frame. */
if ((byte_used > 0) | frame_flag) done_flag = !!frame_flag;
diff --git a/yuvdiff/yuvdiff.c b/yuvdiff/yuvdiff.c
index 5ef4737..386186b 100644
--- a/yuvdiff/yuvdiff.c
+++ b/yuvdiff/yuvdiff.c
@@ -728,29 +728,26 @@ int read_nonyuv_frame(video_data *v, frame_data *f, int frame_idx)
int done_flag = 0;
/* Read the next frame, if any. */
- if (av_read_frame(ifd->format_ctx, &packet) < 0)
- break;
+ int read_success = av_read_frame(ifd->format_ctx, &packet);
/* Video frame. */
- if (packet.stream_index == ifd->stream_id)
+ if (read_success < 0 || packet.stream_index == ifd->stream_id)
{
+ if (read_success < 0)
+ {
+ packet.size = 0;
+ packet.data = 0;
+ }
+
/* We decoded a frame. */
- #ifdef F265_USE_NEW_LIBAV
- if (avcodec_decode_video2(ifd->codec_ctx, ifd->frame, &frame_flag, &packet /*.data, packet.size*/) >= 0)
- #else
- if (avcodec_decode_video(ifd->codec_ctx, ifd->frame, &frame_flag, packet.data, packet.size) >= 0)
+ #ifdef F265_USE_OLD_LIBAV
+ int byte_used = avcodec_decode_video(ifd->codec_ctx, ifd->frame, &frame_flag, packet.data, packet.size);
+ #elif defined F265_USE_NEW_LIBAV
+ int byte_used = avcodec_decode_video2(ifd->codec_ctx, ifd->frame, &frame_flag, &packet);
#endif
- {
- /* We're done if the codec outputted a frame. */
- done_flag = frame_flag;
- /* Get the size and the duration. */
- f->size[frame_idx] = packet.size;
- f->duration[frame_idx] = 0;
- if (packet.duration)
- f->duration[frame_idx] = (double)packet.duration *
- ((double)ifd->stream->time_base.num / (double)ifd->stream->time_base.den);
- }
+ /* We're done if the codec outputted a frame. */
+ if ((byte_used > 0) | frame_flag) done_flag = !!frame_flag;
/* Error decoding the frame. */
else
@@ -758,6 +755,16 @@ int read_nonyuv_frame(video_data *v, frame_data *f, int frame_idx)
frame_flag = 0;
done_flag = 1;
}
+
+ /* Get the size and the duration. */
+ if (frame_flag)
+ {
+ f->size[frame_idx] = packet.size;
+ f->duration[frame_idx] = 0;
+ if (packet.duration)
+ f->duration[frame_idx] = (double)packet.duration *
+ ((double)ifd->stream->time_base.num / (double)ifd->stream->time_base.den);
+ }
}
/* Free the packet. */