You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When recording starts, it is taking almost 100 % CPU usage.Is there a way to reduce it? I have optimized my recording loop, but still no luck, Also I have added a support for audio recording as well.
Please find the code below:
public class ScreenRecordingExample1 {
private static final double FRAME_RATE = 24;
private static final int SECONDS_TO_RUN_FOR = 10;
private static final String outputFilename = "e:/mydesktop122112015.mov";
private static Dimension screenBounds;
private static IMediaWriter writer = null;
private static int VIDEO_WIDTH = 0;
private static int VIDEO_HEIGHT = 0;
private static YouTube youtube;
private static final String SAMPLE_VIDEO_FILENAME = "a.mov";
private static final String VIDEO_FILE_FORMAT = "video/*";
private static boolean videoRecord = true;
//http://forums.winamp.com/showthread.php?t=364617
public static void main(String[] args) {
screenBounds = Toolkit.getDefaultToolkit().getScreenSize();
screenBounds.width = 820; // avi format will work with these resolution
screenBounds.height = 718; // avi format will work with these resolution
VIDEO_WIDTH = screenBounds.width;
VIDEO_HEIGHT = screenBounds.height;
// let's make a IMediaWriter to write the file.
writer = ToolFactory.makeWriter(outputFilename);
MediaListener ml = new MediaListener(1,0);
writer.addListener(ml);
// We tell it we're going to add one video stream, with id 0,
// at position 0, and that it will have a fixed frame rate of FRAME_RATE.
writer.open();
writer.addVideoStream(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
//writer.addVideoStream(0, 0, screenBounds.width, screenBounds.height);
writer.addAudioStream(1, 0, 2, 8000);
AudioThread at = new AudioThread();
at.start();
long startTime = System.nanoTime();
for (int index = 0; index < SECONDS_TO_RUN_FOR * FRAME_RATE; index++) {
//while(videoRecord) {
BufferedImage screen = getDesktopScreenshot();
BufferedImage bgrScreen = convertToType(screen,BufferedImage.TYPE_3BYTE_BGR);
writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
// sleep for frame rate milliseconds
try {
Thread.sleep((long) (1000 / FRAME_RATE));
} catch (InterruptedException e) {
}
Hello Clarke,
When recording starts, it is taking almost 100 % CPU usage.Is there a way to reduce it? I have optimized my recording loop, but still no luck, Also I have added a support for audio recording as well.
Please find the code below:
public class ScreenRecordingExample1 {
}
at.stopRecord();
try {
at.join();
at.interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
writer.close();
}
private static class AudioThread extends Thread {
// IAudioSamples samples = event.getAudioSamples();
if (audioResampler == null) {
audioResampler = IAudioResampler.make(2, samples.getChannels(), 44100, samples.getSampleRate());
}
if (event.getAudioSamples().getNumSamples() > 0) {
IAudioSamples out = IAudioSamples.make(samples.getNumSamples(), samples.getChannels());
audioResampler.resample(out, samples, samples.getNumSamples());
// streamCoder.setCodec(ICodec.ID.CODEC_ID_H264);
streamCoder.setWidth(VIDEO_WIDTH);
streamCoder.setHeight(VIDEO_HEIGHT);
}
super.onAddStream(event);
}
Please give me some idea or clue so that I can work on it.
Thank you
Unni
The text was updated successfully, but these errors were encountered: