Search in sources :

Example 6 with FFMpegProgressBarListener

use of com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener in project screenbird by adamhub.

the class FileUtilTest method testCompressVideoAvi.

/**
     * Test of compressVideoAvi method, of class FileUtil.
     */
@Test
public void testCompressVideoAvi() {
    System.out.println("compressVideoAvi");
    File source = SAMPLE_AVI;
    File target = generateTempFile(".mp4");
    File audioFile = SAMPLE_WAV;
    Integer bitrate = 1040000;
    FFMpegProgressBarListener ffmpegListener = null;
    FileUtil.compressVideoAvi(source, target, audioFile, bitrate, ffmpegListener);
    Integer sampleDuration = FileUtil.getVideoDuration(SAMPLE_AVI.getAbsolutePath());
    Integer resultDuration = FileUtil.getVideoDuration(target.getAbsolutePath());
    assert Math.abs(sampleDuration - resultDuration) < 10 : "Diff: " + Math.abs(sampleDuration - resultDuration);
}
Also used : File(java.io.File) FFMpegProgressBarListener(com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener) Test(org.junit.Test)

Example 7 with FFMpegProgressBarListener

use of com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener in project screenbird by adamhub.

the class RecorderPanel method prepareVideo.

/**
     * Processes all images captured to create a Quicktime movie.
     */
