[FFmpeg-user] trouble with AVChapter

Pavel Koshevoy pkoshevoy at gmail.com
Wed Nov 25 13:00:36 EET 2020


On Wed, Nov 25, 2020, 00:01 Steve Dibb <steve.dibb at gmail.com> wrote:

> Hey there,
>
> So I'm creating an MP4 file, and testing setting some chapters, and running
> into two problems.
>
> 1. The chapter ranges are wrong -- in the example below, they should all be
> one second apart, but the first chapter gets set to 0 to 4 seconds, then
> the ones in the middle have no range, of 4 seconds to 4 seconds, and the
> last chapter's range is 4 seconds to 5 seconds.
>
> 2. The chapter titles are all set to the last metadata entry for title
> given
>
> Here's some sample, simplified code:
>
>         unsigned int num_chapters = 5;
>         unsigned int chapter_ix = 0;
>         unsigned char chapter_title[80];
>         memset(chapter_title, '\0', 80);
>
>         AVChapter *chapter = calloc(1, sizeof(AVChapter));
>
>         chapter->time_base.num = 1;
>         chapter->time_base.den = 1000;
>

The above 3 lines should be inside the for-loop, otherwise your chapters
array will have 5 entries all pointing to the same AVChapter.




>         AVChapter **chapters = calloc(num_chapters, sizeof(AVChapter*));
>
>         for(chapter_ix = 0; chapter_ix < num_chapters; chapter_ix++) {
>
>                 chapter->id = chapter_ix + 1;
>                 chapter->start = 1000 * chapter_ix;
>                 chapter->end = chapter->start + 1000;
>
>                 printf("chapter range: %i-%i\n", chapter->start,
> chapter->end);
>
>                 sprintf(chapter_title, "Chapter %u", chapter_ix + 1);
>
>                 av_dict_set(&chapter->metadata, "title", chapter_title, 0);
>
>                 chapters[chapter_ix] = chapter;
>
>         }
>
>         output->nb_chapters = num_chapters;
>
>         output->chapters = chapters;
>
> And the output of ffprobe:
>
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dvd_rip_00.mp4':
>   Metadata:
>     major_brand     : isom
>     minor_version   : 512
>     compatible_brands: isomiso2avc1mp41
>     encoder         : Lavf58.45.100
>   Duration: 00:00:05.00, start: 0.000000, bitrate: 9020 kb/s
>     Chapter #0:0: start 0.000000, end 4.000000
>     Metadata:
>       title           : Chapter 5
>     Chapter #0:1: start 4.000000, end 4.000000
>     Metadata:
>       title           : Chapter 5
>     Chapter #0:2: start 4.000000, end 4.000000
>     Metadata:
>       title           : Chapter 5
>     Chapter #0:3: start 4.000000, end 4.000000
>     Metadata:
>       title           : Chapter 5
>     Chapter #0:4: start 4.000000, end 5.000000
>     Metadata:
>       title           : Chapter 5
>
> Can someone look at this for me and see if there's any glaring errors on my
> end?
>
> Thanks!!
>
> Steve
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-user mailing list