Revision 91e96eba ffmpeg.c

View differences:

ffmpeg.c
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 137
static int metadata_streams_autocopy  = 1;
133 138
static int metadata_chapters_autocopy = 1;
134 139

  
140
static AVChapterMap *chapter_maps = NULL;
141
static int nb_chapter_maps;
142

  
135 143
/* indexed by output file stream index */
136 144
static int *streamid_map = NULL;
137 145
static int nb_streamid_map = 0;
......
2381 2389
            av_metadata_set2(meta[0], mtag->key, mtag->value, AV_METADATA_DONT_OVERWRITE);
2382 2390
    }
2383 2391

  
2392
    /* copy chapters according to chapter maps */
2393
    for (i = 0; i < nb_chapter_maps; i++) {
2394
        int infile  = chapter_maps[i].in_file;
2395
        int outfile = chapter_maps[i].out_file;
2396

  
2397
        if (infile < 0 || outfile < 0)
2398
            continue;
2399
        if (infile >= nb_input_files) {
2400
            snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile);
2401
            ret = AVERROR(EINVAL);
2402
            goto dump_format;
2403
        }
2404
        if (outfile >= nb_output_files) {
2405
            snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile);
2406
            ret = AVERROR(EINVAL);
2407
            goto dump_format;
2408
        }
2409
        copy_chapters(infile, outfile);
2410
    }
2411

  
2384 2412
    /* copy chapters from the first input file that has them*/
2413
    if (!nb_chapter_maps)
2385 2414
    for (i = 0; i < nb_input_files; i++) {
2386 2415
        if (!input_files[i]->nb_chapters)
2387 2416
            continue;
......
2962 2991
        metadata_chapters_autocopy = 0;
2963 2992
}
2964 2993

  
2994
static void opt_map_chapters(const char *arg)
2995
{
2996
    AVChapterMap *c;
2997
    char *p;
2998

  
2999
    chapter_maps = grow_array(chapter_maps, sizeof(*chapter_maps), &nb_chapter_maps,
3000
                              nb_chapter_maps + 1);
3001
    c = &chapter_maps[nb_chapter_maps - 1];
3002
    c->out_file = strtol(arg, &p, 0);
3003
    if (*p)
3004
        p++;
3005

  
3006
    c->in_file = strtol(p, &p, 0);
3007
}
3008

  
2965 3009
static void opt_input_ts_scale(const char *arg)
2966 3010
{
2967 3011
    unsigned int stream;
......
4074 4118
    { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
4075 4119
    { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" },
4076 4120
    { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile[,metadata]:infile[,metadata]" },
4121
    { "map_chapters",  HAS_ARG | OPT_EXPERT, {(void*)opt_map_chapters},  "set chapters mapping", "outfile:infile" },
4077 4122
    { "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
4078 4123
    { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
4079 4124
    { "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },

Also available in: Unified diff