aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/matroskaenc.c
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-10-18 12:17:01 +0000
committerAurelien Jacobs <aurel@gnuage.org>2009-10-18 12:17:01 +0000
commit2bd0758efaca4aba6d914d1e7de1c40d521b4217 (patch)
tree0ada0e23bf7fa785cf4b316ceec3a9b8cee429b0 /libavformat/matroskaenc.c
parent15674f12bef9a7270c0f5bf27845623a7a63e213 (diff)
downloadffmpeg-2bd0758efaca4aba6d914d1e7de1c40d521b4217.tar.gz
matroskaenc: Add support for writing chapters.
patch by Anton Khirnov wyskas _at_ gmail _dot_ com Originally committed as revision 20277 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a03b11bc3e..c119518967 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -619,6 +619,50 @@ static int mkv_write_tracks(AVFormatContext *s)
return 0;
}
+static int mkv_write_chapters(AVFormatContext *s)
+{
+ MatroskaMuxContext *mkv = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ ebml_master chapters, editionentry;
+ AVRational scale = {1, 1E9};
+ int i, ret;
+
+ if (!s->nb_chapters)
+ return 0;
+
+ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, url_ftell(pb));
+ if (ret < 0) return ret;
+
+ chapters = start_ebml_master(pb, MATROSKA_ID_CHAPTERS , 0);
+ editionentry = start_ebml_master(pb, MATROSKA_ID_EDITIONENTRY, 0);
+ put_ebml_uint(pb, MATROSKA_ID_EDITIONFLAGDEFAULT, 1);
+ put_ebml_uint(pb, MATROSKA_ID_EDITIONFLAGHIDDEN , 0);
+ for (i = 0; i < s->nb_chapters; i++) {
+ ebml_master chapteratom, chapterdisplay;
+ AVChapter *c = s->chapters[i];
+ AVMetadataTag *t = NULL;
+
+ chapteratom = start_ebml_master(pb, MATROSKA_ID_CHAPTERATOM, 0);
+ put_ebml_uint(pb, MATROSKA_ID_CHAPTERUID, c->id);
+ put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMESTART,
+ av_rescale_q(c->start, c->time_base, scale));
+ put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMEEND,
+ av_rescale_q(c->end, c->time_base, scale));
+ put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGHIDDEN , 0);
+ put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGENABLED, 1);
+ if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
+ chapterdisplay = start_ebml_master(pb, MATROSKA_ID_CHAPTERDISPLAY, 0);
+ put_ebml_string(pb, MATROSKA_ID_CHAPSTRING, t->value);
+ put_ebml_string(pb, MATROSKA_ID_CHAPLANG , "und");
+ end_ebml_master(pb, chapterdisplay);
+ }
+ end_ebml_master(pb, chapteratom);
+ }
+ end_ebml_master(pb, editionentry);
+ end_ebml_master(pb, chapters);
+ return 0;
+}
+
static int mkv_write_header(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
@@ -678,6 +722,9 @@ static int mkv_write_header(AVFormatContext *s)
ret = mkv_write_tracks(s);
if (ret < 0) return ret;
+ ret = mkv_write_chapters(s);
+ if (ret < 0) return ret;
+
ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb));
if (ret < 0) return ret;