001package net.bramp.ffmpeg.builder; 002 003import com.google.common.collect.ImmutableList; 004import javax.annotation.CheckReturnValue; 005import net.bramp.ffmpeg.options.EncodingOptions; 006import net.bramp.ffmpeg.probe.FFmpegProbeResult; 007 008/** Abstract base class for building FFmpeg input arguments. */ 009public abstract class AbstractFFmpegInputBuilder<T extends AbstractFFmpegInputBuilder<T>> 010 extends AbstractFFmpegStreamBuilder<T> { 011 private final FFmpegProbeResult probeResult; 012 013 private boolean readAtNativeFrameRate; 014 015 /** 016 * Number of times input stream shall be looped. Loop 0 means no loop, loop -1 means infinite 017 * loop. 018 */ 019 private int streamLoop; 020 021 /** Constructs an input builder with the given parent and filename. */ 022 protected AbstractFFmpegInputBuilder(FFmpegBuilder parent, String filename) { 023 this(parent, null, filename); 024 } 025 026 /** Constructs an input builder with the given parent, probe result, and filename. */ 027 protected AbstractFFmpegInputBuilder( 028 FFmpegBuilder parent, FFmpegProbeResult probeResult, String filename) { 029 super(parent, filename); 030 this.probeResult = probeResult; 031 } 032 033 /** Enables reading input at native frame rate. */ 034 public T readAtNativeFrameRate() { 035 this.readAtNativeFrameRate = true; 036 return getThis(); 037 } 038 039 /** 040 * Sets number of times input stream shall be looped. Loop 0 means no loop, loop -1 means infinite 041 * loop. 042 * 043 * @param streamLoop loop counter 044 * @return this 045 */ 046 public T setStreamLoop(int streamLoop) { 047 this.streamLoop = streamLoop; 048 049 return getThis(); 050 } 051 052 public FFmpegProbeResult getProbeResult() { 053 return probeResult; 054 } 055 056 @Override 057 @CheckReturnValue 058 @SuppressWarnings("unchecked") 059 protected T getThis() { 060 return (T) this; 061 } 062 063 @Override 064 public EncodingOptions buildOptions() { 065 return null; 066 } 067 068 @Override 069 protected void addGlobalFlags(FFmpegBuilder parent, ImmutableList.Builder<String> args) { 070 if (this.readAtNativeFrameRate) { 071 args.add("-re"); 072 } 073 074 if (this.streamLoop != 0) { 075 args.add("-stream_loop", Integer.toString(this.streamLoop)); 076 } 077 078 super.addGlobalFlags(parent, args); 079 } 080 081 public int getStreamLoop() { 082 return streamLoop; 083 } 084}