我试图将RaspberryPi-B的网络摄像头流传输到Youtube。使用的网络摄像头是Logitech C920。如果我使用相机本身的h264流,它可以正常使用
ffmpeg -f alsa -i hw:1,0 -f v4l2 -vcodec h264 -video_size 854x480 -r 25 -i /dev/video0 -acodec aac -b:a 64000 -ar 48000 -bufsize 64k -b:v 1200k -bufsize 1024k -maxrate 1800k -vcodec copy -g 60 -r 30 -f flv
rtmp://a.rtmp.youtube.com/live2/stream_here
因此,为了与其他非h264相机(如Pi Cam或任何其他更便宜的网络摄像头)配合使用,它需要使用原始流并使用libx264转换为h264。这是使用Pi的全部要点。因此第二个命令集。
ffmpeg -f alsa -ac 2 -i hw:1,0 -f v4l2 -i /dev/video0 -framerate 25 -video_size 1280x720 -c:v libx264 -preset veryfast -maxrate 1984k -bufsize 3968k -vf "format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmp://a.rtmp.youtube.com/live2/stream_name
因此,这会产生以下问题。
ffmpeg version git-2017-03-03-68ee800 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --arch=armhf --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --extra-libs=-lasound --enable-pthreads
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
Duration: N/A, start: 1488650966.446293, bitrate: 1024 kb/s
Stream #0:0: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 2227.042654, bitrate: 159252 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 864x480, 159252 kb/s, 24 fps, 24 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[video4linux2,v4l2 @ 0x2e42310] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Illegal instruction
pi@raspberrypi:~ $
如果我添加
thread_queue_size 512
我最终得到了
pi@raspberrypi:~ $ ffmpeg -f alsa -ac 2 -i hw:1,0 -f v4l2 -thread_queue_size 512 -i /dev/video0 -framerate 25 -video_size 1280x720 -c:v libx264 -preset veryfast -maxrate 1984k -bufsize 3968k -vf "format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmp://a.rtmp.youtube.com/live2/zqg7-98wy-60b6-f2yx
ffmpeg version git-2017-03-03-68ee800 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --arch=armhf --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --extra-libs=-lasound --enable-pthreads
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
Duration: N/A, start: 1488651430.836193, bitrate: 1024 kb/s
Stream #0:0: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 2691.407641, bitrate: 159252 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 864x480, 159252 kb/s, 24 fps, 24 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
Illegal instruction
pi@raspberrypi:~ $
究竟在哪里
thread_queue_size
属?
注意: ffmpeg是使用此reference构建的 -extra-libs = -lasound&使用了--enable = pthreads
答案 0 :(得分:3)
我完全忘记了RaspberryPI对H264的硬件支持。
所以我遵循了这个tutorial,我们通过Raspberry Pi B(ARMV6)实时流式传输30%的CPU使用率。