Commit 4aef5dc0 authored by Julian Rother's avatar Julian Rother

Insert dummy chapter if first chapter does not start at beginning of video

parent 7ea39401
...@@ -10,20 +10,28 @@ void parse_chapters(AVFormatContext *ctx, char *s, int64_t duration) ...@@ -10,20 +10,28 @@ void parse_chapters(AVFormatContext *ctx, char *s, int64_t duration)
int i; int i;
duration = av_rescale_q(duration, AV_TIME_BASE_Q, CHAPTER_TIME_BASE); duration = av_rescale_q(duration, AV_TIME_BASE_Q, CHAPTER_TIME_BASE);
for (p = jenter(s), i = 0; p; p = jnext(p), i ++); for (p = jenter(s), i = 0; p; p = jnext(p), i ++);
ctx->chapters = xmalloc(sizeof(AVChapter *)*i); ctx->chapters = xmalloc(sizeof(AVChapter *)*(i+1));
ctx->nb_chapters = i; for (p = jenter(s), i = 0; p; i ++)
for (p = jenter(s), i = 0; p; p = jnext(p), i ++)
{ {
ctx->chapters[i] = malloc(sizeof(AVChapter)); ctx->chapters[i] = malloc(sizeof(AVChapter));
memset(ctx->chapters[i], 0, sizeof(AVChapter)); memset(ctx->chapters[i], 0, sizeof(AVChapter));
ctx->chapters[i]->id = i; ctx->chapters[i]->id = i;
ctx->chapters[i]->time_base = CHAPTER_TIME_BASE; ctx->chapters[i]->time_base = CHAPTER_TIME_BASE;
if (!i && jint(jlookup(p, "time"), -1))
{
/* Insert dummy chapter starting at time 0 (otherwise ffmpeg glitches) */
ctx->chapters[i]->start = 0;
av_dict_set(&ctx->chapters[i]->metadata, "title", "Intro", 0);
continue;
}
ctx->chapters[i]->start = jint(jlookup(p, "time"), 0); ctx->chapters[i]->start = jint(jlookup(p, "time"), 0);
av_dict_set(&ctx->chapters[i]->metadata, "title", jstr(jlookup(p, "text"), "EMPTY"), 0);
if (i) if (i)
ctx->chapters[i-1]->end = ctx->chapters[i]->start; ctx->chapters[i-1]->end = ctx->chapters[i]->start;
av_dict_set(&ctx->chapters[i]->metadata, "title", jstr(jlookup(p, "text"), "EMPTY"), 0);
p = jnext(p);
} }
ctx->nb_chapters = i;
if (ctx->nb_chapters) if (ctx->nb_chapters)
ctx->chapters[i-1]->end = duration; ctx->chapters[ctx->nb_chapters-1]->end = duration;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment