ffmpeg-cli-wrapper
ffmpeg-cli-wrapper copied to clipboard
Listen to file creation during FFmpegExecutor run
trafficstars
The question Hi! My command is:
ffmpeg -i "https://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8" -c:a copy -c:v libx264 -f hls -hls_segments_filename "./out/segment%d.ts" -hls_flags delete_segments+append_list ./out/master_playlist.m3u8
that is:
- transcoding an H.265 source to H.264;
- producing a HLS playlist in the local fs;
- live streaming it.
I made it work in a Spring-Boot project with ffmpeg-cli-wrapper. Now, as an upgrade, I would like to make my code "listen to" the creation of master_playlist.m3u8 as soon as this event happens.
Example ffmpeg command
ffmpeg -i [INPUT_PLAYLIST] -c:a copy -c:v libx264 -f hls -hls_flags append_list [OUTPUT_PATH]/[OUTPUT_FILENAME]
What you have tried I wrote this code:
FFmpeg ffmpeg = new FFmpeg([MY_FFMPEG_PATH]);
// Input stream file
String IN = "https://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8";
// Output stream path
String OUT_PATH = "[MY_OUT_PATH]";
// Output stream filename
String OUT_FILE = "[MY_OUT_FILENAME]";
/*
Command to launch:
ffmpeg -i [IN] -c:a copy -c:v libx264 -f hls ... [OUT_PATH]/[OUT_FILE]
*/
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(IN)
.addOutput(OUT_PATH + "/" + OUT_FILE)
.addExtraArgs("-c:a", "copy")
.addExtraArgs("-c:v", "libx264")
.addExtraArgs("-f", "hls")
.addExtraArgs("-hls_segment_filename", OUT_PATH + "/segment%d.ts")
.addExtraArgs("-hls_flags", "delete_segments+append_list")
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
.done()
.setVerbosity(FFmpegBuilder.Verbosity.VERBOSE);
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg);
// Run a one-pass encode
executor.createJob(builder).run();
// This is printed only when the executor ends, but I would like it to happen as soon as master_playlist.m3u8 is created...
System.out.println("Master playlist has been created and can be played now.");
I've learnt from older Issues that the executor is blocking, but I still wonder if there is a way to achieve my goal.
Thanks!