我尝试使用 FFmpeg 同时录制音频和视频。但是,出现了几个问题。这是我的代码:
ffmpeg -f alsa -ar 24000 -i plughw:1 -acodec aac -strict experimental -f video4linux2 -y -r 4 -i /dev/video0 -vf "drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:expansion=strftime:text='%Y-%m-%d %H\\:%M\\:%S': fontcolor=white:box=1:[email protected]:x=w-text_w:y=h-line_h" -vframes 20 -vcodec mpeg4 out.mp4
我复制的结果如下:
ffmpeg version N-61372-g1306359 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 19 2014 22:59:34 with gcc 4.6 (Debian 4.6.3-14+rpi1)
configuration: --enable-cross-compile --cross-prefix= --arch=armel --target-os=linux --prefix=/usr --enable-gpl --enable-libfreetype --enable-nonfree --enable-libaacplus --extra-cflags=-I/usr/include --extra-ldflags=-L/usr/lib --extra-libs=-ldl
libavutil 52. 66.101 / 52. 66.101
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 34.101 / 55. 34.101
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'plughw:1':
Duration: N/A, start: 1395351824.134003, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 24000 Hz, stereo, s16, 768 kb/s
[video4linux2,v4l2 @ 0x21c1840] The driver changed the time per frame from 1/4 to 1/5
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 15130.155369, bitrate: 24576 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 24576 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
[Parsed_drawtext_0 @ 0x21c14f0] expansion=strftime is deprecated.
libaacplus: bad aac setting: br:128000, AACch:2, AACsr:24000
[libaacplus @ 0x21c6370] libaacplus doesn't support this output format!
Output #0, mp4, to 'out.mp4':
Stream #0:0: Video: mpeg4, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 4 tbc
Stream #0:1: Audio: aac, 24000 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> mpeg4)
Stream #0:0 -> #0:1 (pcm_s16le -> libaacplus)
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
它显示了libaacplus doesn't support this output format!
。当我将输出格式更改为 mpg 时,它工作得很好。但是,最终输出文件中没有声音。我不确定哪个部分出了问题。有人能帮我吗?
有libfaac
支持吗mp4
?
答案1
期权放置事宜:
ffmpeg [global options] [input options] -i input [output options] output
您被告知ffmpeg
使用-acodec aac -strict experimental
作为 v4l2 设备的输入选项,但该选项被忽略。由于ffmpeg
将优先考虑其他受支持的编码器,而不是原生 AAC 编码器,因此它选择了 libaacplus,而这与您提供的选项不兼容。这是一个 AAC-HE 编码器,但我假设您想要一个普通的 AAC-LC 格式。请参阅FFmpeg 和 AAC 编码指南更多细节。
你必须移动-acodec aac -strict experimental
成为输出选项:
ffmpeg -f alsa -ar 24000 -i plughw:1 -f v4l2 -r 4 -i /dev/video0 -vf "drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:expansion=strftime:text='%Y-%m-%d %H\\:%M\\:%S': fontcolor=white:box=1:[email protected]:x=w-text_w:y=h-line_h" -vframes 20 -vcodec mpeg4 -acodec aac -strict experimental out.mp4