2
2
3
3
import com .google .common .collect .ImmutableList ;
4
4
5
- import java .nio .file .DirectoryStream ;
6
5
import java .nio .file .Files ;
7
- import java .nio .file .Path ;
8
6
import java .nio .file .Paths ;
9
7
import java .util .concurrent .TimeUnit ;
10
8
11
9
import net .bramp .ffmpeg .FFmpeg ;
12
- import net .bramp .ffmpeg .FFprobe ;
13
10
import net .bramp .ffmpeg .fixtures .Samples ;
14
- import net .bramp .ffmpeg .probe .FFmpegProbeResult ;
15
11
import org .junit .Test ;
16
12
import java .io .IOException ;
17
13
import java .util .List ;
@@ -37,7 +33,7 @@ public void testAddHlsOutput() {
37
33
.done ()
38
34
.build ();
39
35
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" ,
41
37
"-hls_segment_filename" , "file%03d.ts" , "-hls_init_time" , "00:00:00.003" ,
42
38
"-hls_list_size" , "3" , "-hls_base_url" , "test1234/" , "output.m3u8" ), args );
43
39
}
@@ -58,14 +54,16 @@ public void mixedHlsAndDefault() {
58
54
.done ()
59
55
.build ();
60
56
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" ,
62
58
"-hls_segment_filename" , "file%03d.ts" , "-hls_init_time" , "00:00:00.003" ,
63
59
"-hls_list_size" , "3" , "-hls_base_url" , "test1234/" , "output.m3u8" ), args );
64
60
}
65
61
66
62
@ Test
67
63
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" ));
69
67
70
68
List <String > command = new FFmpegBuilder ()
71
69
.setInput (Samples .TEST_PREFIX + Samples .base_big_buck_bunny_720p_1mb )
@@ -84,64 +82,4 @@ public void testConvertVideoToHls() throws IOException {
84
82
assertTrue (Files .exists (Paths .get ("tmp/output.m3u8" )));
85
83
assertTrue (Files .exists (Paths .get ("tmp/file000.ts" )));
86
84
}
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
- }
147
85
}
0 commit comments