使用 FFmpeg 处理 m3u8 文件时无法打开片段

使用 FFmpeg 处理 m3u8 文件时无法打开片段

我正在尝试使用 FFmpeg 复制 OBS 的“重放缓冲区”功能,或者至少是类似功能。似乎分段和 m3u8 分段列表文件是使此类功能正常工作的方法,但当我尝试在 FFplay 或 FFmpeg 中使用生成的 m3u8 文件时,它只会抛出以下错误:

[hls @ 0000013f97f2cc40] Failed to open segment x of playlist x
[hls @ 0000013f97f2cc40] Error when loading first segment 'EL00.ts'
C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8: Invalid data found when processing input

我在网上找到的任何其他类似问题似乎都与加密的互联网流有关,但这似乎并不适用于我的情况......有什么想法吗?

构建段和段列表的命令的完整日志:

PS G:\My Drive\Programming\Powershell> ffmpeg -y `
-thread_queue_size 9999 -indexmem 9999 -f dshow -rtbufsize 2147.48M -video_size 1920x1080 -framerate 60 `        
-pixel_format yuv420p -i video="Game Capture HD60 Pro (Video) (#01)":audio="Game Capture HD60 Pro (Audio) (#01)" `
-map 0:0,0:1 -map 0:1 -c:v h264_nvenc -preset: hp -r 60 -rc-lookahead 120 -forced-idr 1 -strict_gop 1 `
-sc_threshold 0 -flags +cgop -force_key_frames "expr:gte(t,n_forced*2)" -pix_fmt yuv420p -b:v 288M -minrate 288M `
-maxrate 288M -bufsize 288M -c:a aac -ar 44100 -b:a 320k -af "aresample=async=250" `
-vsync 1 -max_muxing_queue_size 9999 -f segment -segment_time 10 -segment_wrap 30 `
-segment_list "C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8" -segment_list_size 30 `
-reset_timestamps 1 -segment_format_options max_delay=0 "C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL%02d.ts"
ffmpeg version git-2020-04-03-52523b6 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200328
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv 
--enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf   
  libavutil      56. 42.102 / 56. 42.102
  libavcodec     58. 77.101 / 58. 77.101
  libavformat    58. 42.100 / 58. 42.100
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.101 /  7. 77.101
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, dshow, from 'video=Game Capture HD60 Pro (Video) (#01):audio=Game Capture HD60 Pro (Audio) (#01)':
  Duration: N/A, start: 428884.260511, bitrate: 1536 kb/s
    Stream #0:0: Video: rawvideo (YV12 / 0x32315659), yuv420p, 1920x1080, 60 fps, 60 tbr, 10000k tbn, 10000k tbc 
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 [sync #0:1] (rawvideo (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL00.ts' for writing
Output #0, segment, to 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL%02d.ts':
  Metadata:
    encoder         : Lavf58.42.100
    Stream #0:0: Video: h264 (h264_nvenc) (Main), yuv420p, 1920x1080, q=-1--1, 288000 kb/s, 60 fps, 90k tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.77.101 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 288000000/0/288000000 buffer size: 288000000 vbv_delay: N/A
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc58.77.101 aac
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8.tmp' for writing
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL01.ts' for writing    
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8.tmp' for writing
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL02.ts' for writing
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8.tmp' for writing
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\EL03.ts' for writing    
[segment @ 000002267f603200] Opening 'C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8.tmp' for writing
frame= 2336 fps= 60 q=9.0 Lsize=N/A time=00:00:38.91 bitrate=N/A dup=2 drop=0 speed=0.999x    
video:41733kB audio:1522kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[aac @ 000002267f622140] Qavg: 313.398

利用段和段列表的命令的完整日志:

PS G:\My Drive\Programming\Powershell> ffmpeg -y -i "C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8" -c copy `
"C:\Users\gabri\Videos\FFmpeg\Segment Test\Replays\Test.ts"
ffmpeg version git-2020-04-03-52523b6 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200328
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv 
--enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf   
  libavutil      56. 42.102 / 56. 42.102
  libavcodec     58. 77.101 / 58. 77.101
  libavformat    58. 42.100 / 58. 42.100
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.101 /  7. 77.101
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
[hls @ 0000013f97f2cc40] Skip ('#EXT-X-VERSION:3')
[hls @ 0000013f97f2cc40] Skip ('#EXT-X-ALLOW-CACHE:YES')
[hls @ 0000013f97f2cc40] Opening 'EL00.ts' for reading
[hls @ 0000013f97f2cc40] Failed to open segment 0 of playlist 0
[hls @ 0000013f97f2cc40] Opening 'EL01.ts' for reading
[hls @ 0000013f97f2cc40] Failed to open segment 1 of playlist 0
[hls @ 0000013f97f2cc40] Opening 'EL02.ts' for reading
[hls @ 0000013f97f2cc40] Failed to open segment 2 of playlist 0
[hls @ 0000013f97f2cc40] Opening 'EL03.ts' for reading
[hls @ 0000013f97f2cc40] Failed to open segment 3 of playlist 0
[hls @ 0000013f97f2cc40] Error when loading first segment 'EL00.ts'
C:\Users\gabri\Videos\FFmpeg\Segment Test\Segments\list.m3u8: Invalid data found when processing input

m3u8 文件如下所示:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:11
#EXTINF:10.023222,
EL00.ts
#EXTINF:10.000000,
EL01.ts
#EXTINF:10.000000,
EL02.ts
#EXTINF:8.933333,
EL03.ts
#EXT-X-ENDLIST

相关内容