如何使用 FFmpeg 将灰度视频流编码为 MPEG-1?
我有一个来自火线天文相机的灰度视频流,我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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 callingsws_getContext()
, and then usesws_scale()
.灰度和 YUV 的关系非常简单 - YUV 的“Y”与灰度完全相同。
将灰度转换为 YUV 的更简单方法是
参见此参考以了解比例之间的转换:
相应:
您实际上可以使用 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 :
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).
如果您只使用“色调”过滤器,它就可以工作;像这样:
It works if you simply use "hue" filter; like this:
如果 ffmpeg 出现任何问题,您需要先下载最新版本,它将修复一些错误:
Any problem with ffmpeg then you need to download latest version first, it will be fix some thing bug: