我的 ffmpeg 直播不断崩溃:我该如何排除故障?

我的 ffmpeg 直播不断崩溃:我该如何排除故障?

我找不到它崩溃的原因,我所拥有的只是一个动态编码为 AAC 的 mp3 文件列表。

流文件

#!/bin/bash

ffmpeg \
-stream_loop -1 -re \
-i video.mp4 \
-safe 0 \
-f concat \
-i playlist.txt \
-c:v libx264 -preset slower -b:v 3500k -maxrate 3500k -bufsize 7000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 320k -ac 2 -ar 44100 -f flv \
rtmps://---------------/s/----key----:----key----

以下是 journalctl 收集的内容:

Feb 12 18:07:57 main bash[3236855]: [47.9K blob data]
Feb 12 18:11:38 main bash[3236855]: [48.0K blob data]
Feb 12 18:15:19 main bash[3236855]: [48.0K blob data]
Feb 12 18:18:59 main bash[3236855]: [48.0K blob data]
Feb 12 18:22:41 main bash[3236855]: [48.0K blob data]
Feb 12 18:26:21 main bash[3236855]: [48.0K blob data]
Feb 12 18:30:02 main bash[3236855]: [48.0K blob data]
Feb 12 18:33:42 main bash[3236855]: [48.0K blob data]
Feb 12 18:37:23 main bash[3236855]: [48.0K blob data]
Feb 12 18:41:03 main bash[3236855]: [48.0K blob data]
Feb 12 18:44:44 main bash[3236855]: [48.0K blob data]
Feb 12 18:48:25 main bash[3236855]: [48.0K blob data]
Feb 12 18:50:07 main bash[3236855]: [22.3K blob data]
Feb 12 18:50:07 main bash[3236855]: av_interleaved_write_frame(): Input/output error
Feb 12 18:50:09 main bash[3236855]:     Last message repeated 1 times
Feb 12 18:50:09 main bash[3236855]: [flv @ 0x5642d6c08c00] Failed to update header with correct duration.
Feb 12 18:50:09 main bash[3236855]: [flv @ 0x5642d6c08c00] Failed to update header with correct filesize.
Feb 12 18:50:09 main bash[3236855]: Error writing trailer of rtmps://------------/s/key:key: Input/output error
Feb 12 18:50:09 main bash[3236855]: frame=1215777 fps= 30 q=14.0 Lsize=18376958kB time=11:16:04.14 bitrate=3711.3kbits/s dup=0 drop=1 speed=   1x
Feb 12 18:50:09 main bash[3236855]: video:16828839kB audio:1495386kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.287779%
Feb 12 18:50:09 main bash[3236855]: [tls @ 0x5642d6bbcf40] The specified session has been invalidated for some reason.
Feb 12 18:50:09 main bash[3236855]:     Last message repeated 1 times
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] frame I:24338 Avg QP: 3.06  size: 52975
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] frame P:393923 Avg QP: 6.45  size: 24751
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] frame B:797516 Avg QP: 9.68  size:  7767
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] consecutive B-frames:  6.8% 12.2% 15.4% 65.7%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] mb I  I16..4: 47.0%  5.2% 47.9%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] mb P  I16..4:  0.8%  0.5%  4.3%  P16..4: 18.2% 13.6% 11.8%  4.1%  2.3%    skip:44.2%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] mb B  I16..4:  0.2%  0.1%  0.7%  B16..8: 21.7% 14.2%  6.4%  direct: 7.9%  skip:48.8%  L0:35.3% L1:35.8% BI:28.9%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] 8x8 transform intra:6.6% inter:16.5%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] direct mvs  spatial:99.7% temporal:0.3%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] coded y,uvDC,uvAC intra: 68.9% 62.6% 52.6% inter: 36.3% 21.5% 11.4%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] i16 v,h,dc,p: 70% 14% 13%  3%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 21% 19%  5%  5%  5%  6%  8% 10%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 23% 18%  5%  6%  6%  6%  6%  8%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] i8c dc,h,v,p: 59% 24% 12%  5%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] Weighted P-Frames: Y:2.0% UV:0.5%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] ref P L0: 69.7% 13.7%  6.8%  3.4%  2.0%  1.8%  1.3%  1.2%  0.2%  0.0%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] ref B L0: 88.7%  7.1%  2.0%  0.9%  0.7%  0.4%  0.3%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] ref B L1: 97.2%  2.8%
Feb 12 18:50:09 main bash[3236855]: [libx264 @ 0x5642d6be6300] kb/s:3398.63
Feb 12 18:50:09 main bash[3236855]: [aac @ 0x5642d6bbdd40] Qavg: 14231.606
Feb 12 18:50:09 main bash[3236855]: Conversion failed!
Feb 12 18:50:09 main systemd[1]: stream.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 18:50:09 main systemd[1]: stream.service: Failed with result 'exit-code'.

从该日志中很难判断在哪个点和哪个文件开始出现转换问题。

答案1

分离音频/视频,将音频提取为 .wav:

ffmpeg -i input_file.mp4 -vn audio_file.wav && ffmpeg -i input_file.mp4 -an -c copy video_file.mp4

用此连接脚本分别重新组装它们,只需wavmp4&更改-c:a-c:v

ls --quoting-style=shell-always -1v *.wav > tmp.txt
sed 's/^/file /' tmp.txt > list.txt && rm tmp.txt

ffmpeg -f concat -safe 0 -i list.txt -c:a copy new_pcm_audio.wav

一旦合并了 wav 音频和视频,请使用以下命令进行多路复用:

ffmpeg -i new_video_file.mp4 -i new_pcm_audio.wav -c:v copy -c:a aac -shortest -movflags +faststart new_streaming_file.mkv

这应该可以解决所有音频问题。-c:v libx264在此处使用,您可以-c copy在流式传输时使用。

相关内容