[Libav-user] How can we set frame size for live stream?

Stefano Sabatini stefasab at gmail.com
Tue Nov 6 01:32:04 CET 2012


In data Wednesday 2012-10-31 14:22:40 +0200, Wenpeng Zhou ha scritto:
> Hi,
> 
> I use the USB camera to capture live video.
> 
> The default codec context is:
> Input #0, dshow, from 'video=Mercury USB2.0 Camera':
>   Duration: N/A, start: 58890.453000, bitrate: N/A
>     Stream #0:0: Video: mjpeg, yuvj422p, 1280x720, 30 tbr, 10000k tbn, 30
> tbc
> 
> I hope to change frame size from 1280x720 to 640x480. 
> 
> I tried 
> AVCodecContext
> pCodecCtx->width = 640;
>   pCodecCtx->height = 480;
> 
> But this did not work.

You can set the options in the dshow device, using the *private*
option "video_size":
http://ffmpeg.org/ffmpeg.html#dshow

Note that the input device may not honour the exact video size, or may
choose a video size that is "reasonably" similar to the one requested
(need to check the code for that, documentation updates are welcome).

>From a programmatic point of view, you need to set the options for the
input format context in a dictionary and pass it to
avformat_open_input(), something like:

AVDictionary *options = NULL;
av_dict_set(&options, "video_size", "640x480", 0);
av_dict_set(&options, "pixel_format", "rgb24", 0);

if (avformat_open_input(&s, url, NULL, &options) < 0)
   abort();
...
av_dict_free(&options);

Check avformat.h doxy for more information.


More information about the Libav-user mailing list