Skip to content

Commit

Permalink
Merge pull request #215 from kokorin/develop
Browse files Browse the repository at this point in the history
Skip N/A values from ffmpeg progress (#214)
  • Loading branch information
kokorin authored Aug 31, 2021
2 parents 72cb845 + 229dede commit 3052b8e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 8 deletions.
Empty file modified mvnw
100644 → 100755
Empty file.
12 changes: 4 additions & 8 deletions src/main/java/com/github/kokorin/jaffree/util/ParseUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Denis Kokorin
* Copyright 2021 Denis Kokorin, Cromefire_
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ private ParseUtil() {
* @return parsed long or null if value can't be parsed
*/
public static Long parseLong(final String value) {
if (value != null && !value.isEmpty()) {
if (value != null && !value.isEmpty() && !"N/A".equals(value)) {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
Expand All @@ -66,7 +66,7 @@ public static Long parseLong(final String value) {
* @return parsed double or null if value can't be parsed
*/
public static Double parseDouble(final String value) {
if (value != null && !value.isEmpty()) {
if (value != null && !value.isEmpty() && !"N/A".equals(value)) {
try {
return Double.parseDouble(value);
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -163,11 +163,7 @@ private static Double parseDoubleWithSuffix(final String value, final String suf
}

private static String removeSuffix(final String value, final String suffix) {
if (value == null || value.isEmpty()) {
return null;
}

if (!value.endsWith(suffix)) {
if (value == null || value.isEmpty() || !value.endsWith(suffix)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,69 @@ public void onProgress(FFmpegProgress progress) {
Assert.assertEquals((Long) 0L, progress.getDrop());
Assert.assertEquals((Double) 9.29, progress.getSpeed());
}

/**
* Tests progress that has N/A values (first pass in 2 pass encoding for example)
*/
@Test
public void readProgressNA() throws Exception {
final List<FFmpegProgress> progressList = new ArrayList<>();

ProgressListener listener = progressList::add;

FFmpegProgressReader reader = new FFmpegProgressReader(listener);
try (InputStream inputStream = getClass().getResourceAsStream("progress-na.log")) {
reader.readProgress(inputStream);
}

Assert.assertEquals(3, progressList.size());

FFmpegProgress progress = progressList.get(0);

Assert.assertEquals((Long) 1L, progress.getFrame());
Assert.assertEquals((Double) 0., progress.getFps());
Assert.assertEquals((Double) 0., progress.getQ());
Assert.assertNull(progress.getBitrate());
Assert.assertNull(progress.getSize());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.SECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMillis());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MILLISECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMicros());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MICROSECONDS));
Assert.assertEquals((Long) 0L, progress.getDup());
Assert.assertEquals((Long) 0L, progress.getDrop());
Assert.assertEquals((Double) 0., progress.getSpeed());

progress = progressList.get(1);

Assert.assertEquals((Long) 7L, progress.getFrame());
Assert.assertEquals((Double) 0., progress.getFps());
Assert.assertEquals((Double) 0., progress.getQ());
Assert.assertNull(progress.getBitrate());
Assert.assertNull(progress.getSize());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.SECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMillis());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MILLISECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMicros());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MICROSECONDS));
Assert.assertEquals((Long) 0L, progress.getDup());
Assert.assertEquals((Long) 0L, progress.getDrop());
Assert.assertEquals((Double) 0., progress.getSpeed());

progress = progressList.get(2);

Assert.assertEquals((Long) 17L, progress.getFrame());
Assert.assertEquals((Double) 14.77, progress.getFps());
Assert.assertEquals((Double) 0., progress.getQ());
Assert.assertNull(progress.getBitrate());
Assert.assertNull(progress.getSize());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.SECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMillis());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MILLISECONDS));
Assert.assertEquals((Long) 0L, progress.getTimeMicros());
Assert.assertEquals((Long) 0L, progress.getTime(TimeUnit.MICROSECONDS));
Assert.assertEquals((Long) 0L, progress.getDup());
Assert.assertEquals((Long) 0L, progress.getDrop());
Assert.assertEquals((Double) 0., progress.getSpeed());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
frame=1
fps=0.00
stream_0_0_q=0.0
bitrate=N/A
total_size=N/A
out_time_us=0
out_time_ms=0
out_time=00:00:00.000000
dup_frames=0
drop_frames=0
speed= 0x
progress=continue
frame=7
fps=0.00
stream_0_0_q=0.0
bitrate=N/A
total_size=N/A
out_time_us=0
out_time_ms=0
out_time=00:00:00.000000
dup_frames=0
drop_frames=0
speed= 0x
progress=continue
frame=17
fps=14.77
stream_0_0_q=0.0
bitrate=N/A
total_size=N/A
out_time_us=0
out_time_ms=0
out_time=00:00:00.000000
dup_frames=0
drop_frames=0
speed= 0x
progress=continue

0 comments on commit 3052b8e

Please sign in to comment.