[FFmpeg-trac] #1389(undetermined:new): UVC web cam with hardware h264 encoder - input bitrate

FFmpeg trac at avcodec.org
Sat Jun 2 01:15:48 CEST 2012

#1389: UVC web cam with hardware h264 encoder - input bitrate
             Reporter:  burek        |                     Type:  task
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
 I'm not quite sure if this is already possible using FFmpeg, but I'll ask
 just to be sure and if the feature is not present, I'll suggest that it
 will be implemented.

 I was talking with a guy from #v4l channel about an usb web cam that has
 internal (hardware) h264 encoder and can provide 3 types of video streams,
 over the usb cable, to a linux machine: rawvideo, mjpeg and h264. He told
 me (I'll copy/paste the log, just to avoid any confusion, because I'm not
 even closely an expert in this area) that FFmpeg can grab the video from
 the camera either using v4l2 or natively, using IOCTL commands.

 Now, the camera is capable of setting the bitrate that will be used to
 encode the stream. Meaning, it would be possible (hypothetically) to use
 it like this:

 ffmpeg -f v4l2 -b:v 320k -s cif -r 30 -i /dev/video0 ...

 to get the input from the camera at the specified bitrate (that will
 camera's hardware use as an encoding parameter to provide the video of
 that quality). This is very cool since it frees your linux machine from
 the cpu utilization and encoding to h264.

 Can this be implemented/supported by FFmpeg, since, if I got it correctly,
 it is possible to send a kind of "ioctl (fd, UVCIOC_CTRL_QUERY, &xu)" to
 the web cam to request the specified bitrate?

 Here is the cutted/formatted log (only important stuff was left) for those
 who know what this is all about (I've just replaced the guys nickname with
 * to keep his privacy, if needed):


 <xx> burek, if those apps don't support the uvc h264 specification, then
 you can't control bitrate
 <burek> vlc does :)
 <xx> they'd need to send an IOCTL to the uvc driver to control it
 <burek> I already managed that but I don't know how to tell it to use less
 bitrate when sending me video stream over usb
 <xx> 1sec, I'll look at what vlc does
 <burek> ok, thx :)
 <xx> burek, it doesn't, latest git doesn't support uvc h264, grep UVC *
 -RI gave nothing
 <burek> well, it does, I'm actually using it and testing it right now
 <xx> burek, no, it only does v4l2 which supports h264, but it doesn't do
 this : ioctl (fd, UVCIOC_CTRL_QUERY, &xu);
 <burek> oh, I see, well, ffmpeg also supports v4l2 but somehow doesn't
 handle the h264 :/
 <xx> it needs to call the UVC driver's ioctl in order to *control* the
 <xx> all it does is use v4l2 to capture h264 in whatever default settings
 the hardware has
 <xx> it needs support for the h264 uvc 1.0 specification and should use
 the h264 XU from the camera in order to control it
 <xx> because it has to be configured after opening the device and just
 before setting the v4l2 format
 <burek> shortly speaking, is it possible to set the encoding bit rate,
 like that?
 <xx> no, vlc would need to be modified to support the uvc spec
 <burek> I'm just curious, if there was an application that has h264 uvc
 1.0 implemented and all that, could it set the encoding bitrate
 <burek> I can grab the video from usb web cam now (using h264 video stream
 over usb), but the bitrate of that video stream is too high, even for
 320x240 video.. so, I'm looking for a way to lower the bitrate if
 possible, without having to re-encode the video
 <xx> burek, yes, yes, implementing the uvc h264 spec means you get to
 control all of the encoding parameters that the hardware supports
 <xx> the uvc h264 spec has nothing to do with brightness/zoom/whatever,
 it's all about bitrate, cabac/cavlc, slices per frame/long term references
 frames, stream format, realtime/storage/broadcast usage mode,
 cbr/vbr/const_qp, min_qp/max_qp, b frames, baseline/high/main profiles,
 <xx> allows to request keyframes, change bitrate dynamically, etc...
 that's all the spec explains, the API to control all this stuff
 <xx> burek, the bitrate on that camera is by default 3000000 bits/second
 <burek> i thought there was a tool like v4l2-ctl that sets the "default"
 <burek> so I could use it to workaround my issue until the native support
 for such thing is developed in player applications
 <burek> after which I would normally just specify which bitrate I prefer..
 thanks a lot for explaining all this
 <xx> burek, default is in the hardware, as soon as you 'close' the file
 descriptor, it resets back to default, it must be configured while the
 device is open

Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/1389>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list