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 012public class SinglePassFFmpegJob extends FFmpegJob { 013 014 public final FFmpegBuilder builder; 015 016 public SinglePassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder) { 017 this(ffmpeg, builder, null); 018 } 019 020 public SinglePassFFmpegJob( 021 FFmpeg ffmpeg, FFmpegBuilder builder, @Nullable ProgressListener listener) { 022 super(ffmpeg, listener); 023 this.builder = checkNotNull(builder); 024 025 // Build the args now (but throw away the results). This allows the illegal arguments to be 026 // caught early, but also allows the ffmpeg command to actually alter the arguments when 027 // running. 028 List<String> unused = this.builder.build(); 029 } 030 031 @Override 032 public void run() { 033 034 state = State.RUNNING; 035 036 try { 037 ffmpeg.run(builder, listener); 038 state = State.FINISHED; 039 040 } catch (Throwable t) { 041 state = State.FAILED; 042 043 Throwables.throwIfUnchecked(t); 044 throw new RuntimeException(t); 045 } 046 } 047}