import com.google.common.collect.ImmutableList; import net.bramp.ffmpeg.builder.FFmpegBuilder; import java.util.ArrayList; import java.util.List; /*** * 适用于hls协议的构造器,<a href="https://ffmpeg.org/ffmpeg-formats.html#hls-1">hls协议相关参数</a> * @author dqk */ public class HLSFFmpegBuilder extends FFmpegBuilder { /*** * Set the maximum number of playlist entries. If set to 0 the list file will contain all the segments. Default value is 5. */ private Integer hlsListSize = 5; /*** * Set the target segment length in seconds. Default value is 2. Segment will be cut on the next key frame after this time has passed. */ private Integer hlsTime = 2; /*** * This is a deprecated option, you can use hls_list_size and hls_flags delete_segments instead it * * This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk to wrap. */ @Deprecated private Integer hlsWrap = 0; public HLSFFmpegBuilder setHlsListSize(Integer hlsListSize) { this.hlsListSize = hlsListSize; return this; } public HLSFFmpegBuilder setHlsTime(Integer hlsTime) { this.hlsTime = hlsTime; return this; } public HLSFFmpegBuilder setHlsWrap(Integer hlsWrap) { this.hlsWrap = hlsWrap; return this; } public Integer getHlsListSize() { return hlsListSize; } public Integer getHlsTime() { return hlsTime; } public Integer getHlsWrap() { return hlsWrap; } @Override public List<String> build() { List<String> args = super.build(); List<String> temp = new ArrayList<>(); setFormat("hls"); if(this.hlsWrap != null){ temp.add("-hls_wrap"); temp.add(hlsWrap.toString()); } if(this.hlsTime != null){ temp.add("-hls_time"); temp.add(hlsTime.toString()); } if(this.hlsListSize != null){ temp.add("-hls_list_size"); temp.add(hlsListSize.toString()); } for(String arg: temp){ args.add(arg); } List<String> newargs = ImmutableList.copyOf(args); return newargs; } }
GkFFmpegBuilder.java
import com.google.common.collect.ImmutableList; import net.bramp.ffmpeg.builder.FFmpegBuilder; import java.util.ArrayList; import java.util.List; /** * 为了方便拓展api中没有的参数 */ public class GkFFmpegBuilder extends FFmpegBuilder { private Long itsoffset; @Override public List<String> build() { // 该数组为不可变数组 (原因未知) List<String> args = super.build(); List<String> temp = new ArrayList<>(); if(this.itsoffset != null){ temp.add("-itsoffset"); temp.add(this.itsoffset.toString()); } for(String arg: args){ temp.add(arg); } List<String> newargs = ImmutableList.copyOf(temp); return newargs; } public Long getItsoffset() { return itsoffset; } public GkFFmpegBuilder setItsoffset(Long itsoffset) { this.itsoffset = itsoffset; return this; } }