001package net.bramp.ffmpeg.job;
002
003import static com.google.common.base.Preconditions.checkNotNull;
004
005import com.google.common.base.Throwables;
006import java.util.List;
007import javax.annotation.Nullable;
008import net.bramp.ffmpeg.FFmpeg;
009import net.bramp.ffmpeg.builder.FFmpegBuilder;
010import net.bramp.ffmpeg.progress.ProgressListener;
011
012/** An FFmpeg job that performs a single encoding pass. */
013public class SinglePassFFmpegJob extends FFmpegJob {
014
015  public final FFmpegBuilder builder;
016
017  /** Constructs a new single-pass FFmpeg job. */
018  public SinglePassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder) {
019    this(ffmpeg, builder, null);
020  }
021
022  /** Creates a new single-pass FFmpeg job with the given progress listener. */
023  public SinglePassFFmpegJob(
024      FFmpeg ffmpeg, FFmpegBuilder builder, @Nullable ProgressListener listener) {
025    super(ffmpeg, listener);
026    this.builder = checkNotNull(builder);
027
028    // Build the args now (but throw away the results). This allows the illegal arguments to be
029    // caught early, but also allows the ffmpeg command to actually alter the arguments when
030    // running.
031    @SuppressWarnings("unused")
032    List<String> unused = this.builder.build();
033  }
034
035  @Override
036  public void run() {
037
038    state = State.RUNNING;
039
040    try {
041      ffmpeg.run(builder, listener);
042      state = State.FINISHED;
043
044    } catch (Throwable t) {
045      state = State.FAILED;
046
047      Throwables.throwIfUnchecked(t);
048      throw new RuntimeException(t);
049    }
050  }
051}