@@ -208,6 +208,7 @@ public void onResult(String mediaDetailsStr)
208208 static MediaInfo parseMediaInfo (File mediaFile , String string )
209209 {
210210 long durationMs = 0 ;
211+ Integer totalBitrate = null ;
211212 MediaContainer container = null ;
212213 VideoCodec videoCodec = null ;
213214 String videoResolution = null ;
@@ -263,6 +264,24 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
263264 }
264265
265266 durationMs = time ;
267+
268+ split = line .split ("," );
269+ for (String item : split )
270+ {
271+ if (item .contains ("bitrate:" ))
272+ {
273+ item = item .replace ("bitrate:" , "" ).replace ("kb/s" , "" ).trim ();
274+ try
275+ {
276+ // This may be used later if the video bitrate cannot be determined.
277+ totalBitrate = Integer .parseInt (item );
278+ }
279+ catch (NumberFormatException e )
280+ {
281+ continue ;
282+ }
283+ }
284+ }
266285 }
267286
268287 if (line .startsWith ("Input" ))
@@ -388,6 +407,29 @@ static MediaInfo parseMediaInfo(File mediaFile, String string)
388407 }
389408 }
390409
410+ if (totalBitrate != null )
411+ {
412+ if (videoBitrate == null )
413+ {
414+ if (audioBitrate != null )
415+ {
416+ // We know the audio bitrate, we can calculate the video bitrate
417+ videoBitrate = totalBitrate - audioBitrate ;
418+ }
419+
420+ if (videoBitrate == null )
421+ {
422+ // We do not know any of the separate bitrates. Lets guess 100 kb/s for the audio,
423+ // and subtract that from the total to guess the video bitrate.
424+
425+ // As a guess, subtract 100 kb/s from the bitrate for audio, and
426+ // assume that the video is the rest. This should be a decent-ish
427+ // estimate if the video bitrate cannot be found later.
428+ videoBitrate = totalBitrate - 100 ;
429+ }
430+ }
431+ }
432+
391433 MediaInfo info = new MediaInfo (mediaFile , durationMs , container , videoCodec , videoResolution ,
392434 videoBitrate , videoFramerate , audioCodec , audioSampleRate , audioBitrate , audioChannels );
393435 return info ;
0 commit comments