JavaCV FFmpegFrameRecorder将图像保存到视频

JavaCV FFmpegFrameRecorder将图像保存到视频,java,ffmpeg,javacv,video-recording,javacpp,Java,Ffmpeg,Javacv,Video Recording,Javacpp,我对JavaCV FFmpegFrameRecorder的使用感到有点困惑。我有几个字节[]或短[]数组(取决于我的图像是8位还是16位),如果我有几个图像的相关数据。现在,我的想法是使用JavaCPP将每个图像发送到ffmpeg,这样它就可以按照我希望的帧速率从这个集合中创建一个静音视频。到目前为止,我有: package ffmpeg; import java.awt.EventQueue; import java.io.File; import java.nio.Buffer; impo

我对JavaCV FFmpegFrameRecorder的使用感到有点困惑。我有几个字节[]或短[]数组(取决于我的图像是8位还是16位),如果我有几个图像的相关数据。现在,我的想法是使用JavaCPP将每个图像发送到ffmpeg,这样它就可以按照我希望的帧速率从这个集合中创建一个静音视频。到目前为止,我有:

package ffmpeg;

import java.awt.EventQueue;
import java.io.File;
import java.nio.Buffer;
import java.nio.ByteBuffer;

import javax.swing.JFrame;

public class rwa {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    rwa window = new rwa();
                    window.frame.setVisible(true);

                    Frame myframe = new Frame();
                    myframe .imageHeight = 100;
                    myframe .imageWidth = 200;
                    myframe .imageChannels = 1;
                    myframe .imageDepth = 8;

                    byte[] myimage = new byte[20000];

                    //all black
                    for (int j = 0; j<myimage.length; j++){
                        myimage[j]=-128;
                    }

                    File dest = new File("C:\\out.mp4");
                    FFmpegFrameRecorder record = new FFmpegFrameRecorder(dest, 0);
                    //FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(dest);
                    record.setFrameRate(0.04);
                    record.setVideoCodec(13);
                    record.setFormat("mp4");
                    record.setPixelFormat(0);
                    record.setImageHeight(100);
                    record.setImageWidth(200);
                    record.setVideoBitrate(1000000);

                    record.start();
                    for (int i=0; i<100; i++){

                        if (myimage.length*(1+i)<20000) {
                         //this is just for debugging it. I'm creating a different image each frame to see if it works. In practice, I will read in each step the propper image
                        for (int j = myimage.length*i; j<myimage.length*(i+1); j++){
                            myimage[j]=127;
                        }
                      }

                        Buffer[] buf = {ByteBuffer.wrap(myimage)};

                        myframe.image = buf;
                        record.recordImage(200, 100, 8, 1, 0, 0, ByteBuffer.wrap(myimage));
                        //record.record(myframe);
                    }
                    record.stop();
                    record.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public rwa() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
包ffmpeg;
导入java.awt.EventQueue;
导入java.io.File;
导入java.nio.Buffer;
导入java.nio.ByteBuffer;
导入javax.swing.JFrame;
公共类rwa{
私有JFrame;
/**
*启动应用程序。
*/
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
rwa窗口=新rwa();
window.frame.setVisible(true);
帧myframe=新帧();
myframe.imageHeight=100;
myframe.imageWidth=200;
myframe.imageChannels=1;
myframe.imageDepth=8;
字节[]myimage=新字节[20000];
//全黑

对于(int j=0;j当您使用事件/线程时,您应该在JavaCV中使用Parallel.run()方法。

您需要提供大于0的
跨距
。。。