[FFmpeg-devel] [PATCH v3 2/3] aadec: add chapters and seeking
Karsten Otto
ottoka at posteo.de
Mon Jul 2 19:51:45 EEST 2018
> Am 02.07.2018 um 10:22 schrieb Michael Niedermayer <michael at niedermayer.cc>:
>
> Signierter PGP-Teil
> On Thu, Jun 21, 2018 at 06:58:25PM +0200, Karsten Otto wrote:
>> read_packet reads content in chunks. Thus seek must be clamped to valid
>> chunk positions in the file, which in turn are relative to chapter start
>> positions.
>>
>> So in read_header, scan for chapter headers once by skipping through the
>> content. Set stream time_base to bitrate in bytes/s, for easy timestamp to
>> position conversion.
>
> IIUC this would be linearly reading through the whole file before playing
> anything?
> if thats the case, thats not ideal, is that unavoidable ?
>
It is not quite as bad: A chapter header contains the byte size of the chapter,
so after reading it I can avio_skip() ahead to the next chapter header, and
repeat. So, this is not a linear read, but mostly a sequence of seek operations.
I am aware this is not a perfect solution, but unfortunately at the current level of
knowledge about the aa format, this is indeed unavoidable for now. Possibly it
could be improved later if anyone gains a deeper understanding of the format.
>
>
>>
>> Then in read_seek, find the chapter containing the seek position, calculate
>> the nearest chunk position, and reinit the read_seek state accordingly.
>> ---
>> libavformat/aadec.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++---
>> 1 file changed, 83 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/aadec.c b/libavformat/aadec.c
>> index 4db71b1939..b009c9deca 100644
>> --- a/libavformat/aadec.c
>> +++ b/libavformat/aadec.c
>> @@ -35,6 +35,8 @@
>> #define MAX_TOC_ENTRIES 16
>> #define MAX_DICTIONARY_ENTRIES 128
>> #define TEA_BLOCK_SIZE 8
>> +#define CHAPTER_HEADER_SIZE 8
>> +#define TIMEPREC 1000
>>
>> typedef struct AADemuxContext {
>> AVClass *class;
>> @@ -46,6 +48,7 @@ typedef struct AADemuxContext {
>> struct AVTEA *tea_ctx;
>> uint8_t file_key[16];
>> int64_t current_chapter_size;
>> + int64_t content_start;
>> int64_t content_end;
>> } AADemuxContext;
>>
>> @@ -70,7 +73,7 @@ static int aa_read_header(AVFormatContext *s)
>> uint32_t nkey, nval, toc_size, npairs, header_seed = 0, start;
>> char key[128], val[128], codec_name[64] = {0};
>> uint8_t output[24], dst[8], src[8];
>> - int64_t largest_size = -1, current_size = -1;
>> + int64_t largest_size = -1, current_size = -1, chapter_pos;
>> struct toc_entry {
>> uint32_t offset;
>> uint32_t size;
>
>> @@ -172,19 +175,23 @@ static int aa_read_header(AVFormatContext *s)
>> if (!strcmp(codec_name, "mp332")) {
>> st->codecpar->codec_id = AV_CODEC_ID_MP3;
>> st->codecpar->sample_rate = 22050;
>> + st->time_base = av_make_q(8, 32000 * TIMEPREC);
>> st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
>> - st->start_time = 0;
>> } else if (!strcmp(codec_name, "acelp85")) {
>> st->codecpar->codec_id = AV_CODEC_ID_SIPR;
>> st->codecpar->block_align = 19;
>> st->codecpar->channels = 1;
>> st->codecpar->sample_rate = 8500;
>> + st->codecpar->bit_rate = 8500;
>> + st->time_base = av_make_q(8, 8500 * TIMEPREC);
>> st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
>> } else if (!strcmp(codec_name, "acelp16")) {
>> st->codecpar->codec_id = AV_CODEC_ID_SIPR;
>> st->codecpar->block_align = 20;
>> st->codecpar->channels = 1;
>> st->codecpar->sample_rate = 16000;
>> + st->codecpar->bit_rate = 16000;
>> + st->time_base = av_make_q(8, 16000 * TIMEPREC);
>
> see avpriv_set_pts_info()
>
Thanks, I will check it out.
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Elect your leaders based on what they did after the last election, not
> based on what they say before an election.
>
>
>
More information about the ffmpeg-devel
mailing list