Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
1 result

parse_chapters.c

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    parse_chapters.c 896 B
    #include <libavformat/avformat.h>
    
    #include "../util.h"
    
    #define CHAPTER_TIME_BASE (AVRational){1, 1}
    
    void parse_chapters(AVFormatContext *ctx, char *s, int64_t duration)
    {
    	char *p;
    	int i;
    	duration = av_rescale_q(duration, AV_TIME_BASE_Q, CHAPTER_TIME_BASE);
    	for (p = jenter(s), i = 0; p; p = jnext(p), i ++);
    	ctx->chapters = xmalloc(sizeof(AVChapter *)*i);
    	ctx->nb_chapters = i;
    	for (p = jenter(s), i = 0; p; p = jnext(p), i ++)
    	{
    		ctx->chapters[i] = malloc(sizeof(AVChapter));
    		memset(ctx->chapters[i], 0, sizeof(AVChapter));
    		ctx->chapters[i]->id = i;
    		ctx->chapters[i]->time_base = CHAPTER_TIME_BASE;
    		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)
    			ctx->chapters[i-1]->end = ctx->chapters[i]->start;
    	}
    	if (ctx->nb_chapters)
    		ctx->chapters[i-1]->end = duration;
    }