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;
    uint32_t codec_tag = par_dst->codec_tag;
    int i, ret;
    if (!codec_tag) {
        if (!of->ctx->oformat->codec_tag ||
             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_src->codec_id ||
             av_codec_get_tag(of->ctx->oformat->codec_tag, par_src->codec_id) <= 0)
            codec_tag = par_src->codec_tag;
    }
    ret = avcodec_parameters_copy(par_dst, par_src);
    if (ret < 0)
        return ret;
    par_dst->codec_tag = codec_tag;
    ost->st->disposition = ist->st->disposition;
    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);
    if (par_dst->codec_type == AVMEDIA_TYPE_VIDEO) {
        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;
    }
    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    uint32_t codec_tag = par_dst->codec_tag;\n    int i, ret;\n    if (!codec_tag) {\n        if (!of->ctx->oformat->codec_tag ||\n             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_src->codec_id ||\n             av_codec_get_tag(of->ctx->oformat->codec_tag, par_src->codec_id) <= 0)\n            codec_tag = par_src->codec_tag;\n    }\n    ret = avcodec_parameters_copy(par_dst, par_src);\n    if (ret < 0)\n        return ret;\n    par_dst->codec_tag = codec_tag;\n    ost->st->disposition = ist->st->disposition;\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    if (par_dst->codec_type == AVMEDIA_TYPE_VIDEO) {\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    }\n    return 0;\n}', 'static InputStream *get_input_stream(OutputStream *ost)\n{\n    if (ost->source_index >= 0)\n        return input_streams[ost->source_index];\n    if (ost->filter) {\n        FilterGraph *fg = ost->filter->graph;\n        int i;\n        for (i = 0; i < fg->nb_inputs; i++)\n            if (fg->inputs[i]->ist->dec_ctx->codec_type == ost->enc_ctx->codec_type)\n                return fg->inputs[i]->ist;\n    }\n    return NULL;\n}']