Av_interleaved_write_frame Exit slower

Source: Internet
Author: User

Use LIBVLC to do the live push-flow engine
In the case of poor networks, it is necessary to turn off the live broadcast and re-launch it.
In this process, the push-stream engine restarts, requiring a quick response.
In fact, the test results found that the engine shut-down interface often happens to get stuck.
Later the tracking code, located in the S_rtmp_send_thread ()
One sentence:
ret = Av_interleaved_write_frame (Formatcontext, PKT);
This method in the case of a better network, usually a few milliseconds to return the success of the send.
Then in the case of poor network, will remain stuck here, no return ...

Tracking FFmpeg code, the implementation of this method in MUX.C
Libavformat/mux.c
Av_interleaved_write_frame ()
Write_packet () really write data
ret = S->oformat->write_packet (s, PKT);
Write_packet here is a pointer defined in Avformat.h, pointing to Flv_write_packet ()

Follow the code in one step, discover the time-out control about network read and write, define in Url.h

struct/**< maximum time to wait for (network) Read/write ...} Urlcontext;

So in the initialization place, set this parameter:

LIBAVFORMAT/AVIO.C--->
Add the following statement before Url_alloc_for_protocol () return

Network read-write timeout control at 800ms

if (0800000)        UC800000;

Back to the project, the output time at both ends of the av_interleaved_write_frame, it is found that the interface in the network is not good, the basic control within 1s. Then it is not precise time control. Seemingly ffmpeg itself can not be strictly controlled to the millisecond level.

In order to ensure that this return must be answered, the LIBAVFORMAT/MUX.C
Modify the following code in Av_interleaved_write_frame ():

For

This uncontrolled for loop, instead

int  - ; int nn;  for (nn=0; nn<mouttimes;nn++)

The 128 here is an empirical value.

Av_interleaved_write_frame Exit slower

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.