Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding timeout to avformat_open_input

Tags:

c++

ffmpeg

I am trying to add timeout to the function avformat_open_input using dictionary options.

here is my code.

AVDictionary *dict = NULL; // "create" an empty dictionary
av_dict_set(&dict, "timeout", "6000", 0); // add an entry           
if (avformat_open_input(&av_format_ctx, "rtmp://192.168.1.2:1935/live/sum", NULL, &dict) < 0) {
    return false;
}

but the function does not wait for 6 seconds it exits immediately after being called.

like image 350
Summit Avatar asked Sep 18 '26 02:09

Summit


1 Answers

I know it is an old question, but anyhow... The timeout option is used in listen mode. According to the ffmpeg documentation:

timeout Set maximum timeout (in seconds) to wait for incoming connections. A value of -1 means infinite (default). This option implies the rtsp_flags set to listen.

Check the console after the error when trying to set the timeout option. I bet it is saying that it could not open the rtsp for listening. Use stimeout:

stimeout Set socket TCP I/O timeout in microseconds.

Pay double attention on the number of zeros (microseconds)

like image 136
Zsófi Ülkei Avatar answered Sep 19 '26 15:09

Zsófi Ülkei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!