一开始,我不得不承认我是FFmpeg的新手,还有raspbian。不幸的是,我需要尽快解决这个问题。
我尝试通过分别使用PIcamera和USB网络摄像头在我的Raspberry PI上录制视频。当我使用命令时:
ffmpeg -t 10 -f video4linux2 -r 25 -i /dev/video0 out.h264
但是,有些事情是非常错误的,因为该视频文件中没有保存任何内容。我复制了日志。
[video4linux2,v4l2 @ 0x267ad80] The driver changed the time per frame from 1/25 to 1/30
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 37562.908020, bitrate: 147456 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
File 'out.h264' already exists. Overwrite ? [y/N] y
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x267ca60] using cpu capabilities: ARMv6
[libx264 @ 0x267ca60] profile High 4:2:2, level 3.0, 4:2:2 8-bit
Output #0, h264, to 'out.h264':
Metadata:
encoder : Lavf55.34.101
Stream #0:0: Video: h264 (libx264), yuv422p, 640x480, q=-1--1, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> libx264)
Press [q] to stop, [?] for help
DTS 140730117085, next:18648459 st:0 invalid dropping00.00 bitrate=N/A
PTS 140730117085, next:18648459 invalid dropping st:0
DTS 140740452429, next:6538221 st:0 invalid dropping:00.00 bitrate=N/A
PTS 140740452429, next:6538221 invalid dropping st:0
frame= 44 fps=1.1 q=28.0 size= 18kB time=00:00:00.04 bitrate=3712.6kbits/
frame= 45 fps=0.8 q=28.0 size= 22kB time=00:00:00.08 bitrate=2262.8kbits/
frame= 46 fps=0.7 q=28.0 size= 27kB time=00:00:00.12 bitrate=1813.4kbits/
frame= 47 fps=0.6 q=28.0 size= 30kB time=00:00:00.16 bitrate=1559.2kbits/
frame= 48 fps=0.5 q=28.0 size= 34kB time=00:00:00.20 bitrate=1397.7kbits/
frame= 49 fps=0.5 q=28.0 size= 39kB time=00:00:00.24 bitrate=1324.3kbits/
frame= 50 fps=0.4 q=28.0 size= 42kB time=00:00:00.28 bitrate=1241.7kbits/
正如您所看到的,每帧的大小只有几个kb而且fps非常低。因此,每个帧都是使用很长时间(在这种情况下为4秒)。然后我使用命令测试我的USB网络摄像头:
ffplay -f video4linux2 /dev/video0
屏幕上显示的视频流非常不自然。看起来每帧之间有这么长的延迟。所以视频很难移动。我复制的日志:
pi@raspberrypi ~ $ ffplay -f video4linux2 /dev/video0
avplay version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2003-2013 the Libav developers
built on Mar 31 2013 13:58:10 with gcc 4.6.3
[video4linux2 @ 0x1ad83c0] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video0':
Duration: N/A, start: 36107.154598, bitrate: 147456 kb/s
Stream #0.0: Video: rawvideo, yuyv422, 640x480, 147456 kb/s, 30 tbr, 1000k tbn, 30 tbc
[avsink @ 0x1ad9960] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x1ad9d20] w:640 h:480 fmt:yuyv422 -> w:640 h:480 fmt:yuv420p flags:0x4
36163.33 A-V: 0.000 s:0.0 aq= 0KB vq= 3000KB sq= 0B f=8/8
最后一个问题是,当我尝试添加一些声音时,视频文件中没有添加声音。我使用了命令:
avconv -i /home/pi/Desktop/test.mp4 -i /home/pi/Desktop/test.mp3 -map 0:0 -vcodec copy -map 1:0 -acodec copy output.h264
我已单独检查过视频和音频都可以播放。但是合并的文件只有视频但没有音频。日志显示如下,似乎该过程成功。
pi@raspberrypi ~ $ avconv -i /home/pi/Desktop/test.mp4 -i /home/pi/Desktop/test.mp3 -map 0:0 -vcodec copy -map 1:0 -acodec copy output.h264
avconv version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
built on Mar 31 2013 13:58:10 with gcc 4.6.3
[h264 @ 0x1aa6680] max_analyze_duration reached
[h264 @ 0x1aa6680] Estimating duration from bitrate, this may be inaccurate
Input #0, h264, from '/home/pi/Desktop/test.mp4':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: h264 (High), yuv420p, 640x480, 25 fps, 25 tbr, 1200k tbn, 2400k tbc
[mp3 @ 0x1aaa120] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from '/home/pi/Desktop/test.mp3':
Metadata:
title : We Are Legend (Original Mix)
artist : Dimitri Vegas & Like Mike & Steve Aoki
album : SPINNIN RECORDS
encoded_by : iTunes 11.1.5
TBP : 128
genre : Progressive House
date : 2013
Duration: 00:00:11.14, start: 0.000000, bitrate: 191 kb/s
Stream #1.0: Audio: mp3, 48000 Hz, stereo, s16, 192 kb/s
File 'output.h264' already exists. Overwrite ? [y/N] y
Output #0, h264, to 'output.h264':
Metadata:
encoder : Lavf53.21.1
Stream #0.0: Video: libx264, yuv420p, 640x480, q=2-31, 90k tbn, 1200k tbc
Stream #0.1: Audio: libmp3lame, 48000 Hz, stereo, 192 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press ctrl-c to stop encoding
frame= 144 fps= 0 q=-1.0 Lsize= 1684kB time=5.06 bitrate=2724.7kbits/s
video:1566kB audio:119kB global headers:0kB muxing overhead 0.000000%
请帮助我有人帮助我。抱歉我的英语不好。
BTW:当我最终拍摄了200帧时,结果发现它们都是绿色的。