I'm trying to use ffmpeg to stream output from a c920 webcam to YouTube live on a Raspberry Pi.
Unfortunately, YouTube Live returns this error when I start the stream:
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.
For what it's worth, the stream works on Twitch, but buffers pretty frequently.
I am looking for advice to make the stream acceptable to YouTube Live by adjusting the keyframe frequency.
The command I am using is this:
ffmpeg -ar 44100 -ac 2 -acodec pcm_s16le -f s16le \
-i /dev/null -ac 2 -f v4l2 -codec:v h264 -framerate 30 -video_size 1920x1080 \
-itsoffset 0.5 -i /dev/video0 -copyinkf -codec:v copy -codec:a aac -ab 128k -g 10 \
-f flv -strict -2 rtmp://a.rtmp.youtube.com/live2/STREAM_KEY
When I run the command, I get output like:
ffmpeg version N-60774-gc427b2b Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 20 2014 16:29:13 with gcc 4.7.1 (crosstool-NG 1.15.2) 20120402 (prerelease)
configuration: --enable-cross-compile --cross-prefix=/opt/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi- --arch=armel --target-os=linux --prefix=/home/jon/arm --enable-gpl --enable-libx264 --enable-nonfree --extra-cflags=-I/home/jon/arm/include --extra-ldflags=-L/home/jon/arm/lib --extra-libs=-ldl
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, s16le, from '/dev/null':
Duration: N/A, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 80888.938908, bitrate: N/A
Stream #1:0: Video: h264 (Constrained Baseline), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], -5 kb/s, 30 fps, 30 tbr, 1000k tbn, 60 tbc
Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/vktg-95zk-96fm-133h':
Metadata:
encoder : Lavf55.33.100
Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, -5 kb/s, 30 fps, 1k tbn, 1000k tbc
Stream #0:1: Audio: aac ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
Stream mapping:
Stream #1:0 -> #0:0 (copy)
Stream #0:0 -> #0:1 (pcm_s16le -> aac)
Press [q] to stop, [?] for help
[flv @ 0x2c0b3d0] Non-monotonous DTS in output stream 0:0; previous: 500, current: 333; changing to 500. This may result in incorrect timestamps in the output file.
[flv @ 0x2c0b3d0] Non-monotonous DTS in output stream 0:0; previous: 500, current: 369; changing to 500. This may result in incorrect timestamps in the output file.
[flv @ 0x2c0b3d0] Non-monotonous DTS in output stream 0:0; previous: 500, current: 401; changing to 500. This may result in incorrect timestamps in the output file.
[flv @ 0x2c0b3d0] Non-monotonous DTS in output stream 0:0; previous: 500, current: 433; changing to 500. This may result in incorrect timestamps in the output file.
[flv @ 0x2c0b3d0] Non-monotonous DTS in output stream 0:0; previous: 500, current: 469; changing to 500. This may result in incorrect timestamps in the output file.
frame= 202 fps= 18 q=-1.0 size= 760kB time=00:00:13.94 bitrate= 446.4kbits/s
This github issue suggests there's a control in v4l2-ctl to adjust the keyframe rate, but I don't see it available:
$ v4l2-ctl --list-ctrls
brightness (int) : min=0 max=255 step=1 default=-8193 value=128
contrast (int) : min=0 max=255 step=1 default=57343 value=128
saturation (int) : min=0 max=255 step=1 default=57343 value=128
white_balance_temperature_auto (bool) : default=1 value=1
gain (int) : min=0 max=255 step=1 default=57343 value=255
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=2000 max=6500 step=1 default=57343 value=2294 flags=inactive
sharpness (int) : min=0 max=255 step=1 default=57343 value=128
backlight_compensation (int) : min=0 max=1 step=1 default=57343 value=0
exposure_auto (menu) : min=0 max=3 default=0 value=3
exposure_absolute (int) : min=3 max=2047 step=1 default=250 value=666 flags=inactive
exposure_auto_priority (bool) : default=0 value=1
pan_absolute (int) : min=-36000 max=36000 step=3600 default=0 value=0
tilt_absolute (int) : min=-36000 max=36000 step=3600 default=0 value=0
focus_absolute (int) : min=0 max=250 step=5 default=8189 value=0 flags=inactive
focus_auto (bool) : default=1 value=1
zoom_absolute (int) : min=100 max=500 step=1 default=57343 value=100
brightness (int) : min=0 max=255 step=1 default=-8193 value=128
contrast (int) : min=0 max=255 step=1 default=57343 value=128
saturation (int) : min=0 max=255 step=1 default=57343 value=128
white_balance_temperature_auto (bool) : default=1 value=1
gain (int) : min=0 max=255 step=1 default=57343 value=255
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=2000 max=6500 step=1 default=57343 value=2294 flags=inactive
sharpness (int) : min=0 max=255 step=1 default=57343 value=128
backlight_compensation (int) : min=0 max=1 step=1 default=57343 value=0