gpt4 book ai didi

JavaCV FFmpegFrameRecorder 将图像保存到视频

转载 作者:行者123 更新时间:2023-12-04 22:50:25 26 4
gpt4 key购买 nike

我对 JavaCV FFmpegFrameRecorder 的使用有点困惑。我有几个 byte[] 或 short[] 数组(取决于我的图像是 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);
}

}

但我收到了类似的错误

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fefe4511d3, pid=6432, tid=0x000000000000027c



那里有什么问题?我应该如何选择比特率?我的图像最多为 16 位 1 channel 2048*2048 像素。

谢谢!

最佳答案

当您使用事件/线程时,您应该在 JavaCV 中使用 Parallel.run() 方法。

关于JavaCV FFmpegFrameRecorder 将图像保存到视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50592993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com