Created
November 25, 2020 06:46
-
-
Save beandog/c4b4613241251b4569b7f36bfdabb703 to your computer and use it in GitHub Desktop.
ffmpeg AVChapter problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code is designed to create 5 chapters that are each 1 second apart, and then | |
* set its metadata to 'Chapter #'. | |
* | |
* There are two problems happening: | |
* | |
* 1) The chapter titles are all set to whatever the last metadata entry is. In this | |
* case, they are all 'Chapter 5'. | |
* | |
* 2) The range of the chapters is wrong for all of them. They should be 0:00 to 0:01, | |
* 0:01 to 0:02, etc. | |
* | |
* See ffprobe output below for what the output is. | |
*/ | |
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; | |
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; | |
/** | |
ffprobe output: | |
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 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot to add, I'm using ffmpeg 4.3.1