fast video encoding

David Bolen db3l.net at gmail.com
Fri Jul 31 12:40:34 EDT 2009


gregorth <gregor.thalhammer at gmail.com> writes:

> I am a novice with video encoding. I found that few codecs support
> gray scale images. Any hints to take advantage of the fact that I only
> have gray scale images?

I don't know that there's any good way around the fact that video
encoding is simply one of the heavier CPU-bound activities you're
likely to encounter.  So I suspect that codec choice (barring letting
quality drop a bit) is going to move the bar less than picking the
beefiest CPU you can.

If I were looking to do this, I'd probably include investigating
pumping the raw camera images into an ffmpeg encoding subprocess and
let it handle all the encoding.  There's about a gazillion options and
a variety of codec options to play with for performance.  You could
grab and store a short video sample from the camera and use it as a
benchmark to compare encoding options.

ffmpeg does have a -pix_fmt option that can be used to indicate the
input pixel type - "gray" would be 8-bit, and result in a 4:0:0 image
with a YUV-based encoder, for example.  Not sure how much, if any,
impact it would have on encoding speed though.

To be honest, with your data rate, I might even consider getting
Python out of the pure encoding path once it starts - depending on the
raw network format delivered by the camera you might be able to have
ffmpeg read directly from it.  Might not be worth it, since the data
transfer is probably I/O bound, but a 640x480x1 stream at 100Hz is
still nothing to sniff at, and even managing the raw data flow in
Python might eat up some CPU that you could better allocate to the
encoding process, or require extra data copies along the way that
would be best to avoid.

-- David



More information about the Python-list mailing list