我需要使用 Logitech HD Pro Webcam C920 在 Youtube 上进行实时视频流。我的操作系统是 Fedora 20,我尝试使用的命令是:
ffmpeg -f v4l2 -i /dev/video0 -flags +global_header -ac 1 -ar 44100 -ab 16k -s 640x360 -vcodec h264 -pix_fmt yuv420p -g 25 -vb 32k -profile:v baseline -r 30 -f flv "rtmp://a.rtmp.youtube.com/live2/NAME_OF_STREAM_REMOVED"
我刚开始播放流媒体,就出现了很多丢包,Youtube 说没有收到任何数据。为了看看系统是否正常,我尝试播放一个视频文件,结果成功了,所以我不知道我遇到了什么问题。
ffmpeg 输出:
$ ffmpeg -f v4l2 -i /dev/video0 -flags +global_header -ac 1 -ar 44100 -ab 16k -s 640x360 -vcodec h264 -pix_fmt yuv420p -g 25 -vb 32k -profile:v baseline -r 30 -f flv "rtmp://a.rtmp.youtube.comremoved-privacy-reasons"
ffmpeg version 2.1.4 Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 25 2014 08:24:47 with gcc 4.8.2 (GCC) 20131212 (Red Hat 4.8.2-7)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 52. 48.101 / 52. 48.101
libavcodec 55. 39.101 / 55. 39.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libavresample 1. 1. 0 / 1. 1. 0
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 1144393.765046, bitrate: 147456 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Codec AVOption ab (set bitrate (in bits/s)) specified for output file #0 (rtmp://a.rtmp.youtube.comremoved-privacy-reasons) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[libx264 @ 0x1d276c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX XOP FMA4 FMA3 LZCNT BMI1
[libx264 @ 0x1d276c0] profile Constrained Baseline, level 3.0
[libx264 @ 0x1d276c0] 264 - core 138 r2363 c628e3b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=25 keyint_min=2 scenecut=40 intra_refresh=0 rc_lookahead=25 rc=abr mbtree=1 bitrate=32 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://a.rtmp.youtube.comremoved-privacy-reasons':
Metadata:
encoder : Lavf55.19.104
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 640x360, q=-1--1, 32 kb/s, 1k tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> libx264)
Press [q] to stop, [?] for help
[video4linux2,v4l2 @ 0x1d420c0] The v4l2 frame is 748 bytes, but 614400 bytes are expectedop=454
/dev/video0: Invalid data found when processing input
[flv @ 0x1d27120] Failed to update header with correct duration.
[flv @ 0x1d27120] Failed to update header with correct filesize.
frame= 3642 fps= 27 q=-1.0 Lsize= 617kB time=00:02:17.73 bitrate= 36.7kbits/s dup=0 drop=454
video:545kB audio:0kB subtitle:0 global headers:0kB muxing overhead 13.088289%
[libx264 @ 0x1d276c0] frame I:146 Avg QP:37.27 size: 2457
[libx264 @ 0x1d276c0] frame P:3496 Avg QP:39.47 size: 57
[libx264 @ 0x1d276c0] mb I I16..4: 84.6% 0.0% 15.4%
[libx264 @ 0x1d276c0] mb P I16..4: 1.2% 0.0% 0.0% P16..4: 1.4% 0.0% 0.0% 0.0% 0.0% skip:97.3%
[libx264 @ 0x1d276c0] final ratefactor: 39.11
[libx264 @ 0x1d276c0] coded y,uvDC,uvAC intra: 9.5% 18.8% 3.1% inter: 0.0% 0.1% 0.0%
[libx264 @ 0x1d276c0] i16 v,h,dc,p: 49% 34% 14% 4%
[libx264 @ 0x1d276c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 17% 21% 6% 4% 4% 4% 4% 3%
[libx264 @ 0x1d276c0] i8c dc,h,v,p: 94% 4% 3% 0%
[libx264 @ 0x1d276c0] ref P L0: 39.1% 49.9% 11.0%
[libx264 @ 0x1d276c0] kb/s:32.40
[video4linux2,v4l2 @ 0x1d420c0] Some buffers are still owned by the caller on close.
答案1
问题是我设置了音频流的选项,但实际上没有在任何地方设置这个命令
ffmpeg -f v4l2 -i /dev/video0 -f alsa -ac 1 -i hw:1 -flags +global_header -ar 44100 -ab 16k -s 640x360 -vcodec h264 -pix_fmt yuv420p -g 25 -vb 32k -profile:v baseline -r 30 -f flv "rtmp://a.rtmp.youtube.com/live2/REMOVED"