windowsusbffmpegwebcamc#

FFmpeg function avformat_open_input for USB video device throws exception: No such file or directory


Windows & C# & FFmpeg.AutoGen

I used the ffmpeg-function (from library FFmpeg.AutoGen) to show video from rtsp-stream:

ffmpeg.avformat_open_input(&pFormatContext, "rtsp://127.0.0.1:8554/abc", iformat, null);

It works right.

Now I want to use this function for USB video device.

FFmpeg outputs this device name:

ffmpeg -list_devices true -f dshow -i dummy

[dshow @ 0000000000163000] "GENERAL WEBCAM" (video)

This is how I'm trying to get the video:

string deviceName = "GENERAL WEBCAM";

or

string deviceName = "video=GENERAL WEBCAM";

ffmpeg.avformat_open_input(&pFormatContext, deviceName, ffmpeg.av_find_input_format("dshow"), null);

For both variants of device names, I get an error:

No such file or directory.

But here it works:

ffmpeg -video_size 1280x720 -framerate 30 -f dshow -i video="GENERAL WEBCAM":audio="Microphone (3- GENERAL WEBCAM)" -c:v libx264 -crf 30 -preset ultrafast ffmpegvideo.mp4

Why doesn't avformat_open_input work with video device name?


Solution

  • Before using ffmpeg.av_find_input_format("dshow"), we must execute:

    ffmpeg.avdevice_register_all();
    

    I am not promising that it's going to solve all your issues...