0

I am using jcodec library for converting a series of images to video, along with the transitions / animation like fade / flip and so on...

While this conversion process, I use the below function of SequenceEncoder class for each of the image.

 public void encodeNativeFrame(Picture pic) throws IOException {
        if (toEncode == null) {
            toEncode = Picture.create(pic.getWidth(), pic.getHeight(), encoder.getSupportedColorSpaces()[0]);
        }

        // Perform conversion
        transform.transform(pic, toEncode);

        // Encode image into H.264 frame, the result is stored in '_out' buffer
        _out.clear();
        ByteBuffer result = encoder.encodeFrame(toEncode, _out);

        // Based on the frame above form correct MP4 packet
        spsList.clear();
        ppsList.clear();
        H264Utils.wipePS(result, spsList, ppsList);
        H264Utils.encodeMOVPacket(result);

        // Add packet to video track
        outTrack.addFrame(new MP4Packet(result, frameNo * 1, (int)FPS, 1, frameNo, true, null, frameNo * 1, 0));
        frameNo++;
        result = null;
    }

Each of the frame, takes a very long time in the process (about a minute)

Especially, the following statement takes very long time -

ByteBuffer result = encoder.encodeFrame(toEncode, _out);

Converting even the series of 4 images to video with transition / animation takes at least 7 minutes.

Need suggestions to quicken this.

Narendra Singh
  • 3,990
  • 5
  • 37
  • 78

1 Answers1

1

For more optimal encoding of static images (when transitions / animation already ended) you can create one long frame for each image. You can set FPS=1 and duration to 1 for 1 second frame with 1 image.

outTrack.addFrame(new MP4Packet(result, frameNo, 1, 1, frameNo, true, null, frameNo, 0));

Also you should create track with different timescale

muxer.addTrack(TrackType.VIDEO, 1);
gildor
  • 1,789
  • 14
  • 19
  • But, as I mentioned ---- ByteBuffer result = encoder.encodeFrame(toEncode, _out); -----is the actual culprit, which is taking a lot of time. So, I need some way to minimize its time consumption – Narendra Singh May 15 '15 at 11:32
  • Yes, correct. Encoding is heaviest operation. My idea is reduce count of frames which should be encoded. You can encode single frame and use it for several seconds of video (not 30 frames per second, but 1 per second or even 1 for 10-20-30 seconds if it's possible for your video). – gildor May 15 '15 at 15:21