From 2c1c19349e0a2cd4219f5f9b1a1aae2140cf765d Mon Sep 17 00:00:00 2001 From: "Billy J. Beltran" Date: Tue, 3 Mar 2020 00:54:49 +0000 Subject: [PATCH 1/2] Add loopAttribute to EncodingAttributes --- .../src/main/java/ws/schild/jave/Encoder.java | 6 +++++ .../ws/schild/jave/EncodingAttributes.java | 27 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/jave-core/src/main/java/ws/schild/jave/Encoder.java b/jave-core/src/main/java/ws/schild/jave/Encoder.java index 06b18c7..f674ab3 100644 --- a/jave-core/src/main/java/ws/schild/jave/Encoder.java +++ b/jave-core/src/main/java/ws/schild/jave/Encoder.java @@ -430,6 +430,7 @@ public void encode(List multimediaObjects, File target, Encodi String formatAttribute = attributes.getFormat(); Float offsetAttribute = attributes.getOffset(); Float durationAttribute = attributes.getDuration(); + boolean loopAttribute = attributes.getLoop(); AudioAttributes audioAttributes = attributes.getAudioAttributes(); VideoAttributes videoAttributes = attributes.getVideoAttributes(); if (audioAttributes == null && videoAttributes == null) @@ -457,6 +458,11 @@ public void encode(List multimediaObjects, File target, Encodi ffmpeg.addArgument("-threads"); ffmpeg.addArgument(Integer.toString(attributes.getDecodingThreads())); } + if (loopAttribute && durationAttribute != null) + { + ffmpeg.addArgument("-loop 1"); + } + ffmpeg.addArgument("-i"); if (multimediaObjects.size() == 1) { diff --git a/jave-core/src/main/java/ws/schild/jave/EncodingAttributes.java b/jave-core/src/main/java/ws/schild/jave/EncodingAttributes.java index d8ec76c..88c59c1 100644 --- a/jave-core/src/main/java/ws/schild/jave/EncodingAttributes.java +++ b/jave-core/src/main/java/ws/schild/jave/EncodingAttributes.java @@ -81,7 +81,11 @@ public class EncodingAttributes implements Serializable { */ private int encodingThreads= -1; - + /** + * Should the input be treated as a loop + */ + private boolean loop = false; + /** * Returns the format name for the encoded target multimedia file. * @@ -146,6 +150,25 @@ public EncodingAttributes setDuration(Float duration) { return this; } + /* + * Returns if the input is to be considered for looping. + * @return if the input will be looped. + */ + public boolean getLoop() { + return loop; + } + + /** + * Sets if the inputs will be looped or not. + * + * @param loop if the input should be looped. + * @return this instance + */ + public EncodingAttributes setLoop(boolean loop) { + this.loop = loop; + return this; + } + /** * Returns the attributes for the encoding of the audio stream in the target * multimedia file. @@ -199,7 +222,7 @@ public EncodingAttributes setVideoAttributes(VideoAttributes videoAttributes) { @Override public String toString() { return getClass().getName() + "(format=" + format + ", offset=" - + offset + ", duration=" + duration + ", audioAttributes=" + + offset + ", duration=" + duration + ",loop=" + loop + ", audioAttributes=" + audioAttributes + ", videoAttributes=" + videoAttributes + ")"; } From c1bca07a9a1fed3a81c80cd0ed0d7f00ee1c3ed5 Mon Sep 17 00:00:00 2001 From: "Billy J. Beltran" Date: Tue, 3 Mar 2020 10:10:48 +0000 Subject: [PATCH 2/2] Update -loop flag handling to not error ffmpeg --- jave-core/src/main/java/ws/schild/jave/Encoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jave-core/src/main/java/ws/schild/jave/Encoder.java b/jave-core/src/main/java/ws/schild/jave/Encoder.java index f674ab3..0ce6c8f 100644 --- a/jave-core/src/main/java/ws/schild/jave/Encoder.java +++ b/jave-core/src/main/java/ws/schild/jave/Encoder.java @@ -460,7 +460,8 @@ public void encode(List multimediaObjects, File target, Encodi } if (loopAttribute && durationAttribute != null) { - ffmpeg.addArgument("-loop 1"); + ffmpeg.addArgument("-loop"); + ffmpeg.addArgument("1"); } ffmpeg.addArgument("-i");