avconv.c:3443: error: Null Dereference
  pointer `oc` last assigned on line 3422 could be null and is dereferenced at line 3443, column 5.

avconv.c:3410:1: start of procedure opt_output_file()
3408. }
3409. 
3410. static void opt_output_file(void *optctx, const char *filename)
      ^
3411. {
3412.     OptionsContext *o = optctx;

avconv.c:3412:5: 
3410. static void opt_output_file(void *optctx, const char *filename)
3411. {
3412.     OptionsContext *o = optctx;
          ^
3413.     AVFormatContext *oc;
3414.     int i, err;

avconv.c:3419:10: Taking true branch
3417.     InputStream  *ist;
3418. 
3419.     if (!strcmp(filename, "-"))
               ^
3420.         filename = "pipe:";
3421. 

avconv.c:3420:9: 
3418. 
3419.     if (!strcmp(filename, "-"))
3420.         filename = "pipe:";
              ^
3421. 
3422.     oc = avformat_alloc_context();

avconv.c:3422:5: 
3420.         filename = "pipe:";
3421. 
3422.     oc = avformat_alloc_context();
          ^
3423.     if (!oc) {
3424.         print_error(filename, AVERROR(ENOMEM));

libavformat/options.c:127:1: start of procedure avformat_alloc_context()
  125. }
  126. 
  127. AVFormatContext *avformat_alloc_context(void)
       ^
  128. {
  129.     AVFormatContext *ic;

libavformat/options.c:130:5: 
  128. {
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
           ^
  131.     if (!ic) return ic;
  132.     avformat_get_context_defaults(ic);

libavutil/mem.c:64:1: start of procedure av_malloc()
    62.    linker will do it automatically. */
    63. 
    64. void *av_malloc(size_t size)
        ^
    65. {
    66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
    64. void *av_malloc(size_t size)
    65. {
    66.     void *ptr = NULL;
            ^
    67. #if CONFIG_MEMALIGN_HACK
    68.     long diff;

libavutil/mem.c:72:8: Taking false branch
    70. 
    71.     /* let's disallow possible ambiguous cases */
    72.     if(size > (INT_MAX-32) )
               ^
    73.         return NULL;
    74. 

libavutil/mem.c:83:9: Taking false branch
    81.     ((char*)ptr)[-1]= diff;
    82. #elif HAVE_POSIX_MEMALIGN
    83.     if (posix_memalign(&ptr,32,size))
                ^
    84.         ptr = NULL;
    85. #elif HAVE_MEMALIGN

libavutil/mem.c:114:5: 
    112.     ptr = malloc(size);
    113. #endif
    114.     return ptr;
             ^
    115. }
    116. 

libavutil/mem.c:115:1: return from a call to av_malloc
    113. #endif
    114.     return ptr;
    115. }
         ^
    116. 
    117. void *av_realloc(void *ptr, size_t size)

libavformat/options.c:131:10: Taking true branch
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
  131.     if (!ic) return ic;
                ^
  132.     avformat_get_context_defaults(ic);
  133.     return ic;

libavformat/options.c:131:14: 
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
  131.     if (!ic) return ic;
                    ^
  132.     avformat_get_context_defaults(ic);
  133.     return ic;

libavformat/options.c:134:1: return from a call to avformat_alloc_context
  132.     avformat_get_context_defaults(ic);
  133.     return ic;
  134. }
       ^
  135. 
  136. const AVClass *avformat_get_class(void)

avconv.c:3423:10: Taking true branch
3421. 
3422.     oc = avformat_alloc_context();
3423.     if (!oc) {
               ^
3424.         print_error(filename, AVERROR(ENOMEM));
3425.         exit_program(1);

avconv.c:3424:9: 
3422.     oc = avformat_alloc_context();
3423.     if (!oc) {
3424.         print_error(filename, AVERROR(ENOMEM));
              ^
3425.         exit_program(1);
3426.     }

cmdutils.c:435:1: start of procedure print_error()
  433. }
  434. 
  435. void print_error(const char *filename, int err)
       ^
  436. {
  437.     char errbuf[128];

cmdutils.c:438:5: 
  436. {
  437.     char errbuf[128];
  438.     const char *errbuf_ptr = errbuf;
           ^
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)

cmdutils.c:440:9: Taking true branch
  438.     const char *errbuf_ptr = errbuf;
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
               ^
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);

cmdutils.c:441:9: Skipping strerror(): method has no implementation
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  441.         errbuf_ptr = strerror(AVUNERROR(err));
               ^
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
  443. }

cmdutils.c:442:5: Skipping av_log(): empty list of specs
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
           ^
  443. }
  444. 

cmdutils.c:443:1: return from a call to print_error
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
  443. }
       ^
  444. 
  445. static int warned_cfg = 0;