public void prepareVideo() {
    this.showUploadForm();
    this.setEnableUploadForm(false);
    this.btnUpload.setEnabled(true);
    this.showUploadMessage("Processing Video...", MESSAGE_INFO);
    Boolean movieCreated = false;
    JFrame jf = (JFrame) RecorderPanel.this.getTopLevelAncestor();
    jf.setTitle("Screen Recorder - Processing Video...");
    // Place in encoding state
    this.isEncoding = true;
    this.pbEncoding.setIndeterminate(true);
    this.pbEncoding.setStringPainted(false);
    this.showUploadMessage("Rendering Video...", MESSAGE_INFO);
    // Converts screen shots to video file
    try {
        movieCreated = recorder.compileVideo();
    } catch (Exception e) {
        log(e);
    }
    // Converts audio clips to single audio file
    if (recorder.hasAudioToCompile()) {
        this.showUploadMessage("Rendering Audio...", MESSAGE_INFO);
        recorder.compileAudio();
        while (recorder.isWaitingForAudio()) {
            // we need to wait for the audio file.
            TimeUtil.skipToMyLou(0.1);
        }
    }
    // Check for ffmpeg executable on the computer
    // Download if not yet available
    DownloadThread ffmpegDownload = DownloadManager.getInstance().getDownload(Settings.getFFMpegExecutable());
    if (!ffmpegDownload.checkStatus(DownloadStatus.FINISHED)) {
        this.pbEncoding.setIndeterminate(true);
        this.pbEncoding.setStringPainted(false);
        this.showUploadMessage("Preparing Files", MESSAGE_INFO);
    }
    // Wait for ffmpeg download to finish
    while (!ffmpegDownload.checkStatus(DownloadStatus.FINISHED)) {
        TimeUtil.skipToMyLouMS(500L);
        log("Current Status :" + ffmpegDownload.getStatus());
    }
    this.pbEncoding.setIndeterminate(false);
    this.pbEncoding.setStringPainted(true);
    jf.setTitle("Screen Recorder - Done.");
    // Encode video/audio
    if (movieCreated) {
        try {
            int numOfTasks = 1;
            // Assign number of tasks via the operating system of the client
            if (recorder.hasPreviousCompiledVideo()) {
                numOfTasks = (MediaUtil.osIsMac() || MediaUtil.osIsUnix()) ? 5 : 4;
            }
            if (this.scrubManager.isVideoEdited()) {
                numOfTasks += (4 + this.scrubManager.getScrubs().size());
            }
            // Set up encoding progress bar
            this.pbEncodingListener = new FFMpegProgressBarListener(pbEncoding, numOfTasks, FFMpegProgressBarListener.FFMPEG);
            this.showUploadMessage("Encoding Video...", MESSAGE_INFO);
            // Encode the video
            this.recordingOutput = FileUtil.encodeVideoMp4(recorder.getFile(), recorder.getOffset(), recorder.getBitRateCompresion(), this.pbEncodingListener);
            // Append to previously rendered video if continuing
            if (recorder.hasPreviousCompiledVideo()) {
                this.recordingOutput = FileUtil.mergeVideoMp4(recorder.getPrevVideoFileName(), this.recordingOutput, this.pbEncodingListener);
            }
            this.recorder.setResultVideoPath(this.recordingOutput);
            log("Compiled Video Location: " + this.recordingOutput);
        } catch (FileNotFoundException ex) {
            log(ex);
        } catch (IOException ex) {
            log(ex);
        } catch (UnsupportedBitRateCompression e) {
            log(e);
        }
        // Disable scrub feature for resuming previous recordings
        if (this.scrubManager != null && this.scrubManager.isVideoEdited() && !this.recorder.hasPreviousCompiledVideo()) {
            // Give it a few seconds for the video to finish encoding
            TimeUtil.skipToMyLou(3);
            this.scrubManager.scrubVideo(this.recordingOutput, this.pbEncodingListener);
        }
        this.setEnableUploadForm(true);
        // Mark applet as a non-encoding state
        this.isEncoding = false;
        // Start uploading copy if auto-upload is checked
        if (this.chkAutoUpload.isSelected()) {
            // Disable checkbox since is useless after encoding is done
            this.chkAutoUpload.setEnabled(false);
            this.btnUpload.setEnabled(false);
            FileUtil.removeMarker(UPLOAD_ON_ENCODE);
            // Wait a few seconds for client's system to catch up
            TimeUtil.skipToMyLou(5);
            uploadCopy();
        }
        // Set progress bar to 100%
        this.pbEncoding.setValue(pbEncoding.getMaximum());
        this.showUploadMessage("Ready for upload", MESSAGE_OK);
    } else {
        this.showRecorderMessage("Error processing video.", MESSAGE_ERROR);
        log("Movie not compiled properly.");
    }
}
Also used : DownloadThread(com.bixly.pastevid.download.DownloadThread) JFrame(javax.swing.JFrame) FileNotFoundException(java.io.FileNotFoundException) UnsupportedBitRateCompression(com.bixly.pastevid.recorders.UnsupportedBitRateCompression) IOException(java.io.IOException) MissingResourceException(java.util.MissingResourceException) FileNotFoundException(java.io.FileNotFoundException) LineUnavailableException(javax.sound.sampled.LineUnavailableException) IOException(java.io.IOException) FFMpegProgressBarListener(com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener)

Example 8 with FFMpegProgressBarListener

use of com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener in project screenbird by adamhub.

the class FileUtilTest method testConvertMp4ToMpg.

/**
     * Test of convertMp4ToMpg method, of class FileUtil.
     */
@Test
public void testConvertMp4ToMpg() {
    System.out.println("convertMp4ToMpg");
    assert SAMPLE_MP4.exists() : "Please provide a sample MP4 vidoe for testing";
    assert FFMPEG_BIN.exists() : "FFMpeg is needed for this test";
    FFMpegProgressBarListener ffmpegListener = null;
    FileUtil.convertMp4ToMpg(SAMPLE_MP4, ffmpegListener);
    Integer sampleDuration = FileUtil.getVideoDuration(SAMPLE_MP4.getAbsolutePath());
    Integer resultDuration = FileUtil.getVideoDuration(SAMPLE_MPG.getAbsolutePath());
    assertTrue(Math.abs(sampleDuration - resultDuration) < 10);
}
Also used : FFMpegProgressBarListener(com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener) Test(org.junit.Test)

Example 9 with FFMpegProgressBarListener

use of com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener in project screenbird by adamhub.

the class FileUtilTest method testMergeVideoMpgTo.

/**
     * Test of mergeVideoMpgTo method, of class FileUtil.
     */
