问题
第一个视频播放完毕后,直播就停止了。我还能做什么来确保整个播放列表都能播放。直播被转发到 NGINX RTMP 服务器
播放列表文本文件
ffconcat version 1.0
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Old-Fashioned-Grainy-10-second-Movie-Film-Countdown-Timer-HD.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Johnny-Jordaan-en-Willy-Alberti-Oh-zwarte-zigeuner-Op-Volle-Toeren.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Origineel-liedje-uit-Ja-Zuster-Nee-Zuster-Elektrieke-Deken.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Benny-Neyman-Ga-Niet-Weg-Van-Mij-Officiele-video.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Dans-nog-een-keer-met-mij-Henny-Thijssen.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Vader-Abraham-Bedankt-lieve-ouders.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Wim-Sonneveld-Catootje.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Conny-Vandenbos-Een-roosje-mn-roosje-•-TopPop.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Nicole-Ein-Bisschen-Frieden-1982.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Liesbeth-List-Ramses-Shaffy-Pastorale-_-Cor-Co.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Astrid-Nijgh-Ik-doe-wat-ik-doe.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Old-Fashioned-Grainy-10-second-Movie-Film-Countdown-Timer-HD.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Don-Mercedes-Rocky-1976-•-TopPop-1.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Eddie-F-Zie-de-Muziek.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Rudi-Carrell-De-Hoogste-Tijd.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Lenny-Kuhr-The-Poppys-Visite-•-TopPop-1.mp4'
file '/var/www/xxx.com/public_html/wp-content/uploads/2023/04/Rob-de-Nijs-Het-Werd-Zomer-June-21-1977-•-TopPop.mp4'
FFMPEG 命令
#!/bin/bash
ffmpeg \
-re \
-nostdin \
-f concat \
-safe 0 \
-i '/var/www/xxx.com/public_html/wp-content/themes/xxxTheme/Xxx/Data/playlist.txt' \
-c:v libx264 \
-preset superfast \
-r 60 \
-b:v 6000k \
-bufsize 6000k \
-maxrate 6000k \
-f flv "rtmp://localhost/live/stream"
输出
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55921f44df40] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from '/var/www/xxx.com/public_html/wp-content/themes/xxxTheme/xxx/Data/playlist.txt':
Duration: N/A, start: 0.000000, bitrate: 402 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 1280x720 [SAR 1:1 DAR 16:9], 274 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Metadata:
creation_time : 2021-12-23T22:02:18.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 12/23/2021.
vendor_id : [0][0][0][0]
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
Metadata:
creation_time : 2021-12-23T22:02:18.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 12/23/2021.
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
[libx264 @ 0x55921f4f6380] using SAR=1/1
[libx264 @ 0x55921f4f6380] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55921f4f6380] profile High, level 3.2, 4:2:0, 8-bit
[libx264 @ 0x55921f4f6380] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x3 me=dia subme=1 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=0 rc=cbr mbtree=0 bitrate=6000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=6000 vbv_bufsize=6000 nal_hrd=none filler=0 ip_ratio=1.40 pb_ratio=1.30 aq=1:1.00
Output #0, flv, to 'rtmp://localhost/live/stream':
Metadata:
encoder : Lavf58.76.100
Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 6000 kb/s, 60 fps, 1k tbn
Metadata:
creation_time : 2021-12-23T22:02:18.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 12/23/2021.
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 libx264
Side data:
cpb: bitrate max/min/avg: 6000000/0/6000000 buffer size: 6000000 vbv_delay: N/A
Stream #0:1(eng): Audio: mp3 ([2][0][0][0] / 0x0002), 44100 Hz, stereo, fltp
Metadata:
creation_time : 2021-12-23T22:02:18.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 12/23/2021.
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 libmp3lame
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55921f44df40] Auto-inserting h264_mp4toannexb bitstream filter2x
^C
[flv @ 0x55921f480140] Failed to update header with correct duration..1kbits/s speed=0.938x
[flv @ 0x55921f480140] Failed to update header with correct filesize.
frame= 309 fps=3.5 q=-1.0 Lsize= 12805kB time=00:01:26.11 bitrate=1218.1kbits/s speed=0.978x
video:12596kB audio:195kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.108573%
[libx264 @ 0x55921f4f6380] frame I:2 Avg QP:11.64 size: 13755
[libx264 @ 0x55921f4f6380] frame P:91 Avg QP: 5.47 size: 71121
[libx264 @ 0x55921f4f6380] frame B:216 Avg QP: 6.94 size: 29623
[libx264 @ 0x55921f4f6380] consecutive B-frames: 2.6% 8.4% 12.6% 76.4%
[libx264 @ 0x55921f4f6380] mb I I16..4: 68.9% 24.8% 6.3%
[libx264 @ 0x55921f4f6380] mb P I16..4: 9.5% 8.1% 12.6% P16..4: 42.8% 0.0% 0.0% 0.0% 0.0% skip:27.0%
[libx264 @ 0x55921f4f6380] mb B I16..4: 1.2% 1.4% 1.1% B16..8: 25.4% 0.0% 0.0% direct:18.1% skip:52.8% L0:39.2% L1:46.6% BI:14.1%
[libx264 @ 0x55921f4f6380] 8x8 transform intra:29.0% inter:22.0%
[libx264 @ 0x55921f4f6380] coded y,uvDC,uvAC intra: 64.0% 57.0% 52.4% inter: 26.2% 16.2% 12.0%
[libx264 @ 0x55921f4f6380] i16 v,h,dc,p: 49% 30% 6% 16%
[libx264 @ 0x55921f4f6380] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 45% 9% 3% 4% 4% 5% 3% 6%
[libx264 @ 0x55921f4f6380] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 31% 9% 6% 6% 5% 6% 5% 7%
[libx264 @ 0x55921f4f6380] i8c dc,h,v,p: 41% 32% 18% 10%
[libx264 @ 0x55921f4f6380] Weighted P-Frames: Y:6.6% UV:3.3%
[libx264 @ 0x55921f4f6380] kb/s:1186.48
Exiting normally, received signal 2.
NGINX 配置
rtmp {
server {
listen 1935;
chunk_size 4096;
allow publish 127.0.0.1;
deny publish all;
application live {
live on;
record off;
push rtmp://live.twitch.tv/app/live_xxx;
}
}
}
答案1
经过进一步研究,结果表明所有文件都需要具有相同的宽高比、帧速率和一些其他内容(https://trac.ffmpeg.org/wiki/Concatenate)。
解决方案是将目录内的所有文件转码为相同的格式和相同的属性。
for i in *.mp4; do mv $i old-$i | ffmpeg -i old-$i -c:v libx264 -preset superfast -r 60 -vf "scale=1280:720" -c:a aac -ar 44100 -b:a 128k ${i%.*}.mp4 -y; done