动态修改码率

./ffmpeg -re -i /home/dafu.ts -vcodec libx264 -acodec aac -pcr_period 20 -muxdelay 0.700000 -muxrate 16000000 -maxrate 14405000 -minrate 14405000 -bufsize 14405000 -b:v 14405000 -b:a 128k -r 25 -bf 3 -f mpegts output.ts -loglevel debug

 

 

                //lvyunxiang add
                //static int my_count = 0;
                //my_count++;
                //printf("lvyunxiang test count=%d\n",my_count);
                //if(my_count == 10000000)
                static int re_open_flag = 0;
                if(cur_time - timer_start > 9000000 && re_open_flag == 0)
                {
                        re_open_flag = 1;
                        printf("lvyunxiang test output_streams[0]->enc_ctx->bit_rate=%d\n", output_streams[0]->enc_ctx->bit_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->rc_max_rate=%d\n", output_streams[0]->enc_ctx->rc_max_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->rc_min_rate=%d\n", output_streams[0]->enc_ctx->rc_min_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->width=%d\n", output_streams[0]->enc_ctx->width);
                        int frame_count = output_streams[0]->enc_ctx->frame_number;
                        avcodec_close(output_streams[0]->enc_ctx);
                        output_streams[0]->enc_ctx->bit_rate = 1000000;
                        output_streams[0]->enc_ctx->rc_max_rate = 1000000;
                        output_streams[0]->enc_ctx->rc_min_rate = 1000000;
                        output_streams[0]->enc_ctx->rc_buffer_size = 1000000;
                        output_streams[0]->enc_ctx->time_base = (AVRational){1, 25};
                        output_streams[0]->enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
                        output_streams[0]->enc_ctx->width = 1920;
                        output_streams[0]->enc_ctx->height = 1080;
                        output_streams[0]->enc_ctx->framerate = (AVRational) { 25, 1 };
                        output_streams[0]->enc_ctx->thread_count = 8;
                        output_streams[0]->enc_ctx->flags = AV_CODEC_FLAG_GLOBAL_HEADER;
                        output_streams[0]->enc_ctx->gop_size = 50;  //50帧一个关键帧

                        output_streams[0]->enc_ctx->max_b_frames = 0;  //最大的b帧数量

                        //修改st中的编码上下文
                        output_streams[0]->st->codec->bit_rate=1000000;
                        output_streams[0]->st->codec->rc_buffer_size=1000000;
                        output_streams[0]->st->codec->rc_max_rate=1000000;
                        output_streams[0]->st->codec->rc_min_rate=1000000;

       int ret = avcodec_open2(output_streams[0]->enc_ctx, output_streams[0]->enc, NULL);
                        /*
                         *          * FIXME: ost->st->codec should't be needed here anymore.
                         *      */
                        avcodec_copy_context(output_streams[0]->st->codec, output_streams[0]->enc_ctx);
                        avcodec_parameters_from_context(output_streams[0]->st->codecpar, output_streams[0]->enc_ctx);

                        printf("lvyunxiang test avcodec_open2 ret = %d\n",ret);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->bit_rate=%d\n", output_streams[0]->enc_ctx->bit_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->rc_max_rate=%d\n", output_streams[0]->enc_ctx->rc_max_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->rc_min_rate=%d\n", output_streams[0]->enc_ctx->rc_min_rate);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->width=%d\n", output_streams[0]->enc_ctx->width);
                        printf("lvyunxiang test output_streams[0]->enc_ctx->rc_buffer_size=%d\n", output_streams[0]->enc_ctx->rc_buffer_size);
                        output_streams[0]->enc_ctx->frame_number = frame_count;

                        av_dump_format(output_files[0]->ctx, 0, output_files[0]->ctx->url, 1);

                        if (output_streams[0]->enc_ctx->nb_coded_side_data) {
                                int i;
                                for (i = 0; i < output_streams[0]->enc_ctx->nb_coded_side_data; i++) {
                                        const AVPacketSideData *sd_src = &output_streams[0]->enc_ctx->coded_side_data[i];
                                        uint8_t *dst_data;
                                        dst_data = av_stream_new_side_data(output_streams[0]->st, sd_src->type, sd_src->size);
                                        if (!dst_data)
                                                return AVERROR(ENOMEM);
                                        memcpy(dst_data, sd_src->data, sd_src->size);
                                }
                        }

                        av_dump_format(output_files[0]->ctx, 0, output_files[0]->ctx->url, 1);

                        printf("lvyunxiang test output_streams[0]->st->codec->bit_rate=%d\n",output_streams[0]->st->codec->bit_rate);
                        printf("lvyunxiang test output_streams[0]->st->codec->rc_buffer_size=%d\n",output_streams[0]->st->codec->rc_buffer_size);
                        printf("lvyunxiang test output_streams[0]->st->codec->rc_max_rate=1000000=%d\n",output_streams[0]->st->codec->rc_max_rate=1000000);
                        printf("output_streams[0]->st->codec->rc_min_rate=%d\n",output_streams[0]->st->codec->rc_min_rate);
                }




 

 

 

