[Libav-user] Check an address to see if there is any video stream on it or not

Евгений Гарифуллин grisme at yandex.ru
Sun Jan 12 17:38:51 CET 2014

12.01.2014, 22:23, "Hadi" <hadi.hadizadeh at hotmail.com>:
> I want to read a video stream from a UDP address using libavcodec functions. To do so, I use the following code:
> char *url = "udp://";
> AVFormatContext *oc = NULL;
> avformat_open_input(&oc, url, NULL , NULL);
> If we run this code, then function "avformat_open_input" starts listening on the given UDP address, and it looks like the program is halted if there is no video stream at the given UDP address.
> Now, I want to write a code to first check the given UDP address quickly to see whether there is any data on it or not, if there is no data then the program should neglect running "avformat_open_input", otherwise it should run this function so that I can avoid the halting situation.
> Any idea how I can do this? Thanks!
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

use interrupt_callback function to "unblock" avformat_open_input(...);

time_t check_timestamp;

static int interrupt_cb(void* inputdata)
  time_t current_timestamp;
  current_timestamp = time(0)
  if (current_timestamp - check_timestamp >= 10)
    return true;  // interrupt blocked function
    return false; // NOT interrupt, wait more seconds...
oc = avformat_allocate_context();
oc->interrupt_callbacl = (AVIOInterruptCB){interrupt_cb, NULL};
checl_timestamp = time(0);
if (avformat_open_input(&oc, url, NULL , NULL) < 0)
   // error processing

something like that :) if avformat_open_input frezzes more than 10 seconds (in this example), interrupt_cb will break it execution.

С уважением, Евгений Гарифуллин.
e-mail: grisme at yandex.ru
jabber: joffadark at jabber.ufanet.ru
ICQ : 387906261

More information about the Libav-user mailing list