@@ -1053,23 +1053,48 @@ AVStream* FFmpegWriter::add_video_stream()
10531053 }
10541054#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 39, 101)
10551055 else {
1056- switch (c->codec_id ) {
1057- case AV_CODEC_ID_VP8 :
1058- av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,63 ), 0 );
1059- break ;
1060- case AV_CODEC_ID_VP9 :
1061- av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,63 ), 0 );
1062- if (info.video_bit_rate == 0 ) {
1063- av_opt_set_int (c->priv_data , " lossless" , 1 , 0 );
1064- }
1065- break ;
1066- case AV_CODEC_ID_H264 :
1067- av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,51 ), 0 );
1068- break ;
1069- case AV_CODEC_ID_H265 :
1070- av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,51 ), 0 );
1071- break ;
1072- }
1056+ if (hw_en_on) {
1057+ double mbs = 15000000.0 ;
1058+ if (info.video_bit_rate > 0 ) {
1059+ if (info.video_bit_rate > 42 ) {
1060+ mbs = 380.0 ;
1061+ }
1062+ else {
1063+ mbs *= pow (0.912 ,info.video_bit_rate );
1064+ }
1065+ }
1066+ c->bit_rate = (int )(mbs);
1067+ }
1068+ else {
1069+ switch (c->codec_id ) {
1070+ case AV_CODEC_ID_VP8 :
1071+ av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,63 ), 0 );
1072+ break ;
1073+ case AV_CODEC_ID_VP9 :
1074+ av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,63 ), 0 );
1075+ if (info.video_bit_rate == 0 ) {
1076+ av_opt_set_int (c->priv_data , " lossless" , 1 , 0 );
1077+ }
1078+ break ;
1079+ case AV_CODEC_ID_H264 :
1080+ av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,51 ), 0 );
1081+ break ;
1082+ case AV_CODEC_ID_H265 :
1083+ av_opt_set_int (c->priv_data , " crf" , min (info.video_bit_rate ,51 ), 0 );
1084+ break ;
1085+ default :
1086+ double mbs = 15000000.0 ;
1087+ if (info.video_bit_rate > 0 ) {
1088+ if (info.video_bit_rate > 42 ) {
1089+ mbs = 380.0 ;
1090+ }
1091+ else {
1092+ mbs *= pow (0.912 ,info.video_bit_rate );
1093+ }
1094+ }
1095+ c->bit_rate = (int )(mbs);
1096+ }
1097+ }
10731098 }
10741099#endif
10751100
0 commit comments