-vsync 1 -async 1 -y -f bwsc_hdsdi -pixel_format yuv420p -video_size 1920x1080 -standard 1080i50 -audio_pr 1 -channel 2 -ar 48000 -i 1 -dts_error_threshold 10.0 -discontinuity_exit -channel_num 2 -snapshots 1 -log /var/log/transcoder_2.log -telnet_port 1701 -filter_complex [0:v]vmol[ol],[ol]split=outputs=1:[proxy0];[proxy0]scale=720:576[out0] -rtpflags +latm -aspect 16:9 -profile:v main -level 30 -bufsize 1124000 -minrate 1500000 -maxrate 1500000 -rc_init_occupancy 1350000 -bt 150000 -aud 1 -mbtree 0 -mixed-refs 0 -fast-pskip 1 -vflags +cgop -b_strategy 1 -b-bias 12 -trellis 0 -bidir_refine 0 -vflags +loop -deblock -2:-2 -cmp chroma -psy 0 -weightb 0 -weightp 1 -b-pyramid 0 -subq 4 -coder 1 -qcomp 0.01 -direct-pred auto -aq-strength 0.8 -i_qfactor 0.7 -b_qfactor 1.2 -nr 0 -x264opts chroma_qp_offset=12:ipratio=1.40:pbratio=1.20:force_cfr -partitions parti8x8+partp8x8 -pix_fmt yuv420p -r 25 -vflags +ildct+ilme -b:v 1500000 -rc-lookahead 4 -g 50 -keyint_min 5 -bf 3 -refs 1 -mbd 0 -me_method hex -me_range 16 -sc_threshold 40 -qmax 50 -qmin 13 -qdiff 4 -vcodec libx264 -map [out0]:v:0 -max_muxing_queue_size 1024 -b:a:0 32k -ar:a:0 48000 -ac:a:0 2 -codec:a:0 mp2 -map 0:a -f mpegts /usr/local/yckj/bin/.proxy0_out_fifo_t_channel1 -loglevel verbose -stats

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

*************************************

命令

ffmpeg 3.3

[Parsed_scale_1 @ 0xb3c9c0] w:1920 h:1080 fmt:yuvj420p sar:1/1 -> w:1920 h:1080 fmt:yuv420p sar:1/1 flags:0x2
[libx264 @ 0x75e7e0] using SAR=1/1
[libx264 @ 0x75e7e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x75e7e0] profile High, level 4.0
add stream index 0, pid 1, ost codec type 0
[mpegts @ 0x75cfc0] Retain service pids: service_id 1, pmt_pid 480, pcr_pid 481, service_name C3k service, provider_name C3k
[mpegts @ 0x75cfc0] rc_max_rate 8000000, rc_min_rate 8000000. cbr 1
[mpegts @ 0x75cfc0] codecpar[0] rate: 8000000, type 0
[mpegts @ 0x75cfc0] Retain stream 0 pid 481
[mpegts @ 0x75cfc0] stream i 0, codec id 28, codec type 0, pid 481, codecpar 28 0
[mpegts @ 0x75cfc0] codecpar[1] rate: 96000, type 1
[mpegts @ 0x75cfc0] Retain stream 1 pid 482
[mpegts @ 0x75cfc0] stream i 1, codec id 86016, codec type 1, pid 482, codecpar 86016 1
[mpegts @ 0x75cfc0] bitrate 8202000
[mpegts @ 0x75cfc0] nb_streams 2, cbr 1, mux_rate 8459000, pcr every 191 pkts, sdt every 2812, pat/pmt every 562 pkts, max_delay 700000, count_per_pkt 4800               固定码率

ffmpeg 4.2

[mpegts @ 0xf42fc0] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts            可变码率封装

 

 

 

 

 

 

 

./ffmpeg -re -i  /home/dafu.ts  -dts_error_threshold 10.0 -filter_complex split=outputs=1[proxy0],[proxy0]scale=1920:1080[out0] -rtpflags +latm -aspect 16:9 -profile:v main -level 30 -bufsize 1124000 -minrate 1500000 -maxrate 1500000 -rc_init_occupancy 1350000 -bt 150000 -aud 1 -mbtree 0 -mixed-refs 0 -fast-pskip 1 -vflags +cgop -b_strategy 1 -b-bias 12 -trellis 0 -bidir_refine 0 -vflags +loop -deblock -2:-2 -cmp chroma -psy 0 -weightb 0 -weightp 1 -b-pyramid 0 -subq 4 -coder 1 -qcomp 0.01 -direct-pred auto -aq-strength 0.8 -i_qfactor 0.7 -b_qfactor 1.2 -nr 0 -x264opts chroma_qp_offset=12:ipratio=1.40:pbratio=1.20:force_cfr -partitions parti8x8+partp8x8 -pix_fmt yuv420p -r 25 -vflags +ildct+ilme -b:v 1500000 -rc-lookahead 4 -g 50 -keyint_min 5 -bf 3 -refs 1 -mbd 0 -me_method hex -me_range 16 -sc_threshold 40 -qmax 50 -qmin 13 -qdiff 4 -vcodec libx264 -map [out0]:v:0 -max_muxing_queue_size 1024 -b:a:0 32k -ar:a:0 48000 -ac:a:0 2 -codec:a:0 mp2 -map 0:a -f mpegts output.ts -loglevel verbose -stats

posted @ 2020-10-13 09:52  虾兵  阅读(253)  评论(0编辑  收藏  举报