Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
<suppress checks="ParameterName"
files="(probe|builder|options|progress)[\\/]"/>

<!-- Retain existing public method names while providing Google-style alternatives. -->
<suppress checks="GoogleMethodName" files="FFmpegStream\.java"
message="Method name 'getHasBFrames'.*"/>
<suppress checks="GoogleMethodName" files="FFmpegStream\.java"
message="Method name 'getRFrameRate'.*"/>
<suppress checks="GoogleMethodName" files="FFmpegBuilder\.java"
message="Method name 'setVBR'.*"/>
<suppress checks="GoogleMethodName" files="AbstractFFmpegOutputBuilder\.java"
message="Method name 'setBFrames'.*"/>
<suppress files="FFmpeg\.java" checks="GoogleMethodName"
message="Method name 'isFFmpeg'.*"/>
<suppress files="FFprobe\.java" checks="GoogleMethodName"
message="Method name 'isFFprobe'.*"/>
<suppress files="NutDataInputStream\.java" checks="GoogleMethodName"
message="Method name 'resetCRC'.*"/>
<suppress files="NutDataInputStream\.java" checks="GoogleMethodName"
message="Method name 'getCRC'.*"/>

<!-- NUT format parser uses spec-matching names for readability -->
<suppress checks="MemberName|ParameterName|LocalVariableName|AbbreviationAsWordInName|GoogleNonConstantFieldName"
files="nut[\\/]"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.4.2</version>
<version>14.3.0</version>
</dependency>
</dependencies>
<configuration>
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/net/bramp/ffmpeg/FFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,22 @@ public FFmpeg(@Nonnull String path, @Nonnull ProcessFunction runFunction) throws
* @return true iff this is the official ffmpeg binary.
* @throws IOException If a I/O error occurs while executing ffmpeg.
*/
public boolean isFFmpeg() throws IOException {
public boolean isFfmpeg() throws IOException {
return version().startsWith("ffmpeg");
}

/** Returns whether this is ffmpeg, preserving the original method name. */
public boolean isFFmpeg() throws IOException {
return isFfmpeg();
}

/**
* Throws an exception if this is an unsupported version of ffmpeg.
*
* @throws IllegalArgumentException if this is not the official ffmpeg binary.
* @throws IOException If a I/O error occurs while executing ffmpeg.
*/
private void checkIfFFmpeg() throws IllegalArgumentException, IOException {
private void checkIfFfmpeg() throws IllegalArgumentException, IOException {
if (!isFFmpeg()) {
throw new IllegalArgumentException(
"This binary '" + path + "' is not a supported version of ffmpeg");
Expand All @@ -143,7 +148,7 @@ private void checkIfFFmpeg() throws IllegalArgumentException, IOException {

/** Returns the list of supported codecs. */
public synchronized @Nonnull List<Codec> codecs() throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();

if (this.codecs == null) {
codecs = new ArrayList<>();
Expand Down Expand Up @@ -173,7 +178,7 @@ private void checkIfFFmpeg() throws IllegalArgumentException, IOException {

/** Returns the list of supported filters. */
public synchronized @Nonnull List<Filter> filters() throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();

if (this.filters == null) {
filters = new ArrayList<>();
Expand Down Expand Up @@ -213,7 +218,7 @@ private void checkIfFFmpeg() throws IllegalArgumentException, IOException {

/** Returns the list of supported formats. */
public synchronized @Nonnull List<Format> formats() throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();

if (this.formats == null) {
formats = new ArrayList<>();
Expand Down Expand Up @@ -242,7 +247,7 @@ private void checkIfFFmpeg() throws IllegalArgumentException, IOException {

/** Returns the list of supported pixel formats. */
public synchronized List<PixelFormat> pixelFormats() throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();

if (this.pixelFormats == null) {
pixelFormats = new ArrayList<>();
Expand Down Expand Up @@ -275,7 +280,7 @@ public synchronized List<PixelFormat> pixelFormats() throws IOException {

/** Returns the list of supported channel layouts. */
public synchronized List<ChannelLayout> channelLayouts() throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();

if (this.channelLayouts == null) {
Process p = runFunc.run(ImmutableList.of(path, "-layouts"));
Expand Down Expand Up @@ -305,7 +310,7 @@ protected ProgressParser createProgressParser(ProgressListener listener) throws

@Override
public void run(List<String> args) throws IOException {
checkIfFFmpeg();
checkIfFfmpeg();
super.run(args);
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/net/bramp/ffmpeg/FFprobe.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public FFmpegProbeResult probe(
// TODO: Add Probe Inputstream
/** Probes media using the supplied arguments and returns the result. */
public FFmpegProbeResult probe(List<String> args) throws IOException {
checkIfFFprobe();
checkIfFfprobe();

Process p = runFunc.run(path(args));
try {
Expand Down Expand Up @@ -108,17 +108,22 @@ public FFmpegProbeResult probe(List<String> args) throws IOException {
* @return true iff this is the official ffprobe binary.
* @throws IOException If a I/O error occurs while executing ffprobe.
*/
public boolean isFFprobe() throws IOException {
public boolean isFfprobe() throws IOException {
return version().startsWith("ffprobe");
}

/** Returns whether this is ffprobe, preserving the original method name. */
public boolean isFFprobe() throws IOException {
return isFfprobe();
}

/**
* Throws an exception if this is an unsupported version of ffprobe.
*
* @throws IllegalArgumentException if this is not the official ffprobe binary.
* @throws IOException If a I/O error occurs while executing ffprobe.
*/
private void checkIfFFprobe() throws IllegalArgumentException, IOException {
private void checkIfFfprobe() throws IllegalArgumentException, IOException {
if (!isFFprobe()) {
throw new IllegalArgumentException(
"This binary '" + path + "' is not a supported version of ffprobe");
Expand All @@ -127,7 +132,7 @@ private void checkIfFFprobe() throws IllegalArgumentException, IOException {

@Override
public void run(List<String> args) throws IOException {
checkIfFFprobe();
checkIfFfprobe();
super.run(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,21 @@ public T setVideoPreset(String preset) {
* @param bFrames number of b-frames
* @return this
*/
public T setBFrames(int bFrames) {
public T setBframes(int bFrames) {
this.bFrames = bFrames;
return (T) this;
}

/**
* Sets the number of b-frames using the original method name.
*
* @param bFrames number of b-frames
* @return this
*/
public T setBFrames(int bFrames) {
return setBframes(bFrames);
}

/**
* Sets Video Filter.
*
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,22 @@ public FFmpegBuilder setVideoFilter(String filter) {
* @param quality the quality between 0 and 9. Where 0 is best.
* @return FFmpegBuilder
*/
public FFmpegBuilder setVBR(Integer quality) {
public FFmpegBuilder setVbr(Integer quality) {
Preconditions.checkArgument(quality > 0 && quality < 9, "vbr must be between 0 and 9");
this.qscale = quality;
return this;
}

/**
* Sets the VBR quality using the original method name.
*
* @param quality the quality between 0 and 9. Where 0 is best.
* @return this
*/
public FFmpegBuilder setVBR(Integer quality) {
return setVbr(quality);
}

/**
* Add additional ouput arguments (for flags which aren't currently supported).
*
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ public NutDataInputStream(InputStream in) {
}

/** Resets the CRC32 checksum for a new calculation range. */
public void resetCRC() {
public void resetCrc() {
startCrcRange = count.getCount();
crc.resetCrc();
}

/** Resets the CRC32 checksum using the original method name. */
public void resetCRC() {
resetCrc();
}

/** Returns the current CRC32 checksum value. */
public long getCRC() {
public long getCrc() {
endCrcRange = count.getCount();
return crc.getValue();
}

/** Returns the CRC32 checksum using the original method name. */
public long getCRC() {
return getCrc();
}

/** Reads a variable-length encoded integer up to 32 bits. */
public int readVarInt() throws IOException {
boolean more;
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/bramp/ffmpeg/probe/FFmpegStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ public int getHeight() {
return height;
}

public int getHasBFrames() {
public int getHasBframes() {
return has_b_frames;
}

/** Returns the number of B-frames, preserving the original method name. */
public int getHasBFrames() {
return getHasBframes();
}

public String getSampleAspectRatio() {
return sample_aspect_ratio;
}
Expand Down Expand Up @@ -150,10 +155,15 @@ public String getId() {
return id;
}

public Fraction getRFrameRate() {
public Fraction getRframeRate() {
return r_frame_rate;
}

/** Returns the real frame rate, preserving the original method name. */
public Fraction getRFrameRate() {
return getRframeRate();
}

public Fraction getAvgFrameRate() {
return avg_frame_rate;
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/net/bramp/ffmpeg/FFmpegTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
Expand Down Expand Up @@ -60,6 +61,8 @@ public static <T> List<T> argThatHasItem(T s) {
public void testVersion() throws Exception {
assertEquals("ffmpeg version 0.10.9-7:0.10.9-1~raring1", ffmpeg.version());
assertEquals("ffmpeg version 0.10.9-7:0.10.9-1~raring1", ffmpeg.version());
assertTrue(ffmpeg.isFfmpeg());
assertTrue(ffmpeg.isFFmpeg());

verify(runFunc, times(1)).run(argThatHasItem("-version"));
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/net/bramp/ffmpeg/FFprobeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public void testVersion() throws Exception {
"ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers", ffprobe.version());
assertEquals(
"ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers", ffprobe.version());
assertTrue(ffprobe.isFfprobe());
assertTrue(ffprobe.isFFprobe());

verify(runFunc, times(1)).run(argThatHasItem("-version"));
}
Expand Down Expand Up @@ -629,6 +631,7 @@ public void testFullVideoStreamDeserialization() throws IOException {
assertEquals(1280, stream.getWidth());
assertEquals(720, stream.getHeight());
assertEquals(0, stream.getHasBFrames());
assertEquals(stream.getHasBFrames(), stream.getHasBframes());
assertEquals("1:1", stream.getSampleAspectRatio());
assertEquals("16:9", stream.getDisplayAspectRatio());
assertEquals("yuv420p", stream.getPixFmt());
Expand All @@ -639,6 +642,7 @@ public void testFullVideoStreamDeserialization() throws IOException {
assertEquals("4", stream.getNalLengthSize());
assertEquals("0x1", stream.getId());
assertEquals(Fraction.getFraction(25, 1), stream.getRFrameRate());
assertEquals(stream.getRFrameRate(), stream.getRframeRate());
assertEquals(Fraction.getFraction(25, 1), stream.getAvgFrameRate());
assertEquals(Fraction.getFraction(1, 12800), stream.getTimeBase());
assertEquals(0, stream.getStartPts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public void testSetComplexFilter() {
@Test
public void testSetBFrames() {
List<String> command = getBuilder().setBFrames(2).build(0);
List<String> styledCommand = getBuilder().setBframes(2).build(0);

assertThat(removeCommon(command), is(ImmutableList.of("-bf", "2")));
assertThat(removeCommon(styledCommand), is(ImmutableList.of("-bf", "2")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,14 @@ public void testExtraArgs() {
@Test
public void testVbr() {
List<String> args =
new FFmpegBuilder().setInput("input").done().setVBR(2).addOutput("output").done().build();
new FFmpegBuilder().setInput("input").done().setVbr(2).addOutput("output").done().build();

assertEquals(
args, ImmutableList.of("-y", "-v", "error", "-i", "input", "-qscale:a", "2", "output"));

List<String> legacyArgs =
new FFmpegBuilder().setInput("input").done().setVBR(2).addOutput("output").done().build();
assertEquals(args, legacyArgs);
}

@Test(expected = IllegalArgumentException.class)
Expand Down
Loading