001package net.bramp.ffmpeg; 002 003import static com.google.common.base.Preconditions.checkNotNull; 004 005import java.io.IOException; 006import net.bramp.ffmpeg.builder.FFmpegBuilder; 007import net.bramp.ffmpeg.job.FFmpegJob; 008import net.bramp.ffmpeg.job.SinglePassFFmpegJob; 009import net.bramp.ffmpeg.job.TwoPassFFmpegJob; 010import net.bramp.ffmpeg.progress.ProgressListener; 011 012/** Executor that creates and runs FFmpeg jobs. */ 013public class FFmpegExecutor { 014 015 final FFmpeg ffmpeg; 016 final FFprobe ffprobe; 017 018 /** Constructs an FFmpegExecutor using default FFmpeg and FFprobe instances. */ 019 public FFmpegExecutor() throws IOException { 020 this(new FFmpeg(), new FFprobe()); 021 } 022 023 /** Constructs an FFmpegExecutor with the specified FFmpeg instance. */ 024 public FFmpegExecutor(FFmpeg ffmpeg) throws IOException { 025 this(ffmpeg, new FFprobe()); 026 } 027 028 /** Constructs an FFmpegExecutor with the specified FFmpeg and FFprobe instances. */ 029 public FFmpegExecutor(FFmpeg ffmpeg, FFprobe ffprobe) { 030 this.ffmpeg = checkNotNull(ffmpeg); 031 this.ffprobe = checkNotNull(ffprobe); 032 } 033 034 /** Creates a single-pass FFmpeg job from the given builder. */ 035 public FFmpegJob createJob(FFmpegBuilder builder) { 036 return new SinglePassFFmpegJob(ffmpeg, builder); 037 } 038 039 /** Creates a single-pass FFmpeg job with a progress listener. */ 040 public FFmpegJob createJob(FFmpegBuilder builder, ProgressListener listener) { 041 return new SinglePassFFmpegJob(ffmpeg, builder, listener); 042 } 043 044 /** 045 * Creates a two pass job, which will execute FFmpeg twice to produce a better quality output. 046 * More info: https://trac.ffmpeg.org/wiki/x264EncodingGuide#twopass 047 * 048 * @param builder The FFmpegBuilder 049 * @return A new two-pass FFmpegJob 050 */ 051 public FFmpegJob createTwoPassJob(FFmpegBuilder builder) { 052 return new TwoPassFFmpegJob(ffmpeg, builder); 053 } 054 055 /** Creates a two-pass FFmpeg job with a progress listener. */ 056 public FFmpegJob createTwoPassJob(FFmpegBuilder builder, ProgressListener listener) { 057 return new TwoPassFFmpegJob(ffmpeg, builder, listener); 058 } 059}