问题描述
我正在关注 ExtractMpegFramesTest 帖子,以从视频中提取PNG帧.这适用于以横向模式录制的视频,但不适用于以纵向模式录制的视频.
I am following ExtractMpegFramesTest post to extract PNG frames from video.This works fine with videos that are recorded in landscape mode but doesn't work with videos that are recorded in portrait mode.
有人知道如何使用上述链接中提供的解决方案从人像视频生成PNG帧吗?
Does anybody know how to generate PNG frames from portrait video using solution provided in above link ?
我已经用720p和1080p视频进行了测试.
I have tested this with 720p and 1080p videos.
我观察到的事物是
MediaExtractor给出720p视频的宽度和高度1280和720,而与方向无关.横向应为1280 x 720,纵向应为720 x 1280. 1080p视频中的类似情况.
MediaExtractor gives width and height 1280 and 720 of 720p video regardless of orientation. this should be 1280 x 720 in landscape and 720 x 1280 in portrait. simillar case in 1080p videos.
另一件事是,当我在invert参数的方法drawFrame中传递false时,PNG框架很好,但倒置.
Other thing is when i pass false in the Method drawFrame in invert parameter, PNG frame is fine but upside down.
有了ExtractMpegFramesTest,我得到了这个结果
With ExtractMpegFramesTest i'm getting this result
具有invert参数为true的风景视频可提供完美的图像 http://postimg.org/image/qdliypuj5/
Landscape video with invert parameter true gives perfect Imagehttp://postimg.org/image/qdliypuj5/
肖像视频会产生失真的图像 http://postimg.org/image/vfb7dwvdx/
portrait video with invert parameter true gives distorted Imagehttp://postimg.org/image/vfb7dwvdx/
带有反转参数false的肖像视频可以完美呈现颠倒的图像(根据@Peter Tran的答案输出,可以通过旋转位图来固定.) http://postimg.org/image/p7km4iimf/
portrait video with invert parameter false gives perfect upside down Image.(According to @Peter Tran's answer output can be fixed by rotating the Bitmap.)http://postimg.org/image/p7km4iimf/
推荐答案
在 ExtractMpegFramesTest 在saveFrame
的注释中,指出
// Making this even more interesting is the upside-down nature of GL, which means
// our output will look upside-down relative to what appears on screen if the
// typical GL conventions are used. (For ExtractMpegFrameTest, we avoid the issue
// by inverting the frame when we render it.)
这就是为什么您提到的drawFrame
具有布尔参数的原因.
This is why there is the boolean parameter for drawFrame
that you mentioned.
因此,听起来您想要做的就是在保存为PNG之前反转位图.这可以通过将矩阵(带有preScale)应用于位图来完成.调用bmp.copyPixelsFromBuffer
之后,您需要在saveFrame
中修改代码.
So it sounds like what you want to do is invert the bitmap before saving to PNG. This can be done by applying a Matrix (with preScale) to the Bitmap. You would need to modify the code in saveFrame
after the call to bmp.copyPixelsFromBuffer
.
有关镜像位图的信息,请参考此答案;并使用preScale(-1,1)
沿正确的轴反转图像.
Please refer to this answer for mirroring a bitmap; and use preScale(-1,1)
to invert the image on the correct axis.
这篇关于ExtractMpegFramesTest在Android中以人像模式录制的视频出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!