@Test
public void testMergeVideoMpgTo() {
    System.out.println("mergeVideoMpgTo");
    assert SAMPLE_MP4.exists() : "Please provide a sample MP4 vidoe for testing";
    assert FFMPEG_BIN.exists() : "FFMpeg is needed for this test";
    assert HANBRAKE_BIN.exists() : "Handbrake is needed for this test";
    File sourceVideo1 = FileUtil.convertMp4ToMpg(SAMPLE_MP4, null);
    File sourceVideo2 = FileUtil.convertMp4ToMpg(SAMPLE_MP4, null);
    //Create temp file to store merged video
    File targetVideo = generateTempFile("mpg");
    FFMpegProgressBarListener ffmpegListener = null;
    //Merge video
    File mergedVideoMPG = FileUtil.mergeVideoMpgTo(sourceVideo1, sourceVideo2, targetVideo, ffmpegListener);
    //Convert merged video back to MP4 video format
    File mergedVideoMP4 = FileUtil.convertMpgToMp4(targetVideo, ffmpegListener);
    Integer sourceVideo1Duration = FileUtil.getVideoDuration(sourceVideo1.getAbsolutePath());
    Integer sourceVideo2Duration = FileUtil.getVideoDuration(sourceVideo2.getAbsolutePath());
    Integer mergedVideoDuration = FileUtil.getVideoDuration(mergedVideoMP4.getAbsolutePath());
    //Confirm merged video is larger than both the source videos in size and duration
    assert sourceVideo1Duration < mergedVideoDuration : "SV1: " + sourceVideo1Duration + " MV: " + mergedVideoDuration;
    assertTrue(sourceVideo1.length() < mergedVideoMPG.length());
    assertTrue(sourceVideo2Duration < mergedVideoDuration);
    assertTrue(sourceVideo2.length() < mergedVideoMPG.length());
    sourceVideo1.delete();
    sourceVideo2.delete();
    targetVideo.delete();
    mergedVideoMP4.delete();
    mergedVideoMPG.delete();
}
Also used : File(java.io.File) FFMpegProgressBarListener(com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener) Test(org.junit.Test)

Example 10 with FFMpegProgressBarListener

use of com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener in project screenbird by adamhub.

the class FileUtilTest method testMergeVideoMp4.

//FFMpeg Encoding Tests 
/**
     * Test of mergeVideoMp4 method, of class FileUtil.
     */
@Test
public void testMergeVideoMp4() throws Exception {
    System.out.println("mergeVideoMp4");
    assert SAMPLE_MP4.exists() : "Please provide a sample MP4 vidoe for testing";
    assert FFMPEG_BIN.exists() : "FFMpeg is needed for this test";
    String prevFilePath = SAMPLE_MP4.getAbsolutePath();
    String newFilePath = SAMPLE_MP4.getAbsolutePath();
    FFMpegProgressBarListener ffmpegListener = null;
    Integer prevVideoDuration = FileUtil.getVideoDuration(prevFilePath);
    String result = FileUtil.mergeVideoMp4(prevFilePath, newFilePath, ffmpegListener);
    Integer currVideoDuration = FileUtil.getVideoDuration(result);
    assertTrue(prevVideoDuration < currVideoDuration);
    new File(result).delete();
}
Also used : File(java.io.File) FFMpegProgressBarListener(com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener) Test(org.junit.Test)

Aggregations

FFMpegProgressBarListener (com.bixly.pastevid.screencap.components.progressbar.FFMpegProgressBarListener)11 Test (org.junit.Test)9 File (java.io.File)5 DownloadThread (com.bixly.pastevid.download.DownloadThread)1 UnsupportedBitRateCompression (com.bixly.pastevid.recorders.UnsupportedBitRateCompression)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MissingResourceException (java.util.MissingResourceException)1 LineUnavailableException (javax.sound.sampled.LineUnavailableException)1 JFrame (javax.swing.JFrame)1 JProgressBar (javax.swing.JProgressBar)1 Ignore (org.junit.Ignore)1