Skip to content

Commit

Permalink
add support for chapters definition in lavf
Browse files Browse the repository at this point in the history
patch by Anton Khirnov  wyskas _at_ gmail _dot_ com

Originally committed as revision 13240 to svn://svn.ffmpeg.org/ffmpeg/trunk
  • Loading branch information
Anton Khirnov authored and aurelj committed May 22, 2008
1 parent d311f8f commit 79d7836
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
22 changes: 21 additions & 1 deletion libavformat/avformat.h
Expand Up @@ -22,7 +22,7 @@
#define FFMPEG_AVFORMAT_H

#define LIBAVFORMAT_VERSION_MAJOR 52
#define LIBAVFORMAT_VERSION_MINOR 13
#define LIBAVFORMAT_VERSION_MINOR 14
#define LIBAVFORMAT_VERSION_MICRO 0

#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
Expand Down Expand Up @@ -389,6 +389,11 @@ typedef struct AVProgram {
#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
(streams are added dynamically) */

typedef struct AVChapter {
int64_t start, end; /**< chapter start/end time in AV_TIME_BASE units */
char *title; /**< chapter title */
} AVChapter;

#define MAX_STREAMS 20

/**
Expand Down Expand Up @@ -514,6 +519,9 @@ typedef struct AVFormatContext {
* obtained from real-time capture devices.
*/
unsigned int max_picture_buffer;

int num_chapters;
AVChapter **chapters;
} AVFormatContext;

typedef struct AVPacketList {
Expand Down Expand Up @@ -744,6 +752,18 @@ void av_close_input_file(AVFormatContext *s);
AVStream *av_new_stream(AVFormatContext *s, int id);
AVProgram *av_new_program(AVFormatContext *s, int id);

/**
* Add a new chapter.
* This function is NOT part of the public API
* and should be ONLY used by demuxers.
*
* @param s media file handle
* @param start chapter start time in AV_TIME_BASE units
* @param end chapter end time in AV_TIME_BASE units
* @param title chapter title
*/
int ff_new_chapter(AVFormatContext *s, int64_t start, int64_t end, const char *title);

/**
* Set the pts for a given stream.
*
Expand Down
18 changes: 18 additions & 0 deletions libavformat/utils.c
Expand Up @@ -2148,6 +2148,11 @@ void av_close_input_stream(AVFormatContext *s)
av_freep(&s->programs);
flush_packet_queue(s);
av_freep(&s->priv_data);
while(s->num_chapters--) {
av_free(s->chapters[s->num_chapters]->title);
av_free(s->chapters[s->num_chapters]);
}
av_freep(&s->chapters);
av_free(s);
}

Expand Down Expand Up @@ -2229,6 +2234,19 @@ void av_set_program_name(AVProgram *program, char *provider_name, char *name)
}
}

int ff_new_chapter(AVFormatContext *s, int64_t start, int64_t end, const char *title)
{
AVChapter *chapter = av_mallocz(sizeof(AVChapter));
if(!chapter)
return AVERROR(ENOMEM);
chapter->title = av_strdup(title);
chapter->start = start;
chapter->end = end;

dynarray_add(&s->chapters, &s->num_chapters, chapter);

return 0;
}

/************************************************************/
/* output media file */
Expand Down

0 comments on commit 79d7836

Please sign in to comment.