[FFmpeg-soc] [soc]: r4533 - seek_api/parser.c

Baptiste Coudurier baptiste.coudurier at gmail.com
Mon Jun 29 21:10:25 CEST 2009


Hi Zhentan,

zhentan feng wrote:
> Hi
> 
> 2009/6/29 Baptiste Coudurier <baptiste.coudurier at gmail.com>
> 
>> spyfeng wrote:
>>> Author: spyfeng
>>> Date: Sat Jun 27 15:35:59 2009
>>> New Revision: 4533
>>>
>>> Log:
>>> set correct pos when cannot get pos from ff_fetch_timestamp().
>>>
>>> Modified:
>>>    seek_api/parser.c
>>>
>>> Modified: seek_api/parser.c
>>>
>> ==============================================================================
>>> --- seek_api/parser.c Sat Jun 27 15:28:08 2009        (r4532)
>>> +++ seek_api/parser.c Sat Jun 27 15:35:59 2009        (r4533)
>>> @@ -188,6 +188,8 @@ int av_parser_parse2(AVCodecParserContex
>>>      if (index < 0)
>>>          index = 0;
>>>      s->cur_offset += index;
>>> +    if (s->pos == -1)
>>> +        s->pos = s->last_pos + index;
>>>      return index;
>>>  }
>> Can you explain why this change is needed ? It seems wrong to me.
>>
>> The goal is for getting the correct pkt->pos when call av_read_frame().
> 
> consider the attached two log files below. I added some log info when
> av_parser_parse2() is called in libavformait/utils.c
> logpf2.txt is  the original outputs and logpf3.txt is the new outputs.
> 
> I select some lines from logf2.txt.
> for example, the first frame of stream index = 1 is:
> [mpeg @ 0x9c43440]av_read_frame_internal stream=1, pts=45000, dts=45000,
> size=208, flags=1, pos=2048
> 
> then the second frame is
> [mpeg @ 0x9c43440]av_read_frame_internal stream=1, pts=47351, dts=47351,
> size=209, flags=1, pos=-1
> 
> actually, we can calculate the second frame pos by the last_pos.
> If keep the frame as -1, when find the keyframe by index entries, the index
> entries pos is -1, we cannot seek there.

Yes, pos must be set to the PES packet pos to be able to seek there and
retrieve correct pts/dts for the frame.
Example below:

> 
> 
> ------------------------------------------------------------------------
> 
> Input #0, mpeg, from 'tests/data/b-lavf.mpg':
>   Duration: 00:00:01.01, start: 0.500000, bitrate: 2975 kb/s
>     Stream #0.0[0x1e0], 1/90000: Video: mpeg1video, yuv420p, 352x288 [PAR 1:1 DAR 11:9], 1/25, 104857 kb/s, 25 tbr, 90k tbn, 25 tbc
>     Stream #0.1[0x1c0], 1/90000: Audio: mp2, 44100 Hz, mono, s16, 64 kb/s
> Output #0, null, to '/dev/null':
>     Stream #0.0, 1/90000: Video: rawvideo, yuv420p, 352x288 [PAR 1:1 DAR 11:9], 1/25, q=2-31, 200 kb/s, 90k tbn, 25 tbc
>     Stream #0.1, 1/90000: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
> Stream mapping:
>   Stream #0.0 -> #0.0
>   Stream #0.1 -> #0.1
> Press [q] to stop encoding
> [mpeg @ 0x9c43440]mpeg add index stream_index=0, pos = 30, dts = 41400
> [mpeg @ 0x9c43440]av_read_packet stream=0, pts=45000, dts=41400, size=2002,  flags=0, pos = 30
> [mpeg @ 0x9c43440]mpeg add index stream_index=1, pos = 2048, dts = 45000
> [mpeg @ 0x9c43440]av_read_packet stream=1, pts=45000, dts=45000, size=2037,  flags=0, pos = 2048

pos is set here.

> [mpeg @ 0x9c43440]pkt pos:2048, st->parser->pos:2048
> [mpeg @ 0x9c43440]stream_index 1, the frame_offset = 2048
> [mpeg @ 0x9c43440]av_read_frame_internal stream=1, pts=45000, dts=45000, size=208, flags=1, pos=2048
> [mpeg @ 0x9c43440]pkt pos:-1, st->parser->pos:-1
> [mpeg @ 0x9c43440]stream_index 1, the frame_offset = 2256



> [mpeg @ 0x9c43440]av_read_frame_internal stream=1, pts=47351, dts=47351, size=209, flags=1, pos=-1
> [mpeg @ 0x9c43440]pkt pos:-1, st->parser->pos:-1
> [mpeg @ 0x9c43440]stream_index 1, the frame_offset = 2465

Pos must be 2048 as well.

[...]

-- 
Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org


More information about the FFmpeg-soc mailing list