fixes issue 2068
Originally committed as revision 25727 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -630,6 +630,10 @@ of the output file: |
630 | 630 |
@example |
631 | 631 |
ffmpeg -i in.ogg -map_meta_data 0:0,s0 out.mp3 |
632 | 632 |
@end example |
633 |
+@item -map_chapters @var{outfile}:@var{infile} |
|
634 |
+Copy chapters from @var{infile} to @var{outfile}. If no chapter mapping is specified, |
|
635 |
+then chapters are copied from the first input file with at least one chapter to all |
|
636 |
+output files. Use a negative file index to disable any chapter copying. |
|
633 | 637 |
@item -debug |
634 | 638 |
Print specific debug info. |
635 | 639 |
@item -benchmark |
... | ... |
@@ -102,6 +102,11 @@ typedef struct AVMetaDataMap { |
102 | 102 |
int index; //< stream/chapter/program number |
103 | 103 |
} AVMetaDataMap; |
104 | 104 |
|
105 |
+typedef struct AVChapterMap { |
|
106 |
+ int in_file; |
|
107 |
+ int out_file; |
|
108 |
+} AVChapterMap; |
|
109 |
+ |
|
105 | 110 |
static const OptionDef options[]; |
106 | 111 |
|
107 | 112 |
#define MAX_FILES 100 |
... | ... |
@@ -132,6 +137,9 @@ static int nb_meta_data_maps; |
132 | 132 |
static int metadata_streams_autocopy = 1; |
133 | 133 |
static int metadata_chapters_autocopy = 1; |
134 | 134 |
|
135 |
+static AVChapterMap *chapter_maps = NULL; |
|
136 |
+static int nb_chapter_maps; |
|
137 |
+ |
|
135 | 138 |
/* indexed by output file stream index */ |
136 | 139 |
static int *streamid_map = NULL; |
137 | 140 |
static int nb_streamid_map = 0; |
... | ... |
@@ -2381,7 +2389,28 @@ static int transcode(AVFormatContext **output_files, |
2381 | 2381 |
av_metadata_set2(meta[0], mtag->key, mtag->value, AV_METADATA_DONT_OVERWRITE); |
2382 | 2382 |
} |
2383 | 2383 |
|
2384 |
+ /* copy chapters according to chapter maps */ |
|
2385 |
+ for (i = 0; i < nb_chapter_maps; i++) { |
|
2386 |
+ int infile = chapter_maps[i].in_file; |
|
2387 |
+ int outfile = chapter_maps[i].out_file; |
|
2388 |
+ |
|
2389 |
+ if (infile < 0 || outfile < 0) |
|
2390 |
+ continue; |
|
2391 |
+ if (infile >= nb_input_files) { |
|
2392 |
+ snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile); |
|
2393 |
+ ret = AVERROR(EINVAL); |
|
2394 |
+ goto dump_format; |
|
2395 |
+ } |
|
2396 |
+ if (outfile >= nb_output_files) { |
|
2397 |
+ snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile); |
|
2398 |
+ ret = AVERROR(EINVAL); |
|
2399 |
+ goto dump_format; |
|
2400 |
+ } |
|
2401 |
+ copy_chapters(infile, outfile); |
|
2402 |
+ } |
|
2403 |
+ |
|
2384 | 2404 |
/* copy chapters from the first input file that has them*/ |
2405 |
+ if (!nb_chapter_maps) |
|
2385 | 2406 |
for (i = 0; i < nb_input_files; i++) { |
2386 | 2407 |
if (!input_files[i]->nb_chapters) |
2387 | 2408 |
continue; |
... | ... |
@@ -2962,6 +2991,21 @@ static void opt_map_meta_data(const char *arg) |
2962 | 2962 |
metadata_chapters_autocopy = 0; |
2963 | 2963 |
} |
2964 | 2964 |
|
2965 |
+static void opt_map_chapters(const char *arg) |
|
2966 |
+{ |
|
2967 |
+ AVChapterMap *c; |
|
2968 |
+ char *p; |
|
2969 |
+ |
|
2970 |
+ chapter_maps = grow_array(chapter_maps, sizeof(*chapter_maps), &nb_chapter_maps, |
|
2971 |
+ nb_chapter_maps + 1); |
|
2972 |
+ c = &chapter_maps[nb_chapter_maps - 1]; |
|
2973 |
+ c->out_file = strtol(arg, &p, 0); |
|
2974 |
+ if (*p) |
|
2975 |
+ p++; |
|
2976 |
+ |
|
2977 |
+ c->in_file = strtol(p, &p, 0); |
|
2978 |
+} |
|
2979 |
+ |
|
2965 | 2980 |
static void opt_input_ts_scale(const char *arg) |
2966 | 2981 |
{ |
2967 | 2982 |
unsigned int stream; |
... | ... |
@@ -4074,6 +4118,7 @@ static const OptionDef options[] = { |
4074 | 4074 |
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" }, |
4075 | 4075 |
{ "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" }, |
4076 | 4076 |
{ "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile[,metadata]:infile[,metadata]" }, |
4077 |
+ { "map_chapters", HAS_ARG | OPT_EXPERT, {(void*)opt_map_chapters}, "set chapters mapping", "outfile:infile" }, |
|
4077 | 4078 |
{ "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, |
4078 | 4079 |
{ "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, // |
4079 | 4080 |
{ "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, |