-
-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue/138 build ffprobe command (#268)
* Allow probing with custom arguments * Parse ffprobe response for -show_frames and -show_packets * Use FFprobe.path instead of providing executable manually * Add FFprobeBuilder * Use FFprobeBuilder when testing -show_packets and -show_frames * chore: Remove stream api usage * Test probe parameter options
- Loading branch information
Showing
14 changed files
with
27,695 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/net/bramp/ffmpeg/adapter/FFmpegPacketsAndFramesAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.bramp.ffmpeg.adapter; | ||
|
||
import com.google.gson.*; | ||
import net.bramp.ffmpeg.probe.FFmpegFrame; | ||
import net.bramp.ffmpeg.probe.FFmpegFrameOrPacket; | ||
import net.bramp.ffmpeg.probe.FFmpegPacket; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
public class FFmpegPacketsAndFramesAdapter implements JsonDeserializer<FFmpegFrameOrPacket> { | ||
@Override | ||
public FFmpegFrameOrPacket deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
if (jsonElement instanceof JsonObject) { | ||
final String objectType = ((JsonObject) jsonElement).get("type").getAsString(); | ||
|
||
if (objectType.equals("packet")) { | ||
return jsonDeserializationContext.deserialize(jsonElement, FFmpegPacket.class); | ||
} else { | ||
return jsonDeserializationContext.deserialize(jsonElement, FFmpegFrame.class); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/net/bramp/ffmpeg/builder/FFprobeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package net.bramp.ffmpeg.builder; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import javax.annotation.CheckReturnValue; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static net.bramp.ffmpeg.Preconditions.checkNotEmpty; | ||
|
||
/** | ||
* Builds a ffprobe command line | ||
*/ | ||
public class FFprobeBuilder { | ||
private boolean showFormat = true; | ||
private boolean showStreams = true; | ||
private boolean showChapters = true; | ||
private boolean showFrames = false; | ||
private boolean showPackets = false; | ||
private String userAgent; | ||
private String input; | ||
|
||
private final List<String> extraArgs = new ArrayList<>(); | ||
|
||
public FFprobeBuilder setShowFormat(boolean showFormat) { | ||
this.showFormat = showFormat; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setShowStreams(boolean showStreams) { | ||
this.showStreams = showStreams; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setShowChapters(boolean showChapters) { | ||
this.showChapters = showChapters; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setShowFrames(boolean showFrames) { | ||
this.showFrames = showFrames; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setShowPackets(boolean showPackets) { | ||
this.showPackets = showPackets; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setUserAgent(String userAgent) { | ||
this.userAgent = userAgent; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder setInput(String filename) { | ||
checkNotNull(filename); | ||
this.input = filename; | ||
return this; | ||
} | ||
|
||
public FFprobeBuilder addExtraArgs(String... values) { | ||
checkArgument(values != null, "extraArgs can not be null"); | ||
checkArgument(values.length > 0, "one or more values must be supplied"); | ||
checkNotEmpty(values[0], "first extra arg may not be empty"); | ||
|
||
for (String value : values) { | ||
extraArgs.add(checkNotNull(value)); | ||
} | ||
return this; | ||
} | ||
|
||
@CheckReturnValue | ||
public List<String> build() { | ||
ImmutableList.Builder<String> args = new ImmutableList.Builder<>(); | ||
|
||
Preconditions.checkNotNull(input, "Input must be specified"); | ||
|
||
args | ||
.add("-v", "quiet") | ||
.add("-print_format", "json") | ||
.add("-show_error"); | ||
|
||
if (userAgent != null) { | ||
args.add("-user_agent", userAgent); | ||
} | ||
|
||
args.addAll(extraArgs); | ||
|
||
if (showFormat) args.add("-show_format"); | ||
if (showStreams) args.add("-show_streams"); | ||
if (showChapters) args.add("-show_chapters"); | ||
if (showPackets) args.add("-show_packets"); | ||
if (showFrames) args.add("-show_frames"); | ||
|
||
args.add(input); | ||
|
||
return args.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.bramp.ffmpeg.probe; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import net.bramp.ffmpeg.shared.CodecType; | ||
|
||
@SuppressFBWarnings( | ||
value = {"UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"}, | ||
justification = "POJO objects where the fields are populated by gson") | ||
public class FFmpegFrame implements FFmpegFrameOrPacket { | ||
public CodecType media_type; | ||
public int stream_index; | ||
public int key_frame; | ||
public long pkt_pts; | ||
public double pkt_pts_time; | ||
public long pkt_dts; | ||
public double pkt_dts_time; | ||
public long best_effort_timestamp; | ||
public float best_effort_timestamp_time; | ||
public long pkt_duration; | ||
public float pkt_duration_time; | ||
public long pkt_pos; | ||
public long pkt_size; | ||
public String sample_fmt; | ||
public int nb_samples; | ||
public int channels; | ||
public String channel_layout; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/net/bramp/ffmpeg/probe/FFmpegFrameOrPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package net.bramp.ffmpeg.probe; | ||
|
||
public interface FFmpegFrameOrPacket { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.bramp.ffmpeg.probe; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import net.bramp.ffmpeg.shared.CodecType; | ||
|
||
@SuppressFBWarnings( | ||
value = {"UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"}, | ||
justification = "POJO objects where the fields are populated by gson") | ||
public class FFmpegPacket implements FFmpegFrameOrPacket { | ||
public CodecType codec_type; | ||
public int stream_index; | ||
public long pts; | ||
public double pts_time; | ||
public long dts; | ||
public double dts_time; | ||
public long duration; | ||
public float duration_time; | ||
public String size; | ||
public String pos; | ||
public String flags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.