使用 xuggler 从一组图像创建视频
我一直在到处寻找解决方案!在本网站和其他网站上。 我发现了一些有趣的事情,但它们并没有解决我的问题。我会解释一下。
我有一个视频,我用 xuggler 对每一帧进行分级。当我获得所有帧时,我使用颜色算法编辑所有帧。另外,我将音频存储在 mp3 文件中。
现在我需要从所有帧创建一个视频,该视频当然应该具有与帧速率 e 持续时间相同的特征。之后我必须合并音频。
我已经完成了第一部分,但我不知道如何创建具有相同特征的视频。我正在关注此代码:
但它拍摄快照并使用一个奇怪的循环:
for (int index = 0; index < SECONDS_TO_RUN_FOR * FRAME_RATE; index++)
我不知道如何设置正确的特征。这应该很容易,因为我知道关于视频的一切!大小、帧速率和帧数。
我的代码:
public static void main(String[] args) throws IOException {
final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,
720, 304);
long nextFrameTime = 0;
final long frameRate =25/1000;
long startTime = System.nanoTime();
while (indexVideo<1597) {
BufferedImage videoImage = null;
try {
videoImage = getVideoImage();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
writer.encodeVideo(0, videoImage,nextFrameTime,
TimeUnit.MILLISECONDS);
nextFrameTime += frameRate;
}
writer.close();
}
private static BufferedImage getVideoImage() throws IOException, AWTException {
File imgLoc = new File("D:/Gianfranco/Sample/"+indexVideo+".png");
BufferedImage img;
img = ImageIO.read(imgLoc);
System.out.println(imgLoc.getName());
indexVideo++;
return img;
}
有人能帮我吗?
I have been looking for a solution everywhere! On this website and on others.
I have found some interesting things, but they didn't solve my problem. I will explain it.
I have one video, I grad each frame of it with xuggler. When I get all the frames I edit all of them with a color algorithm. Also, I store the audio in an mp3 file.
Now I need to create a video from all the frames, this video, of course, should have the same characteristics as frame rate e duration. After that I have to merge the audio.
I have done the first part, but I don't know how to create a video with the same characteristics. I am following this code:
http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html
Can't encode video with Xuggler
But it takes the snapshot and it uses a strange loop:
for (int index = 0; index < SECONDS_TO_RUN_FOR * FRAME_RATE; index++)
I can't figure out how to set the right characteristic. It should be easy because I know everything about the video! size, frame rate and number of frame.
My code:
public static void main(String[] args) throws IOException {
final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,
720, 304);
long nextFrameTime = 0;
final long frameRate =25/1000;
long startTime = System.nanoTime();
while (indexVideo<1597) {
BufferedImage videoImage = null;
try {
videoImage = getVideoImage();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
writer.encodeVideo(0, videoImage,nextFrameTime,
TimeUnit.MILLISECONDS);
nextFrameTime += frameRate;
}
writer.close();
}
private static BufferedImage getVideoImage() throws IOException, AWTException {
File imgLoc = new File("D:/Gianfranco/Sample/"+indexVideo+".png");
BufferedImage img;
img = ImageIO.read(imgLoc);
System.out.println(imgLoc.getName());
indexVideo++;
return img;
}
Ca anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
快速浏览一下您的代码,我发现您没有设置帧速率。我不知道您使用的是哪个版本的 xuggler,但对我来说,我在添加视频流时设置了帧速率:
现在另一种(可能更合适)的方法是通过打开原始视频来创建 IMediaWriter。
或者,您可以通过获取第一个容器,然后获取格式来实现。我只对流数据而不是存档数据执行此操作。
A quick glance at your code shows me that you aren't setting the frame rate. I don't know what version of xuggler you are using, but for me I set the frame rate when adding video stream:
Now another (probably more appropriate) approach would be to create your IMediaWriter by opening your original video.
Or maybe you make it by grabbing the container of the first, then grabbing the format. I've only done this for streaming data and not archived data.
试试这个帧率:
try this for frame rate: