问题
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.
Does anybody know how to generate PNG frames from portrait video using solution provided in above link ?
I have tested this with 720p and 1080p videos.
Couple of things i observed is,
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.
Other thing is when i pass false in the Method drawFrame in invert parameter, PNG frame is fine but upside down.
Edit:
With ExtractMpegFramesTest i'm getting this result
Landscape video with invert parameter true gives perfect Image http://postimg.org/image/qdliypuj5/
portrait video with invert parameter true gives distorted Image http://postimg.org/image/vfb7dwvdx/
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/
回答1:
In ExtractMpegFramesTest in the comment for saveFrame
, it states the
// 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.)
This is why there is the boolean parameter for drawFrame
that you mentioned.
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
.
Please refer to this answer for mirroring a bitmap; and use preScale(-1,1)
to invert the image on the correct axis.
来源:https://stackoverflow.com/questions/29848152/extractmpegframestest-having-issue-with-video-recorded-in-portrait-mode-in-andro