[libav-api] Win32 webcam: vfw_read_packet(). No data present and mutex acquisition failure

Roderick Hodgson roderick.hodgson at googlemail.com
Wed Apr 17 19:00:21 CEST 2013


I have a windows/linux working application using libav to uncompress
various video formats. I want to extend it to use webcam input as well
as file inputs.

For linux I have had a go using av_find_input_format("video4linux2").
That seems to work fine.

For windows, I have seen a few samples using vfwcap. I have also seen
various comments alluding to its obsolescence. I proceeded with
cautious optimism, noting I can successfully view my webcam on windows
with ffplay -f vfwcap -i 0.

However, when I try to integrate vfwcap into my application, the
application runs avformat_open_input fine(), but then locks up on
avformat_find_stream_info(). This happens at the point at which it
calls vfw_read_packet() (in libavdevice/vfwcap.c). After it fails to
find data on priv_data->pktl, it calls WaitForSingleObject(ctx->event,
INFINITE), and waits...

Based on this information, the problem as far as I can work out,
appears to be a permanent lack of data in priv_data->pktl. I'm
expecting this data gets populated by another thread somewhere. I
can't tell which, though.

Perhaps worth mentioning, is that I notice after I call
avformat_open_input(), that VFormatContext->iformat is populated, but
AVFormatContext->oformat is NULL . I attempted to add some
AVDictionary entries, to see if that fixed the issue, to no avail.

I have also tried skipping the call to avformat_find_stream_info and
populating the fields myself. But the issue just occurs further down
the line, once it attempts to retrieve frames.

What surprises me most, is that ffplay (and ffmpeg) definitely works
with vfwcap. (However, I am using the pre-built binaries in this

Below is my problematic code:

        demuxerContext = avformat_alloc_context(); //all the
information about the source mux
        AVInputFormat* pInfmt = NULL;
        AVDictionary* options = NULL;
        if (strcmp(filename, "0")==0) {
            pInfmt = av_find_input_format("vfwcap");
            av_dict_set(&options, "video_size", "640x480", 0);
            av_dict_set(&options, "pixel_format", "yuyv422", 0);
            //demuxerContext->flags = AVFMT_FLAG_NONBLOCK;
        else if (strcmp(filename, "/dev/video0")==0) {
            pInfmt = av_find_input_format("video4linux2");
            av_dict_set(&options, "video_size", "640x480", 0);
            av_dict_set(&options, "pixel_format", "yuyv422", 0);
        //open source and read the header
        int opencode = avformat_open_input(&demuxerContext, filename,
pInfmt, &options);
        if(opencode!=0) {
            return 0;

        //try to derive stream info from data
        if (avformat_find_stream_info(demuxerContext, &options) < 0) {
           //this line never gets reached!

I built libav with mingw and with the following configure:
../configure --enable-w32threads --prefix=/usr --arch=i686
--target-os=mingw32 --enable-memalign-hack --enable-shared

Any help or advice working out why priv_data->pktl is resolutely NULL
would be really appreciated!

Best regards,

More information about the libav-api mailing list