Skip to content

Commit b3b21a9

Browse files
authored
Revert "Bug/347 invalid chars in hls time (#348)" (#349)
This reverts commit c932b78.
1 parent c932b78 commit b3b21a9

File tree

3 files changed

+6
-77
lines changed

3 files changed

+6
-77
lines changed

src/main/java/net/bramp/ffmpeg/FFmpegUtils.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ public static String toTimecode(long duration, TimeUnit units) {
7474
return ZERO.trimTrailingFrom(String.format("%02d:%02d:%02d.%09d", hours, minutes, seconds, ns));
7575
}
7676

77-
public static String toSeconds(long duration, TimeUnit units) {
78-
// FIXME Negative durations are also supported.
79-
// https://www.ffmpeg.org/ffmpeg-utils.html#Time-duration
80-
checkArgument(duration >= 0, "duration must be positive");
81-
82-
return Float.toString(units.toMillis(duration) / 1_000f);
83-
}
84-
8577
/**
8678
* Returns the number of nanoseconds this timecode represents. The string is expected to be in the
8779
* format "hour:minute:second", where second can be a decimal number.

src/main/java/net/bramp/ffmpeg/builder/FFmpegHlsOutputBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.google.common.collect.ImmutableList;
55
import javax.annotation.CheckReturnValue;
66
import static com.google.common.base.Preconditions.*;
7-
import static net.bramp.ffmpeg.FFmpegUtils.toSeconds;
87
import static net.bramp.ffmpeg.FFmpegUtils.toTimecode;
98
import static net.bramp.ffmpeg.Preconditions.checkNotEmpty;
109
import java.util.concurrent.TimeUnit;
@@ -107,7 +106,7 @@ public FFmpegHlsOutputBuilder setHlsBaseUrl(String baseurl) {
107106
protected void addFormatArgs(ImmutableList.Builder<String> args) {
108107
super.addFormatArgs(args);
109108
if (hls_time != null) {
110-
args.add("-hls_time", toSeconds(hls_time, TimeUnit.MILLISECONDS));
109+
args.add("-hls_time", toTimecode(hls_time, TimeUnit.MILLISECONDS));
111110
}
112111

113112
if (!Strings.isNullOrEmpty(hls_segment_filename)) {

src/test/java/net/bramp/ffmpeg/builder/FFmpegHlsOutputBuilderTest.java

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
import com.google.common.collect.ImmutableList;
44

5-
import java.nio.file.DirectoryStream;
65
import java.nio.file.Files;
7-
import java.nio.file.Path;
86
import java.nio.file.Paths;
97
import java.util.concurrent.TimeUnit;
108

119
import net.bramp.ffmpeg.FFmpeg;
12-
import net.bramp.ffmpeg.FFprobe;
1310
import net.bramp.ffmpeg.fixtures.Samples;
14-
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
1511
import org.junit.Test;
1612
import java.io.IOException;
1713
import java.util.List;
@@ -37,7 +33,7 @@ public void testAddHlsOutput() {
3733
.done()
3834
.build();
3935

40-
assertEquals(ImmutableList.of("-y", "-v", "error", "-i", "input", "-f", "hls", "-hls_time", "0.005",
36+
assertEquals(ImmutableList.of("-y", "-v", "error", "-i", "input", "-f", "hls", "-hls_time", "00:00:00.005",
4137
"-hls_segment_filename", "file%03d.ts", "-hls_init_time", "00:00:00.003",
4238
"-hls_list_size", "3", "-hls_base_url", "test1234/", "output.m3u8"), args);
4339
}
@@ -58,14 +54,16 @@ public void mixedHlsAndDefault() {
5854
.done()
5955
.build();
6056

61-
assertEquals(ImmutableList.of("-y", "-v", "error", "-i", "input","-f","hls","-b:v","3","-vf","TEST","-hls_time", "0.005",
57+
assertEquals(ImmutableList.of("-y", "-v", "error", "-i", "input","-f","hls","-b:v","3","-vf","TEST","-hls_time", "00:00:00.005",
6258
"-hls_segment_filename", "file%03d.ts", "-hls_init_time", "00:00:00.003",
6359
"-hls_list_size", "3", "-hls_base_url", "test1234/", "output.m3u8"), args);
6460
}
6561

6662
@Test
6763
public void testConvertVideoToHls() throws IOException {
68-
cleanupTmp();
64+
Files.createDirectories(Paths.get("tmp/"));
65+
Files.deleteIfExists(Paths.get("tmp/output.m3u8"));
66+
Files.deleteIfExists(Paths.get("tmp/file000.m3u8"));
6967

7068
List<String> command = new FFmpegBuilder()
7169
.setInput(Samples.TEST_PREFIX + Samples.base_big_buck_bunny_720p_1mb)
@@ -84,64 +82,4 @@ public void testConvertVideoToHls() throws IOException {
8482
assertTrue(Files.exists(Paths.get("tmp/output.m3u8")));
8583
assertTrue(Files.exists(Paths.get("tmp/file000.ts")));
8684
}
87-
88-
@Test
89-
public void testConvertVideoToHlsFileSecondDuration() throws IOException {
90-
cleanupTmp();
91-
92-
List<String> command = new FFmpegBuilder()
93-
.setInput(Samples.TEST_PREFIX + Samples.base_big_buck_bunny_720p_1mb)
94-
.addHlsOutput("tmp/output.m3u8")
95-
.setHlsTime(1, TimeUnit.SECONDS)
96-
.setHlsListSize(0)
97-
.setHlsSegmentFileName("tmp/file%03d.ts")
98-
.addExtraArgs("-force_key_frames", "expr:gte(t,n_forced)")
99-
.done()
100-
.build();
101-
102-
new FFmpeg().run(command);
103-
104-
FFmpegProbeResult probe = new FFprobe().probe("tmp/file000.ts");
105-
106-
assertEquals(probe.getStreams().get(0).getDuration(), 1, 0.1);
107-
}
108-
109-
@Test
110-
public void testConvertVideoToHlsFileMillisDuration() throws IOException {
111-
cleanupTmp();
112-
113-
List<String> command = new FFmpegBuilder()
114-
.setInput(Samples.TEST_PREFIX + Samples.base_big_buck_bunny_720p_1mb)
115-
.addHlsOutput("tmp/output.m3u8")
116-
.setHlsTime(500, TimeUnit.MILLISECONDS)
117-
.setHlsListSize(0)
118-
.setHlsSegmentFileName("tmp/file%03d.ts")
119-
.setFrames(30)
120-
.addExtraArgs("-g", "5")
121-
.done()
122-
.build();
123-
124-
new FFmpeg().run(command);
125-
126-
FFmpegProbeResult probe = new FFprobe().probe("tmp/file000.ts");
127-
128-
assertEquals(0.5, probe.getStreams().get(0).getDuration(), 0.1);
129-
}
130-
131-
private void cleanupTmp() throws IOException {
132-
Path tmpFolder = Paths.get("tmp/");
133-
if (!Files.exists(tmpFolder)) {
134-
Files.createDirectory(tmpFolder);
135-
return;
136-
}
137-
138-
139-
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(tmpFolder)) {
140-
for (Path sub : directoryStream) {
141-
if (!tmpFolder.equals(sub)) {
142-
Files.deleteIfExists(sub);
143-
}
144-
}
145-
}
146-
}
14785
}

0 commit comments

Comments
 (0)