2020import java .util .regex .Matcher ;
2121import java .util .regex .Pattern ;
2222
23+ import protect .videotranscoder .media .AudioCodec ;
2324import protect .videotranscoder .media .MediaInfo ;
2425import protect .videotranscoder .media .MediaContainer ;
26+ import protect .videotranscoder .media .VideoCodec ;
2527
2628/**
2729 * Utility class for executing ffmpeg
@@ -186,11 +188,12 @@ public void onResult(String mediaDetailsStr)
186188 static MediaInfo parseMediaInfo (File mediaFile , String string )
187189 {
188190 long durationMs = 0 ;
189- String videoCodec = null ;
191+ MediaContainer container = null ;
192+ VideoCodec videoCodec = null ;
190193 String videoResolution = null ;
191194 String videoBitrate = null ;
192195 String videoFramerate = null ;
193- String audioCodec = null ;
196+ AudioCodec audioCodec = null ;
194197 String audioSampleRate = null ;
195198 String audioBitrate = null ;
196199 int audioChannels = 2 ;
@@ -242,6 +245,18 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
242245 durationMs = time ;
243246 }
244247
248+ if (line .startsWith ("Input" ))
249+ {
250+ for (MediaContainer item : MediaContainer .values ())
251+ {
252+ if (line .contains (item .ffmpegName ))
253+ {
254+ container = item ;
255+ break ;
256+ }
257+ }
258+ }
259+
245260 if (line .startsWith ("Stream" ) && line .contains ("Video:" ))
246261 {
247262 // Stream #0:0: Video: h264 (Main), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc
@@ -252,7 +267,9 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
252267 {
253268 continue ;
254269 }
255- videoCodec = split [3 ];
270+
271+ String videoCodecName = split [3 ];
272+ videoCodec = VideoCodec .fromName (videoCodecName );
256273
257274 // Looking for resolution. There are sometimes items such as:
258275 // (mp4a / 0x6134706D)
@@ -274,12 +291,12 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
274291
275292 if (piece .contains ("kb/s" ))
276293 {
277- videoBitrate = piece ;
294+ videoBitrate = piece . replace ( "kb/s" , "" ). trim () ;
278295 }
279296
280297 if (piece .contains ("fps" ))
281298 {
282- videoFramerate = piece ;
299+ videoFramerate = piece . replace ( "fps" , "" ). trim () ;
283300 }
284301 }
285302 }
@@ -294,7 +311,9 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
294311 {
295312 continue ;
296313 }
297- audioCodec = split [3 ];
314+
315+ String audioCodecName = split [3 ];
316+ audioCodec = AudioCodec .fromName (audioCodecName );
298317
299318 split = line .split ("," );
300319 for (String piece : split )
@@ -303,12 +322,12 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
303322
304323 if (piece .contains ("Hz" ))
305324 {
306- audioSampleRate = piece ;
325+ audioSampleRate = piece . replace ( "Hz" , "" ). trim () ;
307326 }
308327
309328 if (piece .contains ("kb/s" ))
310329 {
311- audioBitrate = piece ;
330+ audioBitrate = piece . replace ( "kb/s" , "" ). trim () ;
312331
313332 if (audioBitrate .contains ("(default)" ))
314333 {
@@ -324,7 +343,7 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
324343 }
325344 }
326345
327- MediaInfo info = new MediaInfo (mediaFile , durationMs , videoCodec , videoResolution ,
346+ MediaInfo info = new MediaInfo (mediaFile , durationMs , container , videoCodec , videoResolution ,
328347 videoBitrate , videoFramerate , audioCodec , audioSampleRate , audioBitrate , audioChannels );
329348 return info ;
330349 }
0 commit comments