2

Right now I am displaying a live stream on a Surface using the vitamio librairy.

I wish to record it in order to watch it later as the feed comes from a drone.

Right now I am periodically saving a series of bitmaps using jcodec :

 SequenceEncoder enc = new SequenceEncoder(new File("filename"));
// GOP size will be supported in 0.2
// enc.getEncoder().setKeyInterval(25);
for(...) {
    BufferedImage image = ... // Obtain an image to encode
    enc.encodeImage(image);
}
enc.finish();

My problems are :

  • The h264 output from jcodec is corrupted (there is a lot of color patches on the frames)
  • I can't record at a very high framerate (I'd like 30fps).

Moreover I still need to find a way to mux it.. I looked into Mp4Parser without much succes.

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109

1 Answers1

1

Why not to use data input stream:

DataInputStream in = new DataInputStream (recording.getInputStream());
FileOutputStream videoFile = new FileOutputStream(targetFile);
int len;
byte buffer[] = new byte[8192];

while((len = in.read(buffer)) != -1) {
    videoFile.write(buffer, 0, len);
}

videoFile.close();

Then, you can play the video from file.

m.aibin
  • 3,528
  • 4
  • 28
  • 47
  • This solution worked perfectly. I used URLConnection.getInputStream() to get the video feed. Moreover anyone who wishes to do this must know that network operations cannot be performed in the main thread. – Jules Simon Jan 11 '16 at 18:57
  • Hi All, I am trying recording live video from IP camera. I am able to save the images (using http protocal) and showing the live stream (using vlcj lib). But I am not able to record video, please provide your code, it will helpful for me. – Kona Suresh Jun 01 '18 at 08:46
  • we will get the inputstream from the this line "DataInputStream in = new DataInputStream (recording.getInputStream());" And we read from that, it is onetime task correct. So how the entire video will be getting here. – Kona Suresh Jun 01 '18 at 09:14