自定义 avi/MP4 文件编写器

发布于 2024-09-28 16:14:11 字数 451 浏览 1 评论 0原文

我正在 Windows 下从相机写入一些视频文件。
我需要未更改的数据 - 不是 MP4 的“未压缩”,即。没有 YUV,没有颜色插值 - 只有原始相机传感器字节流。

目前我正在将其直接写入磁盘并稍后重新读取以重新编码为可用的视频。但由于没有标题,我必须单独跟踪图像大小、帧速率、色彩平衡等。

我可以添加一个自定义标头,但即使实际的视频数据无法被我的应用程序以外的任何其他程序读取,使用 AVI 文件至少会给我一个相对标准的标头来存储所有相机参数,并且还意味着分辨率、长度等将显示在资源管理器中。

有没有一种简单的方法可以生成 AVI 页眉/页脚,而无需通过 directshow 或 vfw 发送所有数据?数据以> 250MB/s 的速度传入,并且我不能丢失任何帧,因此除了将每个帧转储到磁盘之外我没有时间做更多的事情。

编辑:也许 MP4 会更好我有很多关于相机配置的元数据,这些元数据不在 AVI 标准中

I am writing some video files under Windows from a camera.
I need the data unaltered - not MP4's 'uncompressed' ie. no YUV, no color interpolation - just the raw camera sensor bytestream.

At the moment I am writing this direct to disk and re-reading it later to recode into a usable video. But with no header I have to keep track of image size, frame rate, color balance etc separately.

I could add a custom header but even if the actual video data is unreadable by anything other than my app, using an AVI file would at least give me a relatively standard header to store all the camera parameters and also means that resolution, length etc would show up in explorer.

Is there an easy way of generating an AVI header/footer without sending all the data through directshow or vfw? The data is coming in at >250MB/s and I can't lose any frames so I don't have time to do much more than dump each frame to disk.

edit: Perhaps MP4 would be better I have a lot of metadata about the camera config that isn't in the AVI standard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦年海沫深 2024-10-05 16:14:11

好吧,在弄清楚什么是适合您的流的“合理”AVI 标头之后(例如,如果您使用自定义编解码器 fourcc,则任何应用程序都可能无法用它做有用的事情 - 那么为什么还要麻烦 AVI 呢?)
您可以在文件的开头编写一个预构建的 RIFF-AVI 标头。弄清楚这些值并不难。

然后,每个帧都必须包含在自己的 RIFF 块中(4 字节类型:“00db”+ 4 字节长度+您的数据)。
之后,您必须修复标头中的 num_frames 和一些长度字段。对于大于 2GB 的文件,不要忘记标头的 OpenDML 扩展名。

Well, after figuring out what 'reasonable' AVI headers would be for your stream (e.g. if you use a custom codec fourcc, no application would probably be able to do useful things with it -- so why bother with AVI?)
you could just write a prebuild RIFF-AVI header at the beginning of your file. It's not too hard to figure out the values.

Each frame then has to be enclosed in its own RIFF chunk (4 Byte type: "00db" + 4 byte length + your data).
After the fact you have to fix the num_frames and some length fields in the header. And for files >2GB don't forget the OpenDML extension for the header.

白馒头 2024-10-05 16:14:11

马丁,既然你精通OpenCV,你就不能使用cvCreateVideoWriter() 用于创建未压缩的.avi

CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)

关于 foucc 参数,文档指出:

在 Win32 下,如果在使用 avi 文件名时传递 0,它将创建一个视频编写器来创建未压缩的 avi 文件。

Martin, since you are proficient in OpenCV, couldn't you just use cvCreateVideoWriter() for creating an uncompressed .avi?

CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)

Regarding the foucc param, the documentation states:

Under Win32 if 0 is passed while using an avi filename it will create a video writer that creates an uncompressed avi file.

空宴 2024-10-05 16:14:11

听起来你确实可以从使用 opencv 中受益,它可能可以很好地为你处理很多事情。看一下它是否适合您的需求:http://opencv.willowgarage。 com/documentation/cpp/reading_and_writing_images_and_video.html#videocapture

It sounds like you could really benefit from using opencv, it could probably handle alot of this nicely for you. Take a look and see if it suits your needs: http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html#videocapture

安稳善良 2024-10-05 16:14:11

您可以使用OpenCV读写avi文件。
请参阅http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html

请注意,OpenCV 也可用于从相机抓取图像。

You can use OpenCV to read and write avi file.
see http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html

Note that OpenCV can also be used to grab images from a camera.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文