avconv.c:3425:9: Skipping exit_program(): empty list of specs
3423.     if (!oc) {
3424.         print_error(filename, AVERROR(ENOMEM));
3425.         exit_program(1);
              ^
3426.     }
3427. 

avconv.c:3428:9: Taking true branch
3426.     }
3427. 
3428.     if (o->format) {
              ^
3429.         file_oformat = av_guess_format(o->format, NULL, NULL);
3430.         if (!file_oformat) {

avconv.c:3429:9: Skipping av_guess_format(): empty list of specs
3427. 
3428.     if (o->format) {
3429.         file_oformat = av_guess_format(o->format, NULL, NULL);
              ^
3430.         if (!file_oformat) {
3431.             av_log(NULL, AV_LOG_FATAL, "Requested output format '%s' is not a suitable output format\n", o->format);

avconv.c:3430:14: Taking false branch
3428.     if (o->format) {
3429.         file_oformat = av_guess_format(o->format, NULL, NULL);
3430.         if (!file_oformat) {
                   ^
3431.             av_log(NULL, AV_LOG_FATAL, "Requested output format '%s' is not a suitable output format\n", o->format);
3432.             exit_program(1);

avconv.c:3443:5: 
3441.     }
3442. 
3443.     oc->oformat = file_oformat;
          ^
3444.     av_strlcpy(oc->filename, filename, sizeof(oc->filename));
3445. 

static void opt_output_file(void *optctx, const char *filename)
{
    OptionsContext *o = optctx;
    AVFormatContext *oc;
    int i, err;
    AVOutputFormat *file_oformat;
    OutputStream *ost;
    InputStream  *ist;
    if (!strcmp(filename, "-"))
        filename = "pipe:";
    oc = avformat_alloc_context();
    if (!oc) {
        print_error(filename, AVERROR(ENOMEM));
        exit_program(1);
    }
    if (o->format) {
        file_oformat = av_guess_format(o->format, NULL, NULL);
        if (!file_oformat) {
            av_log(NULL, AV_LOG_FATAL, "Requested output format '%s' is not a suitable output format\n", o->format);
            exit_program(1);
        }
    } else {
        file_oformat = av_guess_format(NULL, filename, NULL);
        if (!file_oformat) {
            av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for '%s'\n",
                   filename);
            exit_program(1);
        }
    }
    oc->oformat = file_oformat;
    av_strlcpy(oc->filename, filename, sizeof(oc->filename));
    if (!strcmp(file_oformat->name, "ffm") &&
        av_strstart(filename, "http:", NULL)) {
        int err = read_avserver_streams(o, oc, filename);
        if (err < 0) {
            print_error(filename, err);
            exit_program(1);
        }
    } else if (!o->nb_stream_maps) {
#define NEW_STREAM(type, index)\
        if (index >= 0) {\
            ost = new_ ## type ## _stream(o, oc);\
            ost->source_index = index;\
            ost->sync_ist     = &input_streams[index];\
            input_streams[index].discard = 0;\
        }
        if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {
            int area = 0, idx = -1;
            for (i = 0; i < nb_input_streams; i++) {
                ist = &input_streams[i];
                if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
                    ist->st->codec->width * ist->st->codec->height > area) {
                    area = ist->st->codec->width * ist->st->codec->height;
                    idx = i;
                }
            }
            NEW_STREAM(video, idx);
        }
        if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {
            int channels = 0, idx = -1;
            for (i = 0; i < nb_input_streams; i++) {
                ist = &input_streams[i];
                if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
                    ist->st->codec->channels > channels) {
                    channels = ist->st->codec->channels;
                    idx = i;
                }
            }
            NEW_STREAM(audio, idx);
        }
        if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {
            for (i = 0; i < nb_input_streams; i++)
                if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
                    NEW_STREAM(subtitle, i);
                    break;
                }
        }
    } else {
        for (i = 0; i < o->nb_stream_maps; i++) {
            StreamMap *map = &o->stream_maps[i];
            if (map->disabled)
                continue;
            ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
            switch (ist->st->codec->codec_type) {
            case AVMEDIA_TYPE_VIDEO:    ost = new_video_stream(o, oc);    break;
            case AVMEDIA_TYPE_AUDIO:    ost = new_audio_stream(o, oc);    break;
            case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
            case AVMEDIA_TYPE_DATA:     ost = new_data_stream(o, oc);     break;
            case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;
            default:
                av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n",
                       map->file_index, map->stream_index);
                exit_program(1);
            }
            ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
            ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
                                           map->sync_stream_index];
            ist->discard = 0;
        }
    }
    output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
    output_files[nb_output_files - 1].ctx       = oc;
    output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
    output_files[nb_output_files - 1].recording_time = o->recording_time;
    output_files[nb_output_files - 1].start_time     = o->start_time;
    output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
    av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);
    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
        if (!av_filename_number_test(oc->filename)) {
            print_error(oc->filename, AVERROR(EINVAL));
            exit_program(1);
        }
    }
    if (!(oc->oformat->flags & AVFMT_NOFILE)) {
        if (!file_overwrite &&
            (strchr(filename, ':') == NULL ||
             filename[1] == ':' ||
             av_strstart(filename, "file:", NULL))) {
            if (avio_check(filename, 0) == 0) {
                if (!using_stdin) {
                    fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
                    fflush(stderr);
                    if (!read_yesno()) {
                        fprintf(stderr, "Not overwriting - exiting\n");
                        exit_program(1);
                    }
                }
                else {
                    fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
                    exit_program(1);
                }
            }
        }
        if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
            print_error(filename, err);
            exit_program(1);
        }
    }
    if (o->mux_preload) {
        uint8_t buf[64];
        snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));
        av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);
    }
    oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
    oc->flags |= AVFMT_FLAG_NONBLOCK;
    if (o->chapters_input_file >= nb_input_files) {
        if (o->chapters_input_file == INT_MAX) {
            o->chapters_input_file = -1;
            for (i = 0; i < nb_input_files; i++)
                if (input_files[i].ctx->nb_chapters) {
                    o->chapters_input_file = i;
                    break;
                }
        } else {
            av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
                   o->chapters_input_file);
            exit_program(1);
        }
    }
    if (o->chapters_input_file >= 0)
        copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],
                      !o->metadata_chapters_manual);
    for (i = 0; i < o->nb_meta_data_maps; i++) {
        AVFormatContext *files[2];
        AVDictionary    **meta[2];
        int j;
#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
        if ((index) < 0 || (index) >= (nb_elems)) {\
            av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\
                     (desc), (index));\
            exit_program(1);\
        }
        int in_file_index = o->meta_data_maps[i][1].file;
        if (in_file_index < 0)
            continue;
        METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
        files[0] = oc;
        files[1] = input_files[in_file_index].ctx;
        for (j = 0; j < 2; j++) {
            MetadataMap *map = &o->meta_data_maps[i][j];
            switch (map->type) {
            case 'g':
                meta[j] = &files[j]->metadata;
                break;
            case 's':
                METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")
                meta[j] = &files[j]->streams[map->index]->metadata;
                break;
            case 'c':
                METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")
                meta[j] = &files[j]->chapters[map->index]->metadata;
                break;
            case 'p':
                METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")
                meta[j] = &files[j]->programs[map->index]->metadata;
                break;
            }
        }
        av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);
    }
    if (!o->metadata_global_manual && nb_input_files)
        av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,
                     AV_DICT_DONT_OVERWRITE);
    if (!o->metadata_streams_manual)
        for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {
            InputStream *ist = &input_streams[output_streams[i].source_index];
            av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
        }
    for (i = 0; i < o->nb_metadata; i++) {
        AVDictionary **m;
        char type, *val;
        int index = 0;
        val = strchr(o->metadata[i].u.str, '=');
        if (!val) {
            av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
                   o->metadata[i].u.str);
            exit_program(1);
        }
        *val++ = 0;
        parse_meta_type(o->metadata[i].specifier, &type, &index);
        switch (type) {
        case 'g':
            m = &oc->metadata;
            break;
        case 's':
            if (index < 0 || index >= oc->nb_streams) {
                av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index);
                exit_program(1);
            }
            m = &oc->streams[index]->metadata;
            break;
        case 'c':
            if (index < 0 || index >= oc->nb_chapters) {
                av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
                exit_program(1);
            }
            m = &oc->chapters[index]->metadata;
            break;
        default:
            av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
            exit_program(1);
        }
        av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
    }
    reset_options(o);
}
['static void opt_output_file(void *optctx, const char *filename)\n{\n    OptionsContext *o = optctx;\n    AVFormatContext *oc;\n    int i, err;\n    AVOutputFormat *file_oformat;\n    OutputStream *ost;\n    InputStream  *ist;\n    if (!strcmp(filename, "-"))\n        filename = "pipe:";\n    oc = avformat_alloc_context();\n    if (!oc) {\n        print_error(filename, AVERROR(ENOMEM));\n        exit_program(1);\n    }\n    if (o->format) {\n        file_oformat = av_guess_format(o->format, NULL, NULL);\n        if (!file_oformat) {\n            av_log(NULL, AV_LOG_FATAL, "Requested output format \'%s\' is not a suitable output format\\n", o->format);\n            exit_program(1);\n        }\n    } else {\n        file_oformat = av_guess_format(NULL, filename, NULL);\n        if (!file_oformat) {\n            av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for \'%s\'\\n",\n                   filename);\n            exit_program(1);\n        }\n    }\n    oc->oformat = file_oformat;\n    av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n    if (!strcmp(file_oformat->name, "ffm") &&\n        av_strstart(filename, "http:", NULL)) {\n        int err = read_avserver_streams(o, oc, filename);\n        if (err < 0) {\n            print_error(filename, err);\n            exit_program(1);\n        }\n    } else if (!o->nb_stream_maps) {\n#define NEW_STREAM(type, index)\\\n        if (index >= 0) {\\\n            ost = new_ ## type ## _stream(o, oc);\\\n            ost->source_index = index;\\\n            ost->sync_ist     = &input_streams[index];\\\n            input_streams[index].discard = 0;\\\n        }\n        if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {\n            int area = 0, idx = -1;\n            for (i = 0; i < nb_input_streams; i++) {\n                ist = &input_streams[i];\n                if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n                    ist->st->codec->width * ist->st->codec->height > area) {\n                    area = ist->st->codec->width * ist->st->codec->height;\n                    idx = i;\n                }\n            }\n            NEW_STREAM(video, idx);\n        }\n        if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {\n            int channels = 0, idx = -1;\n            for (i = 0; i < nb_input_streams; i++) {\n                ist = &input_streams[i];\n                if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&\n                    ist->st->codec->channels > channels) {\n                    channels = ist->st->codec->channels;\n                    idx = i;\n                }\n            }\n            NEW_STREAM(audio, idx);\n        }\n        if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {\n            for (i = 0; i < nb_input_streams; i++)\n                if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {\n                    NEW_STREAM(subtitle, i);\n                    break;\n                }\n        }\n    } else {\n        for (i = 0; i < o->nb_stream_maps; i++) {\n            StreamMap *map = &o->stream_maps[i];\n            if (map->disabled)\n                continue;\n            ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];\n            switch (ist->st->codec->codec_type) {\n            case AVMEDIA_TYPE_VIDEO:    ost = new_video_stream(o, oc);    break;\n            case AVMEDIA_TYPE_AUDIO:    ost = new_audio_stream(o, oc);    break;\n            case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;\n            case AVMEDIA_TYPE_DATA:     ost = new_data_stream(o, oc);     break;\n            case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;\n            default:\n                av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\\n",\n                       map->file_index, map->stream_index);\n                exit_program(1);\n            }\n            ost->source_index = input_files[map->file_index].ist_index + map->stream_index;\n            ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +\n                                           map->sync_stream_index];\n            ist->discard = 0;\n        }\n    }\n    output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);\n    output_files[nb_output_files - 1].ctx       = oc;\n    output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;\n    output_files[nb_output_files - 1].recording_time = o->recording_time;\n    output_files[nb_output_files - 1].start_time     = o->start_time;\n    output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;\n    av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);\n    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n        if (!av_filename_number_test(oc->filename)) {\n            print_error(oc->filename, AVERROR(EINVAL));\n            exit_program(1);\n        }\n    }\n    if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n        if (!file_overwrite &&\n            (strchr(filename, \':\') == NULL ||\n             filename[1] == \':\' ||\n             av_strstart(filename, "file:", NULL))) {\n            if (avio_check(filename, 0) == 0) {\n                if (!using_stdin) {\n                    fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n                    fflush(stderr);\n                    if (!read_yesno()) {\n                        fprintf(stderr, "Not overwriting - exiting\\n");\n                        exit_program(1);\n                    }\n                }\n                else {\n                    fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n                    exit_program(1);\n                }\n            }\n        }\n        if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n            print_error(filename, err);\n            exit_program(1);\n        }\n    }\n    if (o->mux_preload) {\n        uint8_t buf[64];\n        snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));\n        av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);\n    }\n    oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);\n    oc->flags |= AVFMT_FLAG_NONBLOCK;\n    if (o->chapters_input_file >= nb_input_files) {\n        if (o->chapters_input_file == INT_MAX) {\n            o->chapters_input_file = -1;\n            for (i = 0; i < nb_input_files; i++)\n                if (input_files[i].ctx->nb_chapters) {\n                    o->chapters_input_file = i;\n                    break;\n                }\n        } else {\n            av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\\n",\n                   o->chapters_input_file);\n            exit_program(1);\n        }\n    }\n    if (o->chapters_input_file >= 0)\n        copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],\n                      !o->metadata_chapters_manual);\n    for (i = 0; i < o->nb_meta_data_maps; i++) {\n        AVFormatContext *files[2];\n        AVDictionary    **meta[2];\n        int j;\n#define METADATA_CHECK_INDEX(index, nb_elems, desc)\\\n        if ((index) < 0 || (index) >= (nb_elems)) {\\\n            av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\\n",\\\n                     (desc), (index));\\\n            exit_program(1);\\\n        }\n        int in_file_index = o->meta_data_maps[i][1].file;\n        if (in_file_index < 0)\n            continue;\n        METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")\n        files[0] = oc;\n        files[1] = input_files[in_file_index].ctx;\n        for (j = 0; j < 2; j++) {\n            MetadataMap *map = &o->meta_data_maps[i][j];\n            switch (map->type) {\n            case \'g\':\n                meta[j] = &files[j]->metadata;\n                break;\n            case \'s\':\n                METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")\n                meta[j] = &files[j]->streams[map->index]->metadata;\n                break;\n            case \'c\':\n                METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")\n                meta[j] = &files[j]->chapters[map->index]->metadata;\n                break;\n            case \'p\':\n                METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")\n                meta[j] = &files[j]->programs[map->index]->metadata;\n                break;\n            }\n        }\n        av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);\n    }\n    if (!o->metadata_global_manual && nb_input_files)\n        av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,\n                     AV_DICT_DONT_OVERWRITE);\n    if (!o->metadata_streams_manual)\n        for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {\n            InputStream *ist = &input_streams[output_streams[i].source_index];\n            av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);\n        }\n    for (i = 0; i < o->nb_metadata; i++) {\n        AVDictionary **m;\n        char type, *val;\n        int index = 0;\n        val = strchr(o->metadata[i].u.str, \'=\');\n        if (!val) {\n            av_log(NULL, AV_LOG_FATAL, "No \'=\' character in metadata string %s.\\n",\n                   o->metadata[i].u.str);\n            exit_program(1);\n        }\n        *val++ = 0;\n        parse_meta_type(o->metadata[i].specifier, &type, &index);\n        switch (type) {\n        case \'g\':\n            m = &oc->metadata;\n            break;\n        case \'s\':\n            if (index < 0 || index >= oc->nb_streams) {\n                av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\\n", index);\n                exit_program(1);\n            }\n            m = &oc->streams[index]->metadata;\n            break;\n        case \'c\':\n            if (index < 0 || index >= oc->nb_chapters) {\n                av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\\n", index);\n                exit_program(1);\n            }\n            m = &oc->chapters[index]->metadata;\n            break;\n        default:\n            av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\\n", o->metadata[i].specifier);\n            exit_program(1);\n        }\n        av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);\n    }\n    reset_options(o);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n    AVFormatContext *ic;\n    ic = av_malloc(sizeof(AVFormatContext));\n    if (!ic) return ic;\n    avformat_get_context_defaults(ic);\n    return ic;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-32) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+32);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&31) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,32,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(32,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n    char errbuf[128];\n    const char *errbuf_ptr = errbuf;\n    if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n        errbuf_ptr = strerror(AVUNERROR(err));\n    av_log(NULL, AV_LOG_ERROR, "%s: %s\\n", filename, errbuf_ptr);\n}']