Skip to content

Commit

Permalink
VideoAttributes add some parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vvshuai committed May 31, 2022
1 parent 146bec6 commit 359385c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import ws.schild.jave.encode.VideoAttributes;
import ws.schild.jave.encode.enums.PresetEnum;
import ws.schild.jave.info.VideoSize;

/** @author a.schild */
Expand Down Expand Up @@ -58,6 +59,8 @@ public void testEncodeVideo1() throws Exception {
video.setBitRate(160000);
video.setFrameRate(15);
video.setSize(new VideoSize(176, 144));
video.setCrf(18);
video.setPreset(PresetEnum.FAST.getPresetName());
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat("mp4");
attrs.setAudioAttributes(audio);
Expand Down
6 changes: 5 additions & 1 deletion jave-core/src/main/java/ws/schild/jave/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ public void encode(
new ValueArgument(ArgType.OUTFILE, "-pix_fmt",
ea -> ea.getVideoAttributes().flatMap(VideoAttributes::getPixelFormat)),
new ValueArgument(ArgType.OUTFILE, "-vsync",
ea -> ea.getVideoAttributes().flatMap(VideoAttributes::getVsync).map(VsyncMethod::getMethodName))
ea -> ea.getVideoAttributes().flatMap(VideoAttributes::getVsync).map(VsyncMethod::getMethodName)),
new ValueArgument(ArgType.OUTFILE, "-crf",
ea -> ea.getVideoAttributes().flatMap(VideoAttributes::getCrf).map(Object::toString)),
new ValueArgument(ArgType.OUTFILE, "-preset",
ea -> ea.getVideoAttributes().flatMap(VideoAttributes::getPreset))
)
);

Expand Down
55 changes: 55 additions & 0 deletions jave-core/src/main/java/ws/schild/jave/encode/VideoAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ public class VideoAttributes implements Serializable {

private X264_PROFILE x264Profile = null;

/**
* Set the quality for constant quality mode.
* The lower the value, the better the quality and the larger the file size.
* Reference Range:[0, 51]
*/
private Integer crf = null;

/**
* This option itemizes a range of choices from ultrafast (best speed) to placebo (best quality).
*
* {@link ws.schild.jave.encode.enums.PresetEnum}
*/
private String preset = null;


/**
* Returns the codec name for the encoding process.
*
Expand Down Expand Up @@ -298,4 +313,44 @@ public VideoAttributes setX264Profile(X264_PROFILE x264Profile) {
this.x264Profile = x264Profile;
return this;
}

/**
* Set the quality for constant quality mode.
*
* @param crf the crf to set
* @return this instance
*/
public VideoAttributes setCrf(Integer crf) {
this.crf = crf;
return this;
}

/**
* Get the quality for constant quality mode.
*
* @return the crf
*/
public Optional<Integer> getCrf() {
return Optional.ofNullable(crf);
}

/**
* set the quality from {@link ws.schild.jave.encode.enums.PresetEnum}
* @param preset
* @return this instance
*/
public VideoAttributes setPreset(String preset) {
this.preset = preset;
return this;
}

/**
* Get the preset.
*
* @return the preset
*/
public Optional<String> getPreset() {
return Optional.ofNullable(preset);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ws.schild.jave.encode.enums;


public enum PresetEnum {

/**
* Code quality from low to high
*/
ULTRAFAST("ultrafast"),
SUPERFAST("superfast"),
VERYFAST("veryfast"),
FASTER("faster"),
FAST("fast"),
MEDIUM("medium"),
SLOW("slow"),
SLOWER("slower"),
VERYSLOW("veryslow"),
PLACEBO("placebo");

private final String presetName;

private PresetEnum(String presetName) {
this.presetName = presetName;
}

public String getPresetName() {
return presetName;
}
}

0 comments on commit 359385c

Please sign in to comment.