1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| public void getBlackInformation( String filename )
{
String blackDetect = " -vf blackdetect=d=0.1:pic_th=0.70:pix_th=0.00 -an -f null -";
String cmd = "\"" + filename + "\"" + blackDetect ;
Map<String,String> fieldMap = executeInquiry(cmd);
if( fieldMap.containsKey( "black_start" ) )
{
fieldMap.get( "black_start" );
}
}
protected String consumeStream( InputStream is )
{
StringBuilder sb = new StringBuilder();
try
{
BufferedReader br = new BufferedReader( new InputStreamReader( is ) );
String line = br.readLine();
while( line != null )
{
sb.append( line );
line = br.readLine();
}
}
catch( Exception e )
{
e.printStackTrace();
}
return sb.toString();
}
protected Map<String,String> executeInquiry( String filename )
{
System.out.println( "Execute Inquiry for file: " + filename );
Map<String,String> fieldMap = new HashMap<String,String>();
try
{
// Build the command line
StringBuilder sb = new StringBuilder();
sb.append( "ffmpeg" );
sb.append( " -i " );
sb.append( filename );
// Execute the command
System.out.println( "Command line: " + sb );
Process p = Runtime.getRuntime().exec( sb.toString() );
// Read the response
BufferedReader input = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
BufferedReader error = new BufferedReader( new InputStreamReader( p.getErrorStream() ) );
// Parse the input stream
String line = input.readLine();
System.out.println( "ffmpeg execution of: " + filename );
while( line != null )
{
System.out.println( "\t***" + line );
line = input.readLine();
}
// Parse the error stream
line = error.readLine();
System.out.println( "Error Stream: " + filename );
int valtest = 0;
while( line != null )
{
// Handle the line
if( line.startsWith( "FFmpeg version" ) )
{
// Handle the version line:
// FFmpeg version 0.6.2-4:0.6.2-1ubuntu1, Copyright (c) 2000-2010 the Libav developers
String version = line.substring( 15, line.indexOf( ", Copyright", 16 ) );
fieldMap.put( "version", version );
}
else if( line.indexOf( "Duration:" ) != -1 )
{
// Handle Duration line:
// Duration: 00:42:53.59, start: 0.000000, bitrate: 1136 kb/s
String duration = line.substring( line.indexOf( "Duration: " ) + 10, line.indexOf( ", start:" ) );
fieldMap.put( "duration", duration );
String bitrate = line.substring( line.indexOf( "bitrate: " ) + 9 );
fieldMap.put( "bitrate", bitrate );
}
else if( line.indexOf( "black_start:" ) != -1 )
{
this.cpt ++;
String black_start = line.substring( line.indexOf( "black_start:" ) + 12, line.indexOf( " black_end:" ) );
fieldMap.put( "Perte n°"+cpt+" Début", black_start );
String black_end = line.substring( line.indexOf( "black_end:" ) + 10, line.indexOf( " black_duration:" ) );
fieldMap.put( "Perte n°"+cpt+" Fin", black_end );
String black_duration = line.substring( line.indexOf( "black_duration:" ) + 15);
fieldMap.put( "Perte n°"+cpt+" Durée", black_duration );
//label1[cpt].setText(" Debut : "+black_start+" Fin : "+black_end+" Durée : "+black_duration);
dlm.addElement(" Perte n°"+cpt+" - Debut : "+black_start+" Durée : "+black_duration+" Fin : "+black_end+ " ");
//labelPertes.setVisible(true);
valtest = 1;
}
//Read the next line
System.out.println( "\t***" + line );
line = error.readLine();
}
if (valtest==0)
{
Color gree = new Color(61, 200, 42);
labelPertes.setVisible(false);
labelIfBlack.setText("Pas de perte d'enregistrement");
labelIfBlack.setForeground(gree);
}
else
{
labelIfBlack.setText("Pertes detectées");
labelIfBlack.setForeground(Color.red);
}
}
catch( Exception e )
{
e.printStackTrace();
}
// Debug: dump fields:
System.out.println( "Fields:" );
for( String field : fieldMap.keySet() )
{
System.out.println( "\t" + field + " = " + fieldMap.get( field ) );
}
return fieldMap;
} |
Partager