[FFmpeg-user] Capturing video and audio from web camera

Денис Горденин denis.g at dssl.ru
Thu Feb 19 14:22:58 CET 2015


Hello.
I want to capture video and audio programmatically. I did it in a version
for Windows of our software. Now I cannot do it in a version for Linux. So,
I do:

        {
            MM::FFMPEG_LOCK fflock(mm);
            av_register_all();
            avdevice_register_all();
            av_log_set_level( AV_LOG_VERBOSE );
        }

AVInputFormat* input_format;
AVFormatContext* format_context;

format_context = avformat_alloc_context();
input_format = av_find_input_format("v4l2");

int err;
if ((err = avformat_open_input(&format_context, "/dev/video0",
input_format, &dict)) != 0)
{
            log_timestamp("USB grabber error: avformat_open_input returned
%d, %s\n", err, get_av_error(err).c_str());
            return;
}

Here I always get only a video stream. How can I get audio (with) video?
Using this command line:
ffmpeg -f video4linux2 -i /dev/video0 -f alsa -ac 1 -i hw:2 camera.mp4
I get a file with video and audio. How can I pass parameters "-f alsa -ac 1
-i hw:2" to avformat_open_input?


More information about the ffmpeg-user mailing list