如何选择全帧(未压缩)作为VideoWriter的编解码器 [英] How to choose Full Frames (Uncompressed) as codec for VideoWriter

查看:818
本文介绍了如何选择全帧(未压缩)作为VideoWriter的编解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将设备中未压缩的帧存储为视频,但我需要知道如何选择全帧(未压缩)"作为VideoWriter的编解码器(在emgu中也称为openCV).

i want to store uncompressed frames from a device as a video, but i need to know how to choose " Full Frames (Uncompressed) " as a codec for the VideoWriter (in emgu aka openCV).

当我通过-1时,我可以从下拉菜单中选择它

Iam able to choose it from the dropdown menu when iam passing -1 like this

VideoWriter myVideoWriter = new VideoWriter ("myVieoColor.avi", -1 , 15, videoSize, true);

但是我想自动选择全帧(未压缩)"编解码器. 例如,我知道我可以通过

But i want to choose the Full Frames (Uncompressed) codec automatically. For example i know i can choose the Lagarith Lossless Video Codec by

VideoWriter myVideoWriter = new VideoWriter ("myVieoColor.avi", Emgu.CV.VideoWriter.Fourcc('L','A','G','S') , 15, videoSize, true);

但是我无法确定我需要使用哪个fourcc.

but iam not able to figure out which fourcc i need to use.

也许有人可以帮助我

推荐答案

如果在打开此编解码器选择对话框时闯入调试器,我们可以看到这是

If we break into debugger when this codec selection dialog box is open, we can see that it's the result of this call to AVISaveOptions(...). So, one way to find out what you picked would be to set a breakpoint on say line 799 and inspect the contents of fourcc.

但是,还有更简单的方法:

However, there is even simpler way:

  1. 创建只有一个黑框的虚拟视频 foo.avi ,然后使用GUI选择编解码器.
  2. 使用cv::VideoCapture打开 foo.avi .
  3. cv::VideoCapture实例获取CAP_PROP_FOURCC.
  4. 解码并打印.
  5. [可选]创建仅具有1个黑框的虚拟视频 bar.avi ,并使用您在步骤3中确定的FOURCC代码.比较 foo.avi bar.avi 来验证它们是否相同.
  1. Create a dummy video foo.avi with just 1 black frame, selecting the codec using the GUI.
  2. Open foo.avi using cv::VideoCapture.
  3. Get the CAP_PROP_FOURCC from the cv::VideoCapture instance.
  4. Decode and print it.
  5. [Optional] Create a dummy video bar.avi with just 1 black frame, and use the FOURCC code you determined in step 3. Compare foo.avi and bar.avi to verify they are the same.

对不起,我没有使用C#/EmguCV,因此无法为您提供确切的示例,但是以下内容很容易移植.

Sorry, I don't use C#/EmguCV, so I can't provide you an exact example, but the following should be easy enough to port.

#include <opencv2/opencv.hpp>
#include <iostream>

int main()
{
    {
        cv::VideoWriter outputVideo;
        outputVideo.open("foo.avi", -1, 25.0, cv::Size(640, 480), true);

        cv::Mat frame(480, 640, CV_8UC3);
        outputVideo.write(frame);
    }

    cv::VideoCapture inputVideo("foo.avi");
    int fourcc = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC));

    char FOURCC_STR[] = {
        (char)(fourcc & 0XFF)
        , (char)((fourcc & 0XFF00) >> 8)
        , (char)((fourcc & 0XFF0000) >> 16)
        , (char)((fourcc & 0XFF000000) >> 24)
        , 0
    };
    std::cout << "FOURCC is '" << FOURCC_STR << "'\n";

    return 0;
}

控制台输出:

FOURCC is 'DIB '

Python示例

import cv2
import numpy as np
import struct

outputVideo = cv2.VideoWriter()
outputVideo.open("foo.avi", -1, 25, (640,480), True)

frame = np.zeros((480,640,3), dtype=np.uint8)
outputVideo.write(frame)
outputVideo.release()

inputVideo = cv2.VideoCapture("foo.avi")
fourcc = int(inputVideo.get(cv2.cv.CV_CAP_PROP_FOURCC))

print "FOURCC is '%s'" % struct.pack("<I", fourcc)

控制台输出:

FOURCC is 'DIB '

这篇关于如何选择全帧(未压缩)作为VideoWriter的编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