static int init_output_stream_streamcopy(OutputStream *ost)
{
    OutputFile *of = output_files[ost->file_index];
    InputStream *ist = get_input_stream(ost);
    AVCodecParameters *par_dst = ost->st->codecpar;
    AVCodecParameters *par_src = ist->st->codecpar;
    AVRational sar;
    int i;
    uint64_t extra_size;
    extra_size = (uint64_t)par_src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;
    if (extra_size > INT_MAX) {
        return AVERROR(EINVAL);
    }
    ost->st->disposition = ist->st->disposition;
    par_dst->codec_id   = par_src->codec_id;
    par_dst->codec_type = par_src->codec_type;
    if (!par_dst->codec_tag) {
        if (!of->ctx->oformat->codec_tag ||
             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_dst->codec_id ||
             av_codec_get_tag(of->ctx->oformat->codec_tag, par_src->codec_id) <= 0)
            par_dst->codec_tag = par_src->codec_tag;
    }
    par_dst->bit_rate        = par_src->bit_rate;
    par_dst->field_order     = par_src->field_order;
    par_dst->chroma_location = par_src->chroma_location;
    if (par_src->extradata) {
        par_dst->extradata       = av_mallocz(extra_size);
        if (!par_dst->extradata) {
            return AVERROR(ENOMEM);
        }
        memcpy(par_dst->extradata, par_src->extradata, par_src->extradata_size);
        par_dst->extradata_size = par_src->extradata_size;
    }
    ost->st->time_base = ist->st->time_base;
    if (ist->st->nb_side_data) {
        ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data,
                                              sizeof(*ist->st->side_data));
        if (!ost->st->side_data)
            return AVERROR(ENOMEM);
        for (i = 0; i < ist->st->nb_side_data; i++) {
            const AVPacketSideData *sd_src = &ist->st->side_data[i];
            AVPacketSideData *sd_dst = &ost->st->side_data[i];
            sd_dst->data = av_malloc(sd_src->size);
            if (!sd_dst->data)
                return AVERROR(ENOMEM);
            memcpy(sd_dst->data, sd_src->data, sd_src->size);
            sd_dst->size = sd_src->size;
            sd_dst->type = sd_src->type;
            ost->st->nb_side_data++;
        }
    }
    ost->parser = av_parser_init(par_dst->codec_id);
    ost->parser_avctx = avcodec_alloc_context3(NULL);
    if (!ost->parser_avctx)
        return AVERROR(ENOMEM);
    switch (par_dst->codec_type) {
    case AVMEDIA_TYPE_AUDIO:
        if (audio_volume != 256) {
            av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
            exit_program(1);
        }
        par_dst->channel_layout     = par_src->channel_layout;
        par_dst->sample_rate        = par_src->sample_rate;
        par_dst->channels           = par_src->channels;
        par_dst->block_align        = par_src->block_align;
        break;
    case AVMEDIA_TYPE_VIDEO:
        par_dst->format             = par_src->format;
        par_dst->width              = par_src->width;
        par_dst->height             = par_src->height;
        if (ost->frame_aspect_ratio)
            sar = av_d2q(ost->frame_aspect_ratio * par_dst->height / par_dst->width, 255);
        else if (ist->st->sample_aspect_ratio.num)
            sar = ist->st->sample_aspect_ratio;
        else
            sar = par_src->sample_aspect_ratio;
        ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
        break;
    case AVMEDIA_TYPE_SUBTITLE:
        par_dst->width  = par_src->width;
        par_dst->height = par_src->height;
        break;
    case AVMEDIA_TYPE_DATA:
    case AVMEDIA_TYPE_ATTACHMENT:
        break;
    default:
        abort();
    }
    return 0;
}
['static int init_output_stream_streamcopy(OutputStream *ost)\n{\n    OutputFile *of = output_files[ost->file_index];\n    InputStream *ist = get_input_stream(ost);\n    AVCodecParameters *par_dst = ost->st->codecpar;\n    AVCodecParameters *par_src = ist->st->codecpar;\n    AVRational sar;\n    int i;\n    uint64_t extra_size;\n    extra_size = (uint64_t)par_src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;\n    if (extra_size > INT_MAX) {\n        return AVERROR(EINVAL);\n    }\n    ost->st->disposition = ist->st->disposition;\n    par_dst->codec_id   = par_src->codec_id;\n    par_dst->codec_type = par_src->codec_type;\n    if (!par_dst->codec_tag) {\n        if (!of->ctx->oformat->codec_tag ||\n             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_dst->codec_id ||\n             av_codec_get_tag(of->ctx->oformat->codec_tag, par_src->codec_id) <= 0)\n            par_dst->codec_tag = par_src->codec_tag;\n    }\n    par_dst->bit_rate        = par_src->bit_rate;\n    par_dst->field_order     = par_src->field_order;\n    par_dst->chroma_location = par_src->chroma_location;\n    if (par_src->extradata) {\n        par_dst->extradata       = av_mallocz(extra_size);\n        if (!par_dst->extradata) {\n            return AVERROR(ENOMEM);\n        }\n        memcpy(par_dst->extradata, par_src->extradata, par_src->extradata_size);\n        par_dst->extradata_size = par_src->extradata_size;\n    }\n    ost->st->time_base = ist->st->time_base;\n    if (ist->st->nb_side_data) {\n        ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data,\n                                              sizeof(*ist->st->side_data));\n        if (!ost->st->side_data)\n            return AVERROR(ENOMEM);\n        for (i = 0; i < ist->st->nb_side_data; i++) {\n            const AVPacketSideData *sd_src = &ist->st->side_data[i];\n            AVPacketSideData *sd_dst = &ost->st->side_data[i];\n            sd_dst->data = av_malloc(sd_src->size);\n            if (!sd_dst->data)\n                return AVERROR(ENOMEM);\n            memcpy(sd_dst->data, sd_src->data, sd_src->size);\n            sd_dst->size = sd_src->size;\n            sd_dst->type = sd_src->type;\n            ost->st->nb_side_data++;\n        }\n    }\n    ost->parser = av_parser_init(par_dst->codec_id);\n    ost->parser_avctx = avcodec_alloc_context3(NULL);\n    if (!ost->parser_avctx)\n        return AVERROR(ENOMEM);\n    switch (par_dst->codec_type) {\n    case AVMEDIA_TYPE_AUDIO:\n        if (audio_volume != 256) {\n            av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\\n");\n            exit_program(1);\n        }\n        par_dst->channel_layout     = par_src->channel_layout;\n        par_dst->sample_rate        = par_src->sample_rate;\n        par_dst->channels           = par_src->channels;\n        par_dst->block_align        = par_src->block_align;\n        break;\n    case AVMEDIA_TYPE_VIDEO:\n        par_dst->format             = par_src->format;\n        par_dst->width              = par_src->width;\n        par_dst->height             = par_src->height;\n        if (ost->frame_aspect_ratio)\n            sar = av_d2q(ost->frame_aspect_ratio * par_dst->height / par_dst->width, 255);\n        else if (ist->st->sample_aspect_ratio.num)\n            sar = ist->st->sample_aspect_ratio;\n        else\n            sar = par_src->sample_aspect_ratio;\n        ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;\n        break;\n    case AVMEDIA_TYPE_SUBTITLE:\n        par_dst->width  = par_src->width;\n        par_dst->height = par_src->height;\n        break;\n    case AVMEDIA_TYPE_DATA:\n    case AVMEDIA_TYPE_ATTACHMENT:\n        break;\n    default:\n        abort();\n    }\n    return 0;\n}', 'void *av_realloc_array(void *ptr, size_t nmemb, size_t size)\n{\n    if (!size || nmemb >= INT_MAX / size)\n        return NULL;\n    return av_realloc(ptr, nmemb * size);\n}']