package org.helioviewer.jhv.export;

import java.awt.image.BufferedImage;
import java.io.File;

import org.jcodec.api.awt.AWTSequenceEncoder8Bit;

public class JCodecExporter implements MovieExporter {

    private AWTSequenceEncoder8Bit encoder;

    @Override
    public void open(String path, int w, int h, int fps) throws Exception {
        encoder = AWTSequenceEncoder8Bit.createSequenceEncoder8Bit(new File(path), fps);
        encoder.getEncoder().setKeyInterval(fps);
    }

    @Override
    public void encode(BufferedImage image) throws Exception {
        encoder.encodeImage(image);
    }

    @Override
    public void close() throws Exception {
        encoder.finish();
    }

}

@@ -104,45 +104,215 @@
 org.
-jcodec.api.awt.AWTSequenceEncoder8Bit
+helioviewer.jhv.base.FileUtils;%0Aimport org.jcodec.api.awt.AWTSequenceEncoder8Bit;%0Aimport org.jcodec.containers.mp4.MP4Util;%0Aimport org.jcodec.containers.mp4.boxes.MovieBox;%0Aimport org.jcodec.movtool.Flattern
 ;%0A%0Ap
@@ -409,16 +409,41 @@
 encoder;
+%0A    private String path;
 %0A%0A    @O
@@ -518,32 +518,58 @@
 ows Exception %7B%0A
+        this.path = path;%0A
         encoder 
@@ -867,32 +867,32 @@
 ows Exception %7B%0A
-
         encoder.
@@ -901,16 +901,392 @@
 nish();%0A
+        prepareStream();%0A    %7D%0A%0A    private void prepareStream() throws Exception %7B%0A        File orig = new File(path);%0A        MovieBox movie = MP4Util.createRefMovieFromFile(orig);%0A%0A        File optim = new File(path + %22_optim%22);%0A        new Flattern().flattern(movie, optim);%0A        FileUtils.copy(optim, orig); // renameTo doesn't work on Windows%0A        optim.delete();%0A
     %7D%0A%0A%7D

Prepare for streaming