I am trying to stream video from a Logitech c920 to YouTube live via ffmpeg. I have a setup that works in Twitch, but YouTube rejects the stream with the message:

Please use a keyframe frequency of four seconds or less. Currently, keyframes are not being sent often enough, which will cause buffering. The current keyframe frequency is 9.9 seconds.

My command looks like this:

ffmpeg \
    -ar 44100 \
    -acodec pcm_s16le \
    -f s16le \
    -ac 2 -i /dev/null \
    -f v4l2 \
    -codec:v h264 \
    -framerate 60 \
    -video_size 1920x1080 \
    -i /dev/video0 \
    -c:v copy \
    -c:a aac \
    -f flv \
    -strict -2 \

And in the logs ffmpeg gives this message:

[video4linux2,v4l2 @ 0x2965ec0] The driver changed the time per frame from 1/60 to 1/30

Does anyone know a way to force the camera, v4l2 or ffmpeg to provide keyframes at a suitable rate?



I managed to get it to work on YouTube Live with the following command:

ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f v4l2 -input_format h264 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/REMOVED

I can set the resolution by doing: v4l2-ctl --device=/dev/video0 --set-fmt-video=width=1280,height=720

The ffmpeg output looks like this: Stream #1:0: Video: h264 (Constrained Baseline), yuvj420p(pc), 320x240 [SAR 1:1 DAR 4:3], -5 kb/s, 30 fps, 30 tbr, 1000k tbn, 60 tbc

Eventually YouTube complains about keyframes, but it manages to maintain a decent stream at 1080p.

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.