public void render ( MultimediaObject multimediaObject , int width , int height , int seconds , File target , int quality ) throws EncoderException { File inputFile = multimediaObject . getFile ( ) ; target = target . getAbsoluteFile ( ) ; target . getParentFile ( ) . mkdirs ( ) ; try { if ( ! inputFile . canRead ( ) ) { LOG . debug ( "Failed to open input file" ) ; throw new SecurityException ( ) ; } } catch ( SecurityException e ) { LOG . debug ( "Access denied checking destination folder" + e ) ; } MultimediaInfo multimediaInfo = multimediaObject . getInfo ( ) ; int duration = ( int ) ( multimediaInfo . getDuration ( ) * .001 ) ; numberOfScreens = seconds <= duration ? 1 : 0 ; FFMPEGExecutor ffmpeg = this . locator . createExecutor ( ) ; ffmpeg . addArgument ( "-i" ) ; ffmpeg . addArgument ( inputFile . getAbsolutePath ( ) ) ; ffmpeg . addArgument ( "-f" ) ; ffmpeg . addArgument ( "image2" ) ; ffmpeg . addArgument ( "-vframes" ) ; ffmpeg . addArgument ( "1" ) ; ffmpeg . addArgument ( "-ss" ) ; ffmpeg . addArgument ( String . valueOf ( seconds ) ) ; ffmpeg . addArgument ( "-s" ) ; ffmpeg . addArgument ( String . format ( "%sx%s" , String . valueOf ( width ) , String . valueOf ( height ) ) ) ; ffmpeg . addArgument ( "-qscale" ) ; ffmpeg . addArgument ( String . valueOf ( quality ) ) ; ffmpeg . addArgument ( target . getAbsolutePath ( ) ) ; try { ffmpeg . execute ( ) ; } catch ( IOException e ) { throw new EncoderException ( e ) ; } try { RBufferedReader reader = new RBufferedReader ( new InputStreamReader ( ffmpeg . getErrorStream ( ) ) ) ; int step = 0 ; int lineNR = 0 ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { lineNR ++ ; LOG . debug ( "Input Line (" + lineNR + "): " + line ) ; // TODO: Implement additional input stream parsing } } catch ( IOException e ) { throw new EncoderException ( e ) ; } finally { ffmpeg . destroy ( ) ; } }
Generate a single screenshot from source video .