Given an input video, input.mp4
, the following command produces an out
folder containing a bunch of HLS video segments and m3u8
playlist files for a number of resolutions:
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
When running said command, the output looks like the following:
[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
As you can see, the output of ffmpeg tells me what files it is opening for writing. Is there any way for ffmpeg to output when files are closed for writing, or otherwise knowing when it is safe to interact with those files programmatically? I am specifically running this on Unix systems so if the answer involves some unix tricks to monitor the running ffmpeg process that's fine, but I'd rather ffmpeg tell me directly when it's done writing to files.