我正在尝试将音频和视频结合起来,以便从 Raspberry Pi 进行流式传输。无论我是流式传输输出还是将其写入文件,音频都会领先视频几秒钟。
命令行:
raspivid -o - -t 0 -n -w 1280 -h 720 -fps 25 | ffmpeg -report -probesize 32000 -thread_queue_size 1024 -y -f h264 -r 25 -framerate 25 -i - -thread_queue_size 512 -f alsa -ac 1 -channel_layout mono -i hw:1 -vcodec copy -acodec mp3 -f mpegts udp://44.0.0.95:1234
ffmpeg 报告/日志:
ffmpeg started on 2015-06-15 at 19:14:26
Report written to "ffmpeg-20150615-191426.log"
Command line:
ffmpeg -report -probesize 32000 -thread_queue_size 1024 -y -f h264 -r 25 -framerate 25 -i - -thread_queue_size 512 -f alsa -ac 1 -channel_layout mono -i hw:1 -vcodec copy -acodec mp3 -f mpegts udp://44.0.0.95:1234
ffmpeg version N-72834-gfd004e1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.6 (Debian 4.6.3-14+rpi1)
configuration: --enable-libmp3lame
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
Splitting the commandline.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-probesize' ... matched as AVOption 'probesize' with argument '32000'.
Reading option '-thread_queue_size' ... matched as option 'thread_queue_size' (set the maximum number of queued packets from the demuxer) with argument '1024'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'h264'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '25'.
Reading option '-framerate' ... matched as AVOption 'framerate' with argument '25'.
Reading option '-i' ... matched as input file with argument '-'.
Reading option '-thread_queue_size' ... matched as option 'thread_queue_size' (set the maximum number of queued packets from the demuxer) with argument '512'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'alsa'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '1'.
Reading option '-channel_layout' ... matched as option 'channel_layout' (set channel layout) with argument 'mono'.
Reading option '-i' ... matched as input file with argument 'hw:1'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'mp3'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mpegts'.
Reading option 'udp://44.0.0.95:1234' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file -.
Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 1024.
Applying option f (force format) with argument h264.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 25.
Successfully parsed a group of options.
Opening an input file: -.
[h264 @ 0x12a83c0] Before avformat_find_stream_info() pos: 0 bytes read:4096 seeks:0
[h264 @ 0x12a83c0] Probe buffer size limit of 32000 bytes reached
[h264 @ 0x12a83c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
[h264 @ 0x12a83c0] decoding for stream 0 failed
[h264 @ 0x12a83c0] After avformat_find_stream_info() pos: 34816 bytes read:53248 seeks:0 frames:3
Input #0, h264, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0:0, 3, 1/1200000: Video: h264 (High), yuv420p, 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Successfully opened the file.
Parsing a group of options: input file hw:1.
Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 512.
Applying option f (force format) with argument alsa.
Applying option ac (set number of audio channels) with argument 1.
Applying option channel_layout (set channel layout) with argument mono.
Successfully parsed a group of options.
Opening an input file: hw:1.
[alsa @ 0x12cee80] All info found
Input #1, alsa, from 'hw:1':
Duration: N/A, start: 1434392072.070301, bitrate: 768 kb/s
Stream #1:0, 1, 1/1000000: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Successfully opened the file.
Parsing a group of options: output file udp://44.0.0.95:1234.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument mp3.
Applying option f (force format) with argument mpegts.
Successfully parsed a group of options.
Opening an output file: udp://44.0.0.95:1234.
Matched encoder 'libmp3lame' for codec 'mp3'.
Successfully opened the file.
detected 4 logical cores
[graph 0 input from stream 1:0 @ 0x12a82a0] Setting 'time_base' to value '1/48000'
[graph 0 input from stream 1:0 @ 0x12a82a0] Setting 'sample_rate' to value '48000'
[graph 0 input from stream 1:0 @ 0x12a82a0] Setting 'sample_fmt' to value 's16'
[graph 0 input from stream 1:0 @ 0x12a82a0] Setting 'channel_layout' to value '0x4'
[graph 0 input from stream 1:0 @ 0x12a82a0] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x4
[audio format for output stream 0:1 @ 0x12a0390] Setting 'sample_fmts' to value 's32p|fltp|s16p'
[audio format for output stream 0:1 @ 0x12a0390] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000'
[audio format for output stream 0:1 @ 0x12a0390] Setting 'channel_layouts' to value '0x4|0x3'
[audio format for output stream 0:1 @ 0x12a0390] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 0:1'
[AVFilterGraph @ 0x1320b60] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto-inserted resampler 0 @ 0x1321c60] ch:1 chl:mono fmt:s16 r:48000Hz -> ch:1 chl:mono fmt:s16p r:48000Hz
[mpegts @ 0x12bdbf0] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://44.0.0.95:1234':
Metadata:
encoder : Lavf56.36.100
Stream #0:0, 0, 1/90000: Video: h264, yuv420p, 1280x720, q=2-31, 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1, 0, 1/90000: Audio: mp3 (libmp3lame), 48000 Hz, mono, s16p
Metadata:
encoder : Lavc56.41.100 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
frame= 11 fps=0.0 q=-1.0 size= 276kB time=00:00:00.44 bitrate=5130.7kbits/s
frame= 24 fps= 24 q=-1.0 size= 494kB time=00:00:00.96 bitrate=4212.8kbits/s
frame= 36 fps= 24 q=-1.0 size= 681kB time=00:00:01.44 bitrate=3872.8kbits/s
frame= 49 fps= 24 q=-1.0 size= 877kB time=00:00:01.96 bitrate=3664.8kbits/s
frame= 62 fps= 24 q=-1.0 size= 1119kB time=00:00:02.48 bitrate=3695.1kbits/s
frame= 74 fps= 24 q=-1.0 size= 1309kB time=00:00:02.96 bitrate=3622.3kbits/s
frame= 87 fps= 25 q=-1.0 size= 1503kB time=00:00:03.48 bitrate=3539.2kbits/s
frame= 99 fps= 24 q=-1.0 size= 1677kB time=00:00:03.96 bitrate=3470.2kbits/s
frame= 112 fps= 25 q=-1.0 size= 1873kB time=00:00:04.48 bitrate=3424.6kbits/s
frame= 125 fps= 25 q=-1.0 size= 2121kB time=00:00:05.00 bitrate=3475.1kbits/s
frame= 137 fps= 25 q=-1.0 size= 2300kB time=00:00:05.48 bitrate=3437.8kbits/s
frame= 150 fps= 25 q=-1.0 size= 2486kB time=00:00:06.00 bitrate=3394.5kbits/s
frame= 162 fps= 25 q=-1.0 size= 2657kB time=00:00:06.48 bitrate=3358.5kbits/s
frame= 175 fps= 25 q=-1.0 size= 2852kB time=00:00:07.00 bitrate=3337.4kbits/s
frame= 188 fps= 25 q=-1.0 size= 3124kB time=00:00:07.52 bitrate=3403.6kbits/s
frame= 200 fps= 25 q=-1.0 size= 3416kB time=00:00:08.00 bitrate=3497.7kbits/s
frame= 213 fps= 25 q=-1.0 size= 3679kB time=00:00:08.52 bitrate=3537.4kbits/s
frame= 226 fps= 25 q=-1.0 size= 3976kB time=00:00:09.04 bitrate=3603.4kbits/s
frame= 239 fps= 25 q=-1.0 size= 4228kB time=00:00:09.56 bitrate=3622.7kbits/s
frame= 251 fps= 25 q=-1.0 size= 4502kB time=00:00:10.04 bitrate=3673.7kbits/s
frame= 263 fps= 25 q=-1.0 size= 4761kB time=00:00:10.52 bitrate=3707.7kbits/s
frame= 276 fps= 25 q=-1.0 size= 5135kB time=00:00:11.04 bitrate=3810.1kbits/s
frame= 289 fps= 25 q=-1.0 size= 5458kB time=00:00:11.56 bitrate=3867.7kbits/s
frame= 302 fps= 25 q=-1.0 size= 5831kB time=00:00:12.08 bitrate=3954.1kbits/s
frame= 314 fps= 25 q=-1.0 size= 6107kB time=00:00:12.56 bitrate=3982.8kbits/s
frame= 327 fps= 25 q=-1.0 size= 6364kB time=00:00:13.08 bitrate=3985.8kbits/s
frame= 339 fps= 25 q=-1.0 size= 6674kB time=00:00:13.56 bitrate=4032.2kbits/s
frame= 352 fps= 25 q=-1.0 size= 7217kB time=00:00:14.08 bitrate=4198.9kbits/s
frame= 365 fps= 25 q=-1.0 size= 7714kB time=00:00:14.60 bitrate=4328.5kbits/s
frame= 377 fps= 25 q=-1.0 size= 7969kB time=00:00:15.08 bitrate=4329.3kbits/s
frame= 390 fps= 25 q=-1.0 size= 8194kB time=00:00:15.60 bitrate=4302.8kbits/s
frame= 402 fps= 25 q=-1.0 size= 8397kB time=00:00:16.08 bitrate=4277.8kbits/s
frame= 414 fps= 25 q=-1.0 size= 8597kB time=00:00:16.56 bitrate=4252.9kbits/s
frame= 427 fps= 25 q=-1.0 size= 8874kB time=00:00:17.08 bitrate=4256.3kbits/s
frame= 440 fps= 25 q=-1.0 size= 9092kB time=00:00:17.60 bitrate=4231.8kbits/s
frame= 453 fps= 25 q=-1.0 size= 9321kB time=00:00:18.12 bitrate=4213.8kbits/s
frame= 465 fps= 25 q=-1.0 size= 9512kB time=00:00:18.60 bitrate=4189.3kbits/s
frame= 478 fps= 25 q=-1.0 size= 9721kB time=00:00:19.12 bitrate=4164.9kbits/s
frame= 490 fps= 25 q=-1.0 size= 9983kB time=00:00:19.60 bitrate=4172.7kbits/s
frame= 503 fps= 25 q=-1.0 size= 10173kB time=00:00:20.12 bitrate=4142.1kbits/s
frame= 515 fps= 25 q=-1.0 size= 10366kB time=00:00:20.60 bitrate=4122.1kbits/s
frame= 528 fps= 25 q=-1.0 size= 10571kB time=00:00:21.12 bitrate=4100.4kbits/s
frame= 540 fps= 25 q=-1.0 size= 10780kB time=00:00:21.60 bitrate=4088.2kbits/s
frame= 553 fps= 25 q=-1.0 size= 11118kB time=00:00:22.12 bitrate=4117.6kbits/s
frame= 566 fps= 25 q=-1.0 size= 11360kB time=00:00:22.64 bitrate=4110.4kbits/s
frame= 578 fps= 25 q=-1.0 size= 11584kB time=00:00:23.12 bitrate=4104.6kbits/s
frame= 591 fps= 25 q=-1.0 size= 11852kB time=00:00:23.64 bitrate=4107.2kbits/s
frame= 603 fps= 25 q=-1.0 size= 12123kB time=00:00:24.12 bitrate=4117.4kbits/s
frame= 617 fps= 25 q=-1.0 size= 12346kB time=00:00:24.68 bitrate=4098.2kbits/s
frame= 629 fps= 25 q=-1.0 size= 12543kB time=00:00:25.16 bitrate=4083.8kbits/s
frame= 641 fps= 25 q=-1.0 size= 12781kB time=00:00:25.64 bitrate=4083.4kbits/s
frame= 654 fps= 25 q=-1.0 size= 12996kB time=00:00:26.16 bitrate=4069.8kbits/s
frame= 667 fps= 25 q=-1.0 size= 13313kB time=00:00:26.68 bitrate=4087.9kbits/s
frame= 679 fps= 25 q=-1.0 size= 13539kB time=00:00:27.16 bitrate=4083.7kbits/s
frame= 692 fps= 25 q=-1.0 size= 13774kB time=00:00:27.68 bitrate=4076.6kbits/s
frame= 704 fps= 25 q=-1.0 size= 14011kB time=00:00:28.16 bitrate=4075.9kbits/s
frame= 717 fps= 25 q=-1.0 size= 14210kB time=00:00:28.68 bitrate=4059.0kbits/s
frame= 729 fps= 25 q=-1.0 size= 14462kB time=00:00:29.16 bitrate=4063.0kbits/s
frame= 742 fps= 25 q=-1.0 size= 14676kB time=00:00:29.68 bitrate=4050.9kbits/s
frame= 755 fps= 25 q=-1.0 size= 14892kB time=00:00:30.20 bitrate=4039.5kbits/s
frame= 767 fps= 25 q=-1.0 size= 15090kB time=00:00:30.68 bitrate=4029.1kbits/s
frame= 780 fps= 25 q=-1.0 size= 15326kB time=00:00:31.20 bitrate=4024.2kbits/s
frame= 792 fps= 25 q=-1.0 size= 15793kB time=00:00:31.68 bitrate=4083.9kbits/s
frame= 805 fps= 25 q=-1.0 size= 16167kB time=00:00:32.20 bitrate=4112.9kbits/s
frame= 818 fps= 25 q=-1.0 size= 16652kB time=00:00:32.72 bitrate=4169.0kbits/s
frame= 830 fps= 25 q=-1.0 size= 16917kB time=00:00:33.20 bitrate=4174.3kbits/s
frame= 843 fps= 25 q=-1.0 size= 17224kB time=00:00:33.72 bitrate=4184.4kbits/s
frame= 855 fps= 25 q=-1.0 size= 17441kB time=00:00:34.20 bitrate=4177.6kbits/s
frame= 868 fps= 25 q=-1.0 size= 17678kB time=00:00:34.72 bitrate=4171.0kbits/s
frame= 881 fps= 25 q=-1.0 size= 17908kB time=00:00:35.24 bitrate=4163.1kbits/s
frame= 893 fps= 25 q=-1.0 size= 18119kB time=00:00:35.72 bitrate=4155.5kbits/s
frame= 906 fps= 25 q=-1.0 size= 18401kB time=00:00:36.24 bitrate=4159.6kbits/s
frame= 918 fps= 25 q=-1.0 size= 18617kB time=00:00:36.72 bitrate=4153.3kbits/s
frame= 931 fps= 25 q=-1.0 size= 18854kB time=00:00:37.24 bitrate=4147.5kbits/s
frame= 944 fps= 25 q=-1.0 size= 19084kB time=00:00:37.76 bitrate=4140.3kbits/s
frame= 956 fps= 25 q=-1.0 size= 19293kB time=00:00:38.24 bitrate=4133.0kbits/s
frame= 969 fps= 25 q=-1.0 size= 19612kB time=00:00:38.76 bitrate=4145.0kbits/s
frame= 981 fps= 25 q=-1.0 size= 19807kB time=00:00:39.24 bitrate=4135.0kbits/s
frame= 994 fps= 25 q=-1.0 size= 20021kB time=00:00:39.76 bitrate=4125.1kbits/s
frame= 1007 fps= 25 q=-1.0 size= 20233kB time=00:00:40.28 bitrate=4114.9kbits/s
frame= 1020 fps= 25 q=-1.0 size= 20453kB time=00:00:40.80 bitrate=4106.5kbits/s
frame= 1032 fps= 25 q=-1.0 size= 20704kB time=00:00:41.28 bitrate=4108.7kbits/s
frame= 1045 fps= 25 q=-1.0 size= 20915kB time=00:00:41.80 bitrate=4099.0kbits/s
frame= 1058 fps= 25 q=-1.0 size= 21168kB time=00:00:42.32 bitrate=4097.6kbits/s
frame= 1070 fps= 25 q=-1.0 size= 21518kB time=00:00:42.80 bitrate=4118.6kbits/s
frame= 1082 fps= 25 q=-1.0 size= 22021kB time=00:00:43.28 bitrate=4168.1kbits/s
frame= 1095 fps= 25 q=-1.0 size= 22460kB time=00:00:43.80 bitrate=4200.8kbits/s
frame= 1107 fps= 25 q=-1.0 size= 22899kB time=00:00:44.28 bitrate=4236.4kbits/s
frame= 1120 fps= 25 q=-1.0 size= 23297kB time=00:00:44.80 bitrate=4260.1kbits/s
frame= 1133 fps= 25 q=-1.0 size= 23649kB time=00:00:45.32 bitrate=4274.9kbits/s
frame= 1145 fps= 25 q=-1.0 size= 23979kB time=00:00:45.80 bitrate=4289.0kbits/s
frame= 1158 fps= 25 q=-1.0 size= 24220kB time=00:00:46.32 bitrate=4283.5kbits/s
frame= 1170 fps= 25 q=-1.0 size= 24429kB time=00:00:46.80 bitrate=4276.1kbits/s
frame= 1182 fps= 25 q=-1.0 size= 24666kB time=00:00:47.28 bitrate=4273.6kbits/s
frame= 1196 fps= 25 q=-1.0 size= 24886kB time=00:00:47.84 bitrate=4261.5kbits/s
frame= 1208 fps= 25 q=-1.0 size= 25133kB time=00:00:48.32 bitrate=4261.0kbits/s
frame= 1221 fps= 25 q=-1.0 size= 25332kB time=00:00:48.84 bitrate=4249.0kbits/s
frame= 1233 fps= 25 q=-1.0 size= 25525kB time=00:00:49.32 bitrate=4239.6kbits/s
frame= 1246 fps= 25 q=-1.0 size= 25733kB time=00:00:49.84 bitrate=4229.7kbits/s
frame= 1259 fps= 25 q=-1.0 size= 25941kB time=00:00:50.36 bitrate=4219.8kbits/s
frame= 1271 fps= 25 q=-1.0 size= 26186kB time=00:00:50.84 bitrate=4219.5kbits/s
frame= 1284 fps= 25 q=-1.0 size= 26387kB time=00:00:51.36 bitrate=4208.8kbits/s
frame= 1296 fps= 25 q=-1.0 size= 26574kB time=00:00:51.84 bitrate=4199.3kbits/s
frame= 1309 fps= 25 q=-1.0 size= 26780kB time=00:00:52.36 bitrate=4189.9kbits/s
frame= 1322 fps= 25 q=-1.0 size= 27029kB time=00:00:52.88 bitrate=4187.3kbits/s
frame= 1334 fps= 25 q=-1.0 size= 27223kB time=00:00:53.36 bitrate=4179.4kbits/s
frame= 1347 fps= 25 q=-1.0 size= 27424kB time=00:00:53.88 bitrate=4169.7kbits/s
frame= 1359 fps= 25 q=-1.0 size= 27610kB time=00:00:54.36 bitrate=4160.7kbits/s
frame= 1372 fps= 25 q=-1.0 size= 27813kB time=00:00:54.88 bitrate=4151.6kbits/s
frame= 1385 fps= 25 q=-1.0 size= 28062kB time=00:00:55.40 bitrate=4149.6kbits/s
frame= 1397 fps= 25 q=-1.0 size= 28246kB time=00:00:55.88 bitrate=4140.8kbits/s
frame= 1410 fps= 25 q=-1.0 size= 28449kB time=00:00:56.40 bitrate=4132.1kbits/s
frame= 1422 fps= 25 q=-1.0 size= 28631kB time=00:00:56.88 bitrate=4123.5kbits/s
frame= 1435 fps= 25 q=-1.0 size= 28837kB time=00:00:57.40 bitrate=4115.5kbits/s
frame= 1448 fps= 25 q=-1.0 size= 29086kB time=00:00:57.92 bitrate=4113.8kbits/s
frame= 1460 fps= 25 q=-1.0 size= 29269kB time=00:00:58.40 bitrate=4105.7kbits/s
frame= 1473 fps= 25 q=-1.0 size= 29465kB time=00:00:58.92 bitrate=4096.7kbits/s
frame= 1485 fps= 25 q=-1.0 size= 29646kB time=00:00:59.40 bitrate=4088.5kbits/s
frame= 1498 fps= 25 q=-1.0 size= 29845kB time=00:00:59.92 bitrate=4080.3kbits/s
frame= 1511 fps= 25 q=-1.0 size= 30097kB time=00:01:00.44 bitrate=4079.3kbits/s
frame= 1523 fps= 25 q=-1.0 size= 30281kB time=00:01:00.92 bitrate=4072.0kbits/s
frame= 1536 fps= 25 q=-1.0 size= 30474kB time=00:01:01.44 bitrate=4063.2kbits/s
frame= 1548 fps= 25 q=-1.0 size= 30653kB time=00:01:01.92 bitrate=4055.4kbits/s
frame= 1561 fps= 25 q=-1.0 size= 30853kB time=00:01:02.44 bitrate=4047.8kbits/s
frame= 1574 fps= 25 q=-1.0 size= 31100kB time=00:01:02.96 bitrate=4046.5kbits/s
frame= 1586 fps= 25 q=-1.0 size= 31291kB time=00:01:03.44 bitrate=4040.6kbits/s
frame= 1599 fps= 25 q=-1.0 size= 31499kB time=00:01:03.96 bitrate=4034.3kbits/s
frame= 1611 fps= 25 q=-1.0 size= 31686kB time=00:01:04.44 bitrate=4028.1kbits/s
frame= 1624 fps= 25 q=-1.0 size= 31940kB time=00:01:04.96 bitrate=4027.9kbits/s
frame= 1637 fps= 25 q=-1.0 size= 32135kB time=00:01:05.48 bitrate=4020.4kbits/s
frame= 1649 fps= 25 q=-1.0 size= 32320kB time=00:01:05.96 bitrate=4014.0kbits/s
frame= 1661 fps= 25 q=-1.0 size= 32496kB time=00:01:06.44 bitrate=4006.7kbits/s
frame= 1674 fps= 25 q=-1.0 size= 32685kB time=00:01:06.96 bitrate=3998.7kbits/s
frame= 1687 fps= 25 q=-1.0 size= 32932kB time=00:01:07.48 bitrate=3997.9kbits/s
frame= 1699 fps= 25 q=-1.0 size= 33175kB time=00:01:07.96 bitrate=3999.0kbits/s
frame= 1712 fps= 25 q=-1.0 size= 33507kB time=00:01:08.48 bitrate=4008.3kbits/s
frame= 1724 fps= 25 q=-1.0 size= 33797kB time=00:01:08.96 bitrate=4014.9kbits/s
frame= 1737 fps= 25 q=-1.0 size= 34091kB time=00:01:09.48 bitrate=4019.5kbits/s
frame= 1750 fps= 25 q=-1.0 size= 34451kB time=00:01:10.00 bitrate=4031.8kbits/s
frame= 1763 fps= 25 q=-1.0 size= 34750kB time=00:01:10.52 bitrate=4036.7kbits/s
frame= 1775 fps= 25 q=-1.0 size= 35010kB time=00:01:11.00 bitrate=4039.5kbits/s
[libmp3lame @ 0x1320770] Trying to remove 47 more samples than there are in the queue
frame= 1779 fps= 25 q=-1.0 Lsize= 35116kB time=00:01:11.28 bitrate=4035.7kbits/s
video:31803kB audio:557kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.515517%
Input file #0 (pipe:):
Input stream #0:0 (video): 1779 packets read (32566370 bytes);
Total: 1779 packets (32566370 bytes) demuxed
Input file #1 (hw:1):
Input stream #1:0 (audio): 57720 packets read (6842992 bytes); 57720 frames decoded (3421496 samples);
Total: 57720 packets (6842992 bytes) demuxed
Output file #0 (udp://44.0.0.95:1234):
Output stream #0:0 (video): 1779 packets muxed (32566370 bytes);
Output stream #0:1 (audio): 2970 frames encoded (3421440 samples); 2971 packets muxed (570432 bytes);
Total: 4750 packets (33136802 bytes) muxed
57720 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x1321210] Statistics: 0 seeks, 25491 writeouts
[AVIOContext @ 0x12a7e40] Statistics: 35211617 bytes read, 0 seeks
Received signal 2: terminating.
答案1
我的建议是:如果您能够使用raspvid
预览窗口测试相机的输出同步,并且发现相机落后,那么我认为相机的 h264 编码器是罪魁祸首。但是,如果它同步,那么 FFmpeg 正在对管道输入进行处理。
如果问题出在相机的 h264 编码器上并且视频滞后于音频的持续时间是一致的(即,您每次都会观察到 2.5 秒的滞后),您可以-itsoffset
向音频输入添加一个参数以将其延迟该持续时间。例如:
raspivid -o - -t 0 -n -w 1280 -h 720 -fps 25 | \
ffmpeg -report -y \
-f h264 -r 25 -i - \
-itsoffset 2.5 -f alsa -ac 1 -i hw:1 \
-vcodec copy -acodec libmp3lame -ac 1 -ar 44100 -b:a 128k \
-f mpegts udp://44.0.0.95:1234
如果相机的预览输出没有延迟,那么我建议安装相机的 V4L2 驱动程序,以便您的 FFmpeg 命令可以直接从相机中提取帧。
ffmpeg -report -y \
-f v4l2 -input_format h264 -r 25 -video_size 1280x720 -i /dev/video0 \
-f alsa -ac 1 -i hw:1 \
-vcodec copy -acodec libmp3lame -ac 1 -ar 44100 -b:a 128k \
-f mpegts udp://44.0.0.95:1234
然而,从我在网上收集到的信息来看,人们对这款相机的 V4L2 驱动程序的性能有所抱怨,所以你最终可能会坚持使用你所熟悉的驱动程序,-itsoffset
不管怎样都要使用音频输入。
命令说明:由于您指定了输入格式和帧速率,因此我已从您的命令中删除了该probesize
选项。此外,您不应同时指定两者-r 25
(这会“强制”将帧速率设置为指定值)和 -framerate 25
(将尝试使用“原生”输入帧速率)。我保留了-r 25
它,因为我发现它更适合实时视频输入。MP3 编码器设置更具体,因此 FFmpeg 不必“猜测”它们。params-thread_queue_size
被修剪为行长,因此如果绝对必要,您可以将它们重新添加。
答案2
尝试在 rtp://127.0.0.1:1235 上重新流式传输音频并将视频合并到 mp4 容器中。