gpt4 book ai didi

JavaCV FFmpegFrameFilter 不适用于 fps 过滤器

转载 作者:行者123 更新时间:2023-12-01 18:51:11 30 4
gpt4 key购买 nike

我正在尝试使用 JavaCV 的 FFmpegFrameFilter 和 -grabber 更改视频的帧速率。但是,filter.pull(); 始终返回 null。

我基本上尝试了拉动和插入框架的所有组合,但似乎没有任何效果。

这是我的代码:


FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new File("input.mp4"));
grabber.start();

FFmpegFrameFilter filter = new FFmpegFrameFilter("fps=fps=60", null, grabber.getImageWidth(), grabber.getImageHeight(), 0);
filter.setVideoInputs(1);
filter.start();

Java2DFrameConverter converter = new Java2DFrameConverter();

for (int i = 0; i < 10; i++) {
//Push the newly grabbed frame to the filter.
Frame frame = grabber.grabImage();
int n = frame.image.length - 1;
filter.pushImage(n > 0 ? n : 0, frame.imageWidth, frame.imageHeight, frame.imageDepth, frame.imageChannels, frame.imageStride, grabber.getPixelFormat(), frame.image);

//Pull the frame from the filter, convert it to a BufferedImage, and save it.
//This line throws an IllegalArgumentException, stating the image is null.
ImageIO.write(converter.convert(filter.pullImage()), "jpg", new File(outputPath + i + ".jpg"));
}

我最好的猜测是我给了 pushImage(...) 错误的参数,因为我不确定第一个参数 n 应该是什么。

最佳答案

我找到了一种避免过滤器的方法。

class GrabWithDifferentFrameRate {

private Frame lastFrame;
private FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(input);

// Basically converts a frameNumber based on the desiredFrameRate
// to one fitting for the grabbers frameRate and returns the frame at that frameNumber
public Frame grabAt(int frameNumber, int desiredFrameRate) {
double stepSize = desiredFrameRate / grabber.getFrameRate();
double adjustedFrameNumber = calculateAdjustedFrameNumber(stepSize);

Frame frame = lastFrame;
while ((adjustedFrameNumber <= frameNumber && frameNumber / stepSize < grabber.getLengthInFrames())) {
frame = grabber.grabImage();
adjustedFrameNumber = calculateAdjustedFrameNumber(stepSize);
}

return frame;
}

private double calculateAdjustedFrameNumber(double stepSize) {
return grabber.getFrameNumber() * stepSize;
}
}

关于JavaCV FFmpegFrameFilter 不适用于 fps 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59737017/

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