给定输入视频,input.mp4
以下命令会生成一个out
文件夹,其中包含一堆 HLS 视频片段和m3u8
多种分辨率的播放列表文件:
ffmpeg -hide_banner -y -i input.mp4 \
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k -hls_segment_filename out/360p_%03d.ts out/360p.m3u8 \
-vf scale=w=842:h=480:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 1400k -maxrate 1498k -bufsize 2100k -b:a 128k -hls_segment_filename out/480p_%03d.ts out/480p.m3u8 \
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 2800k -maxrate 2996k -bufsize 4200k -b:a 128k -hls_segment_filename out/720p_%03d.ts out/720p.m3u8 \
-vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 5000k -maxrate 5350k -bufsize 7500k -b:a 192k -hls_segment_filename out/1080p_%03d.ts out/1080p.m3u8
运行上述命令时,输出如下所示:
[hls @ 0x12be06030] Opening 'out/360p_000.ts' for writing
[hls @ 0x12be088d0] Opening 'out/480p_000.ts' for writing
[hls @ 0x12be0b810] Opening 'out/720p_000.ts' for writing
[hls @ 0x12be0e790] Opening 'out/1080p_000.ts' for writing
[hls @ 0x12be06030] Opening 'out/360p_001.ts' for writing
[hls @ 0x12be088d0] Opening 'out/480p_001.ts' for writing
[hls @ 0x12be0b810] Opening 'out/720p_001.ts' for writing
[hls @ 0x12be0e790] Opening 'out/1080p_001.ts' for writing
[hls @ 0x12be06030] Opening 'out/360p_002.ts' for writing
[hls @ 0x12be088d0] Opening 'out/480p_002.ts' for writing
[hls @ 0x12be0b810] Opening 'out/720p_002.ts' for writing
[hls @ 0x12be0e790] Opening 'out/1080p_002.ts' for writing
[hls @ 0x12be06030] Opening 'out/360p_003.ts' for writing
[hls @ 0x12be088d0] Opening 'out/480p_003.ts' for writing
[hls @ 0x12be0b810] Opening 'out/720p_003.ts' for writing
[hls @ 0x12be0e790] Opening 'out/1080p_003.ts' for writing
etc
如您所见,ffmpeg 的输出告诉我它正在打开哪些文件进行写入。当关闭文件以进行写入时,ffmpeg 有什么方法可以输出,或者知道何时以编程方式与这些文件交互是安全的?我专门在 Unix 系统上运行它,所以如果答案涉及一些 unix 技巧来监视正在运行的 ffmpeg 进程,那很好,但我宁愿 ffmpeg 在完成写入文件时直接告诉我。