[Libav-user] Grabbing video from webcam

Luke Clemens lclemens at gmail.com
Thu Mar 29 23:16:37 CEST 2012


yes, libavformat and libavcodec will work for that.

in general...

inFormat = avformat_open_input(...);
outFormat = avformat_alloc_context(...);

for each input stream () {
    avcodec_find_decoder();
    avcodec_find_encoder();
    avcodec_open(outFormat);
    avcodec_open(inFormat);
}

avio_open(outFormat->pb);
av_write_header(outFormat);

while (1) {
    frame = av_read_frame();
    if (you need to change codec or modify the video somehow) {
        if (frame is video) {
            decodedFrame = avcodec_decode_video2(frame);
            encodedFrame = avcodec_encode_video(decodedFrame);
            writeframe(encodedFrame);
        } else if (frame is audio) {
            decodedFrame = avcodec_decode_audio3(frame);
            encodedFrame = avcodec_encode_audio(encodedFrame);
            writeframe(encodedFrame);
        }
    } else {
         av_write_frame(frame);
    }
}

av_close_input_file(inFormat);
avio_close(outFormat);


--luke

On Tue, Jan 24, 2012 at 4:43 PM, Ognen Duzlevski
<ognen.duzlevski at gmail.com>wrote:

> Hello,
>
> I am just beginning to dabble with video and sound programming on Linux.
> For starters I just want to make a simple program to grab a video from a
> webcam and record it. Can ffmpeg be used for this? Where do I find
> documentation on the API involved and, in general, where do I start? :)
>
> Thanks!
> OD
>
> --
> "Before you start searching for happiness, think about it - maybe you are
> already happy? Happiness is common, often invisible and many people usually
> can't see it." -- Dusko Radovic
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>


-- 
-
-
-
-
Luke Clemens
http://clemens.bytehammer.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120329/6a71bccb/attachment.html>


More information about the Libav-user mailing list