Java video automatic recoding does not working as expected

1

I'm using java monte screen recorder jar file in order to record my screen while executing java code,

this is my code:

import static org.monte.media.FormatKeys.EncodingKey;
import static org.monte.media.FormatKeys.FrameRateKey;
import static org.monte.media.FormatKeys.KeyFrameIntervalKey;
import static org.monte.media.FormatKeys.MIME_AVI;
import static org.monte.media.FormatKeys.MediaTypeKey;
import static org.monte.media.FormatKeys.MimeTypeKey;
import static org.monte.media.VideoFormatKeys.CompressorNameKey;
import static org.monte.media.VideoFormatKeys.DepthKey;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE;
import static org.monte.media.VideoFormatKeys.QualityKey;

import java.awt.AWTException;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.monte.media.Format;
import org.monte.media.Registry;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;

public class MonteRecorder extends ScreenRecorder {

    private File movieFolder;
    private String name;

    public MonteRecorder(String name, File movieFolder) throws IOException, AWTException {

        super(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration(),

                 new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
                    new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                            CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24, FrameRateKey,
                            Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
                    new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),
                    null);
                /* output format for audio - null == no audio */
            this.movieFolder = movieFolder;
        this.name = name;
    }

    @Override
    protected File createMovieFile(Format fileFormat) throws IOException {
        if (!movieFolder.exists()) {
            movieFolder.mkdirs();
        } else if (!movieFolder.isDirectory()) {
            throw new IOException("\"" + movieFolder + "\" is not a directory.");
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 'at' HH.mm.ss");

        File f = new File(movieFolder, //
                "Scenario - " + name + " - " +dateFormat.format(new Date()) + "."
                        + Registry.getInstance().getExtension(fileFormat));
        return f;
    }



}

file type is .avi and it's created successfully. but when trying to open it using VLC media player, I'm getting the following error message:

This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt. 0xc00d36c4

error message

note: this code worked successfully before some weeks, but I did not tested it constantly.

in order to fix it I tried to change format parameters, to MP4 or quicktime (.mov) file , it's all failed to be opened.

if someone know another maven library that can record the screen it will be helpful(with code example).

java
screen-recording
asked on Stack Overflow Jun 10, 2019 by Ali Taha • edited Jun 11, 2019 by Ali Taha

1 Answer

0

the problem occurred because o does note invoked stop method at the end of screen recording. before is started the screen recording by using the following code:

ScreenRecorder screenRecorder = new MonteRecorder(videoName, new File(path));
this.screenRecorder.start();

to fix the problem I should add

this.screenRecorder.stop();

at the end of the scenario.

after adding it, created video start as expected using VLC media player.

answered on Stack Overflow Jun 11, 2019 by Ali Taha

User contributions licensed under CC BY-SA 3.0