2

With the following command i'm trying to capture 10fps and send them the device driver. Now i want 8 bit gray raw frames (640x480= 307200 bytes per frame) to be send to the device driver. I can't figure out how to set the output with ffmpeg or the intput with v4l2 to this format.

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 -f rawvideo "/dev/devicedriver"

ffmpeg doesn't seem to support 8-bit gray output. And with v4l2 i can't figure out how to set it. It seems it doesn't recoginize V4L2_PIX_FMT_GREY.

v4l2-ctl --set-fmt-video-out=width=640,height=480,pixelformat=V4L2_PIX_FMT_GREY

I came up with a solution combining python, opencv and ffmpeg:

import cv
import sys
import os
import time
camera_index = 0 
capture = cv.CaptureFromCAM(camera_index)
count = 0
def repeat():
    global capture
    global camera_index
    global count
    frame = cv.GetMat(cv.QueryFrame(capture))
    framegray = cv.CreateMat(480, 640, cv.CV_8UC1)
    cv.CvtColor(frame, framegray, cv.CV_BGR2GRAY)
    sys.stdout.write(framegray.tostring())
    c = cv.WaitKey(1)
    if c == 27:
        print count
        sys.exit()

while True:
    repeat()

and then pipe it to ffmpeg

python capturewebcam.py | ffmpeg -f rawvideo -pix_fmt gray -s 640x480 -i - -an -f rawvideo -r 10 "/dev/null"

But i think it really has to be possible with just ffmpeg and v4l2, and i can't figure out how. My head hurts from reading the documentation :p.

1

First, check pixel formats are supported by your output device driver:

v4l2-ctl --list-formats -d /dev/devicedriver

the pixelformat you want to pass to the v4l2-ctl command line is the fourcc shown in the result, eg:

Pixel Format  : 'YUYV'

in this case your command line would be:

v4l2-ctl --set-fmt-video-out=width=640,height=480,pixelformat=YUYV

If you need V4L2_PIX_FMT_GREY probably the fourcc will be 'GREY' (I guess from videodev2.h, can't check)

If it is not in the result of the list-formats command it is not supported by the driver, so you'll need some conversion from the source (input/camera) format to the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.