video_enc->strict_std_compliance = strict;
void opt_output_file(const char *filename){    AVStream *st;    AVFormatContext *oc;    int use_video, use_audio, nb_streams, input_has_video, input_has_audio;    int codec_id;    if (!strcmp(filename, "-"))        filename = "pipe:";    oc = av_mallocz(sizeof(AVFormatContext));    if (!file_oformat) {        file_oformat = guess_format(NULL, filename, NULL);        if (!file_oformat) {            fprintf(stderr, "Unable for find a suitable output format for '%s'\n",                    filename);            exit(1);        }    }        oc->oformat = file_oformat;    if (!strcmp(file_oformat->name, "ffm") &&         strstart(filename, "http:", NULL)) {        /* special case for files sent to ffserver: we get the stream           parameters from ffserver */        if (read_ffserver_streams(oc, filename) < 0) {            fprintf(stderr, "Could not read stream parameters from '%s'\n", filename);            exit(1);        }    } else {        use_video = file_oformat->video_codec != CODEC_ID_NONE;        use_audio = file_oformat->audio_codec != CODEC_ID_NONE;        /* disable if no corresponding type found and at least one           input file */        if (nb_input_files > 0) {            check_audio_video_inputs(&input_has_video, &input_has_audio);            if (!input_has_video)                use_video = 0;            if (!input_has_audio)                use_audio = 0;        }        /* manual disable */        if (audio_disable) {            use_audio = 0;        }        if (video_disable) {            use_video = 0;        }                nb_streams = 0;        if (use_video) {            AVCodecContext *video_enc;                        st = av_mallocz(sizeof(AVStream));            if (!st) {                fprintf(stderr, "Could not alloc stream\n");                exit(1);            }            avcodec_get_context_defaults(&st->codec);            video_enc = &st->codec;            if (video_stream_copy) {                st->stream_copy = 1;                video_enc->codec_type = CODEC_TYPE_VIDEO;            } else {                char *p;                int i;                            codec_id = file_oformat->video_codec;                if (video_codec_id != CODEC_ID_NONE)                    codec_id = video_codec_id;                                video_enc->codec_id = codec_id;                                video_enc->bit_rate = video_bit_rate;                video_enc->bit_rate_tolerance = video_bit_rate_tolerance;                video_enc->frame_rate = frame_rate;                                 video_enc->width = frame_width;                video_enc->height = frame_height;                if (!intra_only)                    video_enc->gop_size = gop_size;                else                    video_enc->gop_size = 0;                if (video_qscale || same_quality) {                    video_enc->flags |= CODEC_FLAG_QSCALE;                    st->quality = video_qscale;                }                            if (use_hq) {                    video_enc->flags |= CODEC_FLAG_HQ;                }                            if (use_4mv) {                    video_enc->flags |= CODEC_FLAG_HQ;                    video_enc->flags |= CODEC_FLAG_4MV;                }                            if(use_part)                    video_enc->flags |= CODEC_FLAG_PART;                                           if (b_frames) {                    if (codec_id != CODEC_ID_MPEG4) {                        fprintf(stderr, "\nB frames encoding only supported by MPEG-4.\n");                        exit(1);                    }                    video_enc->max_b_frames = b_frames;                    video_enc->b_frame_strategy = 0;                    video_enc->b_quant_factor = 2.0;                }                            video_enc->qmin = video_qmin;                video_enc->qmax = video_qmax;                video_enc->mb_qmin = video_mb_qmin;                video_enc->mb_qmax = video_mb_qmax;                video_enc->max_qdiff = video_qdiff;                video_enc->qblur = video_qblur;                video_enc->qcompress = video_qcomp;                video_enc->rc_eq = video_rc_eq;                video_enc->debug= debug;                                p= video_rc_override_string;                for(i=0; p; i++){                    int start, end, q;                    int e=sscanf(p, "%d,%d,%d", &start, &end, &q);                    if(e!=3){                        fprintf(stderr, "error parsing rc_override\n");                        exit(1);                    }                    video_enc->rc_override=                         realloc(video_enc->rc_override, sizeof(RcOverride)*(i+1));                    video_enc->rc_override[i].start_frame= start;                    video_enc->rc_override[i].end_frame  = end;                    if(q>0){                        video_enc->rc_override[i].qscale= q;                        video_enc->rc_override[i].quality_factor= 1.0;                    }                    else{                        video_enc->rc_override[i].qscale= 0;                        video_enc->rc_override[i].quality_factor= -q/100.0;                    }                    p= strchr(p, '/');                    if(p) p++;                }                video_enc->rc_override_count=i;                video_enc->rc_max_rate = video_rc_max_rate;                video_enc->rc_min_rate = video_rc_min_rate;                video_enc->rc_buffer_size = video_rc_buffer_size;                video_enc->rc_buffer_aggressivity= video_rc_buffer_aggressivity;                video_enc->rc_initial_cplx= video_rc_initial_cplx;                video_enc->i_quant_factor = video_i_qfactor;                video_enc->b_quant_factor = video_b_qfactor;                video_enc->i_quant_offset = video_i_qoffset;                video_enc->b_quant_offset = video_b_qoffset;                video_enc->dct_algo = dct_algo;                video_enc->idct_algo = idct_algo;                if(packet_size){                    video_enc->rtp_mode= 1;                    video_enc->rtp_payload_size= packet_size;                }                            if (do_psnr)                    video_enc->flags|= CODEC_FLAG_PSNR;                            video_enc->me_method = me_method;                /* two pass mode */                if (do_pass) {                    if (do_pass == 1) {                        video_enc->flags |= CODEC_FLAG_PASS1;                    } else {                        video_enc->flags |= CODEC_FLAG_PASS2;                    }                }                            /* XXX: need to find a way to set codec parameters */                if (oc->oformat->flags & AVFMT_RGB24) {                    video_enc->pix_fmt = PIX_FMT_RGB24;                }            }            oc->streams[nb_streams] = st;            nb_streams++;        }            if (use_audio) {            AVCodecContext *audio_enc;            st = av_mallocz(sizeof(AVStream));            if (!st) {                fprintf(stderr, "Could not alloc stream\n");                exit(1);            }            avcodec_get_context_defaults(&st->codec);            audio_enc = &st->codec;            audio_enc->codec_type = CODEC_TYPE_AUDIO;            if (audio_stream_copy) {                st->stream_copy = 1;            } else {                codec_id = file_oformat->audio_codec;                if (audio_codec_id != CODEC_ID_NONE)                    codec_id = audio_codec_id;                audio_enc->codec_id = codec_id;                                audio_enc->bit_rate = audio_bit_rate;                audio_enc->sample_rate = audio_sample_rate;                /* For audio codecs other than AC3 we limit */                /* the number of coded channels to stereo   */                if (audio_channels > 2 && codec_id != CODEC_ID_AC3) {                    audio_enc->channels = 2;                } else                    audio_enc->channels = audio_channels;            }            oc->streams[nb_streams] = st;            nb_streams++;        }        oc->nb_streams = nb_streams;        if (!nb_streams) {            fprintf(stderr, "No audio or video streams available\n");            exit(1);        }        if (str_title)            pstrcpy(oc->title, sizeof(oc->title), str_title);        if (str_author)            pstrcpy(oc->author, sizeof(oc->author), str_author);        if (str_copyright)            pstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright);        if (str_comment)            pstrcpy(oc->comment, sizeof(oc->comment), str_comment);    }    output_files[nb_output_files++] = oc;    strcpy(oc->filename, filename);    /* check filename in case of an image number is expected */    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {        if (filename_number_test(oc->filename) < 0) {            print_error(oc->filename, AVERROR_NUMEXPECTED);            exit(1);        }    }    if (!(oc->oformat->flags & AVFMT_NOFILE)) {        /* test if it already exists to avoid loosing precious files */        if (!file_overwrite &&             (strchr(filename, ':') == NULL ||             strstart(filename, "file:", NULL))) {            if (url_exist(filename)) {                int c;                                printf("File '%s' already exists. Overwrite ? [y/N] ", filename);                fflush(stdout);                c = getchar();                if (toupper(c) != 'Y') {                    fprintf(stderr, "Not overwriting - exiting\n");                    exit(1);                }            }        }                /* open the file */        if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {            fprintf(stderr, "Could not open '%s'\n", filename);            exit(1);        }    }    /* reset some options */    file_oformat = NULL;    file_iformat = NULL;    audio_disable = 0;    video_disable = 0;    audio_codec_id = CODEC_ID_NONE;    video_codec_id = CODEC_ID_NONE;    audio_stream_copy = 0;    video_stream_copy = 0;}