[FFmpeg-devel] [PATCH] Use sample size in case incorrect timestamps for aac in AVI (Ticket #1755)

정희석 heesuk.jung at lge.com
Wed Oct 10 10:30:58 CEST 2012


>From 2848da6b6092d68a8724d3b6a941e49b961c5e21 Mon Sep 17 00:00:00 2001

From: Heesuk Jung <heesuk.jung at lge.com>

Date: Wed, 10 Oct 2012 14:00:06 +0900

Subject: [PATCH]  Use sample size in case incorrect timestamps for aac in
AVI (Ticket #1755)

 

In some case for aac in AVI, avidec extracts wrong PTS value.

(www.ffmpeg.org/trac/ffmpeg/ticket/1755)

If you want to know cause of problem, I recommend to visit ticket #1755.

In getDuration function, I suggest using sample size instead of len.

 

Also I have done regression test in our media pool.

 

Test result of 11 problematic files is ok after patch apply.

(11 files have fixed sample size in AVI Stream Header)

 

Regression test result of 4 non-problematic files is ok after patch apply.

(4 files have variable sample size in AVI Stream Header)

---

libavformat/avidec.c |   16 ++++++++++------

1 files changed, 10 insertions(+), 6 deletions(-)

 

diff --git a/libavformat/avidec.c b/libavformat/avidec.c

index b4c5fe8..43d80ce 100644

--- a/libavformat/avidec.c

+++ b/libavformat/avidec.c

@@ -115,9 +115,13 @@ static int guess_ni_flag(AVFormatContext *s);

            (tag >> 24) & 0xff,                          \

            size)

-static inline int get_duration(AVIStream *ast, int len){

+static inline int get_duration(AVIStream *ast, int len, enum AVCodecID
codecId) {

     if(ast->sample_size){

-        return len;

+        if (codecId == AV_CODEC_ID_AAC) {

+            return ast->sample_size;

+        } else {

+            return len;

+        }

     }else if (ast->dshow_block_align){

         return (len + ast->dshow_block_align - 1)/ast->dshow_block_align;

     }else

@@ -208,7 +212,7 @@ static int read_braindead_odml_indx(AVFormatContext *s,
int frame_num){

             if(last_pos != pos && (len || !ast->sample_size))

                 av_add_index_entry(st, pos, ast->cum_len, len, 0, key ?
AVINDEX_KEYFRAME : 0);

-            ast->cum_len += get_duration(ast, len);

+            ast->cum_len += get_duration(ast, len, st->codec->codec_id);

             last_pos= pos;

         }else{

             int64_t offset, pos;

@@ -990,7 +994,7 @@ start_sync:

                /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags &
AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering

                || st->discard >= AVDISCARD_ALL){

                 if (!exit_early) {

-                    ast->frame_offset += get_duration(ast, size);

+                    ast->frame_offset += get_duration(ast, size, st->codec-
>codec_id);

                 }

                 avio_skip(pb, size);

                 goto start_sync;

@@ -1206,7 +1210,7 @@ resync:

             } else {

                 pkt->flags |= AV_PKT_FLAG_KEY;

             }

-            ast->frame_offset += get_duration(ast, pkt->size);

+            ast->frame_offset += get_duration(ast, pkt->size, st->codec-
>codec_id);

         }

         ast->remaining -= err;

         if(!ast->remaining){

@@ -1301,7 +1305,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)

             av_add_index_entry(st, pos, ast->cum_len, len, 0,
(flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);

             last_idx= pos;

         }

-        ast->cum_len += get_duration(ast, len);

+        ast->cum_len += get_duration(ast, len, st->codec->codec_id);

         last_pos= pos;

         anykey |= flags&AVIIF_INDEX;

     }

-- 

1.7.0.4

 



More information about the ffmpeg-devel mailing list