有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java/OpenCV如何在OpenCV中进行无损h264视频写入?

上一次我在java下与openCV中的VideoWriter进行了一些斗争。我想在*中写一个视频文件。带有h.264编解码器的mp4容器-但我看不到在openCV VideoWriter中切换比特率或质量的选项。我确实用ffmpeg作为后端构建了openCV。我只想以精确的质量值编写视频文件,作为原始输入视频。 我也有一些代码来做这项工作

import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.videoio.VideoWriter;
import org.opencv.videoio.Videoio;

public class VideoOutput
{
     private final int H264_CODEC = 33;

     private VideoWriter writer;

     private String filename;

     public VideoOutput (String filename)
     {
        writer = null;

        this.filename = filename;
    }

    public void initialize(double framesPerSecond, int height, int width) throws Exception
    {

        this.writer = new VideoWriter();

        this.writer.open(filename, H264_CODEC, framesPerSecond, new Size(width, height));

        if(!writer.isOpened())
        {
             Logging.LOGGER.severe("Could not create video output file " + filename + "\n");

             throw new Exception("Could not create video output file " + filename + "\n");
        }
    }

    public void setFrame(VideoFrame videoFrame) throws Exception
    {
         if (writer.isOpened()) 
         {
             Mat frame = ImageUtil.imageToMat(videoFrame.getFrame());

             writer.write(frame);

             frame.release();
         }
    }

我希望录像作者能给出一些选择来做这项工作,但似乎不是这样

那么,对于openCV和java下的无损h264视频编写,我是否缺少了一个选项或标志? 请帮助我-如果你已经这样做了,我真的很感激一些示例代码来完成这些事情

更新

我现在确实有一个适合我的应用程序的解决方案,因此:

String fps = Double.toString(this.config.getInputConfig().getFramesPerSecond());

Runtime.getRuntime().exec(
        new String[] {
        "C:\\ffmpeg-3.4.2-win64-static\\bin\\ffmpeg.exe",
        "-framerate",
        fps,
        "-i",
        imageOutputPath + File.separator +  "%01d.jpg",
        "-c:v",
        "libx265",
        "-crf",
        "1",
        imageOutputPath + File.separator +  "ffmpeg.mp4"
        }
    );

感谢@Gyan,他在这篇文章中给我打了正确的ffmpeg电话:

Win/ffmpeg - How to generate a video from images under ffmpeg?

问候


共 (0) 个答案