At the beginning, I have to admit that I am a newbie in FFmpeg and also raspbian. Unfortunately, I need to solve this problem as soon as possible.
I tried to record videos on my Raspberry PI by using PIcamera and USB webcam separately. When I used command:
ffmpeg -t 10 -f video4linux2 -r 25 -i /dev/video0 out.h264
However, something was very wrong because there was nothing saved in that video file. I copy the log.
[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/
As you can see, the size of each frame was only few kb and fps was so low. Thus each frame was taken by using a long time(4s in this case). Then I test my USB webcam by using command:
ffplay -f video4linux2 /dev/video0
The video stream which displayed on the screen was so unnatural. It looked like there was such a long delay between each frame. So the video was hardly moved. The log I have copied:
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
The final problem is that no sound was added in video file when I tried to add some in. I used the command:
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
I have checked separately that the video and audio were both able to play. However the merged file only had video but no audio. The log is shown below, it seems that the process was succeed.
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%
Could somebody helps me, please. And sorry for my bad english.