[Libav-user] Decode mjpeg stream from v4l2 web camera

Vlad Luzin luzinv at gmail.com
Mon May 2 21:19:39 CEST 2011


Hi all,

I have a web cam that can stream MJPEG or raw video. By default libav API
initializes raw video.
How can I read MJPEG stream?

Code below shows how I am doing it right now (my VideoEncoder reads stream
from webcam and encodes it into MPEG):

m_pInputFormat = av_find_input_format("video4linux2");

AVFormatParameters formatParams;
formatParams.channel   = 0;
formatParams.standard  = 0; // no standard
formatParams.width     = m_VideoEncoderSettings.WidthIn();
formatParams.height    = m_VideoEncoderSettings.HeightIn();
formatParams.time_base =
(AVRational){1,m_VideoEncoderSettings.FramesPerSecond()};
//formatParams.video_codec_id = CODEC_ID_MJPEG;

if (!OpenVideoFile  (m_pFormatCtx,
m_VideoEncoderSettings.DeviceName().c_str(), m_pInputFormat, &formatParams))
return (false);
if (!FindStreamInfo (m_pFormatCtx,
m_VideoEncoderSettings.DeviceName().c_str()))
                     return (false);
if (!FindVideoStream(m_pFormatCtx, m_VideoStream))
                                                                     return
(false);

I can set the resolution and the framerate using the above code but
switching do MJPEG doesn't work.

Any help will be highly appreciated.

Thank you,
Vlad.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110502/cdbf7c38/attachment.html>


More information about the Libav-user mailing list