22
33import com .google .common .collect .ImmutableList ;
44
5- import java .nio .file .DirectoryStream ;
65import java .nio .file .Files ;
7- import java .nio .file .Path ;
86import java .nio .file .Paths ;
97import java .util .concurrent .TimeUnit ;
108
119import net .bramp .ffmpeg .FFmpeg ;
12- import net .bramp .ffmpeg .FFprobe ;
1310import net .bramp .ffmpeg .fixtures .Samples ;
14- import net .bramp .ffmpeg .probe .FFmpegProbeResult ;
1511import org .junit .Test ;
1612import java .io .IOException ;
1713import 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