ffmpegh.264video4linux

How to capture h264 with ffmpeg


I'm trying to capture h264 with ffmpeg and send it to my virtual device. I can capture YUYV and send it with this command:

ffmpeg -f video4linux2 -s 1920x1080 -i /dev/video0 -vcodec copy -f v4l2 /dev/video3

Then I tried this to capture h264 instead of YUYV:

ffmpeg -f video4linux2 -input_format h264 -s 1920x1080 -i /dev/video0 -vcodec copy -f v4l2 /dev/video3

Then ffmpeg returns the error statement:

V4l2 output device supports only a single raw video stream

Does anybody know the correct command or what's wrong?


Solution

  • Like the error message states it needs a single, raw video stream and not a H.264 raw stream:

    if (s1->nb_streams != 1 ||
           s1->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
           s1->streams[0]->codec->codec_id   != AV_CODEC_ID_RAWVIDEO) {
           av_log(s1, AV_LOG_ERROR,
                   "V4L2 output device supports only a single raw video stream\n");
           return AVERROR(EINVAL);
    }
    

    FFmpeg/v4l2enc.c on GitHub

    You are using -input_format h264 with -vcodec copy. You must change it to -vcodec rawvideo or omit it entirely for the v4l2 output format. You might also need to set the correct pixel format.