diff mbox

[FFmpeg-devel] lavc: Fix ticket 6024, truncated mode decoding

Message ID 1481822363-22231-1-git-send-email-pkoshevoy@gmail.com
State Accepted
Headers show

Commit Message

Pavel Koshevoy Dec. 15, 2016, 5:19 p.m. UTC
From: Pavel Koshevoy <pkoshevoy@gmail.com>

The assumption that avcodec_send_packet makes regarding decoders
consuming the entire packet is not true if the codec supports
truncated decoding mode and the truncated flag is turned on.

Steps to reproduce:
./ffmpeg_g -flags truncated \
-i "http://samples.ffmpeg.org/MPEG2/test-ebu-422.40000.pakets.ts" \
-c:v ffv1 -c:a copy -y /tmp/truncated.nut
---
 libavcodec/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pavel Koshevoy Dec. 15, 2016, 6:33 p.m. UTC | #1
passes fate, but I don't do that often so someone might want to double-check

  Pavel.

On Thu, Dec 15, 2016 at 10:19 AM,  <pkoshevoy@gmail.com> wrote:
> From: Pavel Koshevoy <pkoshevoy@gmail.com>
>
> The assumption that avcodec_send_packet makes regarding decoders
> consuming the entire packet is not true if the codec supports
> truncated decoding mode and the truncated flag is turned on.
>
> Steps to reproduce:
> ./ffmpeg_g -flags truncated \
> -i "http://samples.ffmpeg.org/MPEG2/test-ebu-422.40000.pakets.ts" \
> -c:v ffv1 -c:a copy -y /tmp/truncated.nut
> ---
>  libavcodec/utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 44ecc09..be50459 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2788,7 +2788,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
>      if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
>          ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
>                                      &got_frame, pkt);
> -        if (ret >= 0)
> +        if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
>              ret = pkt->size;
>      } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
>          ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,
> --
> 2.6.6
>
wm4 Dec. 16, 2016, 4:16 p.m. UTC | #2
On Thu, 15 Dec 2016 10:19:23 -0700
pkoshevoy@gmail.com wrote:

> From: Pavel Koshevoy <pkoshevoy@gmail.com>
> 
> The assumption that avcodec_send_packet makes regarding decoders
> consuming the entire packet is not true if the codec supports
> truncated decoding mode and the truncated flag is turned on.
> 
> Steps to reproduce:
> ./ffmpeg_g -flags truncated \
> -i "http://samples.ffmpeg.org/MPEG2/test-ebu-422.40000.pakets.ts" \
> -c:v ffv1 -c:a copy -y /tmp/truncated.nut
> ---
>  libavcodec/utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 44ecc09..be50459 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2788,7 +2788,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
>      if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
>          ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
>                                      &got_frame, pkt);
> -        if (ret >= 0)
> +        if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
>              ret = pkt->size;
>      } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
>          ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,

Yep, that's much better, thanks.
Michael Niedermayer Dec. 17, 2016, 5:44 p.m. UTC | #3
On Thu, Dec 15, 2016 at 10:19:23AM -0700, pkoshevoy@gmail.com wrote:
> From: Pavel Koshevoy <pkoshevoy@gmail.com>
> 
> The assumption that avcodec_send_packet makes regarding decoders
> consuming the entire packet is not true if the codec supports
> truncated decoding mode and the truncated flag is turned on.
> 
> Steps to reproduce:
> ./ffmpeg_g -flags truncated \
> -i "http://samples.ffmpeg.org/MPEG2/test-ebu-422.40000.pakets.ts" \
> -c:v ffv1 -c:a copy -y /tmp/truncated.nut
> ---
>  libavcodec/utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

applied

thx

PS: do you want to add a fate test for this ?

[...]
diff mbox

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 44ecc09..be50459 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2788,7 +2788,7 @@  static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
     if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
         ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
                                     &got_frame, pkt);
-        if (ret >= 0)
+        if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
             ret = pkt->size;
     } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
         ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,