I want to sure that did you test it in ABR mode? I have not used the CRF mode, 
but I will try it.




------------------ ???????? ------------------
??????:&nbsp;"Strahinja Radman"<[email protected]&gt;;
????????:&nbsp;2019??12??16??(??????) ????6:27
??????:&nbsp;"This list is about using libavcodec, libavformat, 
libavutil,libavdevice and libavfilter."<[email protected]&gt;;

????:&nbsp;Re: [Libav-user]??????  videorate realtime-adjusting



The change is gradual, not instant. It will change over time. At least it did 
in my testing of directly modifying the x264 code. Set it to crf 45 and then 
change to 12. It will do something for sure.

-------- Original message --------
From: ?????? <[email protected]&gt; 
Date: 16/12/2019  10:46  (GMT+01:00) 
To: "This list is about using libavcodec, libavformat, libavutil,libavdevice 
and libavfilter." <[email protected]&gt; 
Subject: [Libav-user] ??????&nbsp; videorate realtime-adjusting 



Excuse me, I have called the API-'reconfig_encoder' to controll the bitrate of 
X264-encoder in real time, but I found it didn't work by network monitor. I 
changed the&nbsp; AVCodecContext-&gt;bit_rate \ AVCodecContext-&gt;rc_max_rate 
\&nbsp; AVCodecContext-&gt;rc_buffer_size. And I checked the return value of 
'x264_encoder_reconfig' which equals to zero. So whats the problem? 


------------------ ???????? ------------------
??????:&nbsp;"Strahinja Radman"<[email protected]&gt;;
????????:&nbsp;2019??12??2??(??????) ????5:03
??????:&nbsp;"This list is about using libavcodec, libavformat, 
libavutil,libavdevice and libavfilter."<[email protected]&gt;;

????:&nbsp;Re: [Libav-user] videorate realtime-adjusting






On Mon, Dec 2, 2019 at 9:29 AM ?????? <[email protected]&gt; wrote:

I have a question. How can I modify the video-encode bitrate in real time 
during coding after the video encoder has been turned on? Here's what I did 
(take x264-encoder as an example) :


step1.
Modified the definition of structural AVCoder to add a function pointer.
        int (*valid_context)(AVCodecContext*);


step2.
Added function definition to enable the codec rate of x264.
static int X264_config(AVCodecContext* avctx){
&nbsp; &nbsp; X264Context* x4 = avctx-&gt;priv_data;
&nbsp; &nbsp; if(avctx-&gt;bit_rate){
&nbsp; &nbsp; &nbsp; &nbsp; x4-&gt;params.rc.i_bitrate = avctx-&gt;bit_rate / 
1000;
&nbsp; &nbsp; }
&nbsp; &nbsp; avctx-&gt;bit_rate = x4-&gt;params.rc.i_bitrate*1000;
&nbsp; &nbsp; return 0;
}


step3.
build AVCodec.
AVCodec ff_libx264_encoder = {
&nbsp; &nbsp; .name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= "libx264",
&nbsp; &nbsp; .long_name&nbsp; &nbsp; &nbsp; &nbsp; = 
NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
&nbsp; &nbsp; .type&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 
AVMEDIA_TYPE_VIDEO,
&nbsp; &nbsp; .id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 
AV_CODEC_ID_H264,
&nbsp; &nbsp; .priv_data_size&nbsp; &nbsp;= sizeof(X264Context),
&nbsp; &nbsp; .init&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= X264_init,
&nbsp; &nbsp; //
&nbsp; &nbsp; .valid_context&nbsp; &nbsp; = X264_config,
&nbsp; &nbsp; //
&nbsp; &nbsp; .encode2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = X264_frame,
&nbsp; &nbsp; .close&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = X264_close,
&nbsp; &nbsp; .capabilities&nbsp; &nbsp; &nbsp;= AV_CODEC_CAP_DELAY | 
AV_CODEC_CAP_AUTO_THREADS,
&nbsp; &nbsp; .priv_class&nbsp; &nbsp; &nbsp; &nbsp;= &amp;x264_class,
&nbsp; &nbsp; .defaults&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= x264_defaults,
&nbsp; &nbsp; .init_static_data = X264_init_static,
&nbsp; &nbsp; .caps_internal&nbsp; &nbsp; = FF_CODEC_CAP_INIT_THREADSAFE |
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; FF_CODEC_CAP_INIT_CLEANUP,
&nbsp; &nbsp; .wrapper_name&nbsp; &nbsp; &nbsp;= "libx264",
};


step4.
FFmpeg interface layer.
int attribute_align_arg avcodec_valid_codec_Context(AVCodecContext* avctx){
&nbsp; &nbsp; int ret = 0;
&nbsp; &nbsp; ret = avctx-&gt;codec-&gt;valid_context(avctx);
&nbsp; &nbsp; if(ret){
&nbsp; &nbsp; &nbsp; &nbsp; av_log(avctx, AV_LOG_ERROR, "valid context error, 
ERROR CODE:%d\n", 
                ret);
&nbsp; &nbsp; }
&nbsp; &nbsp; return ret;
}


step5.
Whenever the application layer needs to modify the bit rate, then App should 
modify the AVCodecContext-&gt; bit_rate, and then call the above interface to 
make the Context take effect in the encoder.


Because of the limited understanding of ffmpeg. So if there is a better way, 
also hope to give instruction.

_______________________________________________
 Libav-user mailing list
 [email protected]
 https://ffmpeg.org/mailman/listinfo/libav-user
 
 To unsubscribe, visit link above, or email
 [email protected] with subject "unsubscribe".



Well, according to the libx264.c wrapper and x264's encoder.c code, one can 
simply change the value
of bitrate, bufsize, maxrate or crf in AVCodecContext, and reconfig_encoder 
will invoke x264's internal
API that will reconfigure the encoder with one or more of the previously 
mentioned values. That should
be it. The change will be triggered on the next sent frame. Checkout the source 
of libx264.c line 186.


-- 

Regards
Strahinja Radman
_______________________________________________
Libav-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to