public static boolean repair ( String path , Integer audioId , Integer videoId ) throws InterruptedException { boolean result = false ; FLVWriter writer = null ; log . debug ( "Serial file path: " + path ) ; System . out . println ( "Serial file path: " + path ) ; if ( path . endsWith ( ".ser" ) ) { File ser = new File ( path ) ; if ( ser . exists ( ) && ser . canRead ( ) ) { ser = null ; String flvPath = path . substring ( 0 , path . lastIndexOf ( ' ' ) ) ; log . debug ( "Flv file path: " + flvPath ) ; System . out . println ( "Flv file path: " + flvPath ) ; // check for .info and if it does not exist set dummy data File inf = new File ( flvPath + ".info" ) ; if ( inf . exists ( ) && inf . canRead ( ) ) { inf = null ; // create a writer writer = new FLVWriter ( true , flvPath ) ; } else { log . debug ( "Info file was not found or could not be read, using dummy data" ) ; System . err . println ( "Info file was not found or could not be read, using dummy data" ) ; // create a writer writer = new FLVWriter ( true , flvPath ) ; int acid = audioId == null ? 11 : audioId , vcid = videoId == null ? 7 : videoId ; writer . setAudioCodecId ( acid ) ; // default: speex writer . setVideoCodecId ( vcid ) ; // default: h.264 writer . setDuration ( Integer . MAX_VALUE ) ; writer . setSoundRate ( 16000 ) ; writer . setSoundSize ( 16 ) ; } } else { log . error ( "Serial file was not found or could not be read" ) ; System . err . println ( "Serial file was not found or could not be read" ) ; } } else { log . error ( "Provide the path to your .ser file" ) ; System . err . println ( "Serial file was not found or could not be read" ) ; } if ( writer != null ) { // spawn a flv finalizer Future < ? > future = writer . submit ( writer . new FLVFinalizer ( ) ) ; try { // get result / blocking future . get ( ) ; log . debug ( "File repair completed" ) ; System . out . println ( "File repair completed" ) ; result = true ; } catch ( Exception e ) { log . warn ( "Exception while finalizing: {}" , path , e ) ; } } return result ; }
Allows repair of flv files if . info and . ser files still exist .