如何使用 FFmpeg 将灰度视频流编码为 MPEG-1?

发布于 2024-12-19 05:54:44 字数 111 浏览 0 评论 0原文

我有一个来自火线天文相机的灰度视频流,我想使用 FFmpeg 来压缩视频流,但它不接受 MPEG1VIDEO 编解码器的单字节像素格式。如何使用FFmpeg API将灰度视频帧转换为FFmpeg接受的帧格式?

I've got a grayscale video stream coming off a Firewire astronomy camera, I'd like to use FFmpeg to compress the video stream but it will not accept single byte pixel formats for the MPEG1VIDEO codecs. How can I use the FFmpeg API to convert grayscale video frames into a frame format accepted by FFmpeg?

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

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

发布评论

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

评论(4

酒解孤独 2024-12-26 05:54:44

MPEG-1 仅接受 YUV,因此您需要将帧转换为 YUV 格式。使用通过调用 sws_getContext() 创建的 SwsContext 结构,然后使用 sws_scale()

MPEG-1 only accepts YUV so you need to convert your frame to the YUV format. Use the SwsContext structure which you create by calling sws_getContext(), and then use sws_scale().

月亮是我掰弯的 2024-12-26 05:54:44

灰度和 YUV 的关系非常简单 - YUV 的“Y”与灰度完全相同。

将灰度转换为 YUV 的更简单方法是

参见参考以了解比例之间的转换:

相应:

Y  =      (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

Now: 
For a Grayscale image (W): 

R = W;
G = W;
B = W;

Keeping this: 

Y[i] = 0.895 * W[i] + 16. 
U[i] = 128 (fixed value)
V[i] = 128 (fxied value)

您实际上可以使用 Y[i] = W[i] 几乎相同。 128 值表示 0-256 有符号到无符号转换的缩放/移位基数中的“0”。

因此,您需要保留的就是创建另一个内存区域 Y 和 U 作为固定值,并将这些帧提供给 ffmpeg。

我不确定,但通过适当地告诉 FFMPEG,它只在内部执行此操作。您提供的 RGB 值也同样包含在内;这也不是 MPEG 原生的。

因此,请寻找 FFMPEG 的 API,它可以让您做到这一点。

奖金
请记住,在过去的美好时光里有黑白(灰度)电视机。新的彩色电视机需要与旧的电视机兼容,因此以 U 和 V 的形式添加颜色信息(有时也称为 YCbCr - 其中 Cb 和 Cr 称为色度,分别是 UV 的线性变化)此上下文)。

The Relationship of Gray scale and YUV is very simple - The "Y" of YUV is exactly same as Grayscale.

The simpler way to convert the Grayscale in to YUV is

See this reference for Conversion between the scales :

Accordingly :

Y  =      (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

Now: 
For a Grayscale image (W): 

R = W;
G = W;
B = W;

Keeping this: 

Y[i] = 0.895 * W[i] + 16. 
U[i] = 128 (fixed value)
V[i] = 128 (fxied value)

You can actually use Y[i] = W[i] that will be almost same. The 128 value represents '0' in a scaled/shifted base of 0-256 signed to unsigned conversion.

So all you need to keep is create this other memory area Y and U as the fixed value and provide this frames to ffmpeg.

I am not sure, but by appropriately telling FFMPEG, it does this inside only. The RGB values you supply are equally covered there as well; which is also not native to MPEG.

So look for FFMPEG's API which is able to let you do this.

BONUS
Remember, that in good old days there were Black and white (Gray scale) TV sets. The new color TV sets, needed to be compliant to the old ones, so color information is added in the form of U and V (sometimes it is also called YCbCr - where Cb and Cr are called chroma and are respectively linear variations of UV in this context).

灼疼热情 2024-12-26 05:54:44

如果您只使用“色调”过滤器,它就可以工作;像这样:

ffmpeg -i inputfile.ogv -vf hue=s=0 outputfile-unsat.ogv

It works if you simply use "hue" filter; like this:

ffmpeg -i inputfile.ogv -vf hue=s=0 outputfile-unsat.ogv
别靠近我心 2024-12-26 05:54:44

如果 ffmpeg 出现任何问题,您需要先下载最新版本,它将修复一些错误:

https://ffmpeg.org/download.html#build-windows

Any problem with ffmpeg then you need to download latest version first, it will be fix some thing bug:

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