iPhone 上的 FFmpeg - 修改视频方向
我正在弄乱 iPhone 3GS 上加载 FFmpeg 的 h264 视频。问题是任何以“纵向”方向录制的视频都会应用变换矩阵,导致它们显示旋转 90 度的逆时钟。
据我所知,到目前为止,我只需要修改“tkhd”原子中的变换矩阵。问题是我在访问或修改这些数据时遇到问题。我检查了 FFmpeg 实现:
static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
它清楚地显示了如何以 avformat 访问矩阵,但是当我尝试使用相同的函数访问标头字节时,我没有得到任何有理值。即使我成功拉动了矩阵,我也不知道如何替换它? FFmpeg 具有检索和附加到轨道头的功能,但似乎没有任何可替换的功能?
任何帮助将不胜感激。
谢谢, 马特。
I'm messing with h264 videos loaded with FFmpeg on the iPhone 3GS. The problem is any videos recorded in "Portrait" orientation have a transformation matrix applied to them causing them to display rotated 90 degrees counter-clock.
From what I understand thus far, I just need to modify the transform matrix in the 'tkhd' atom. The problem is I am having trouble accessing or modifying this data. I checked out the FFmpeg implementation for:
static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
which clearly shows how the matrix is accessed in avformat but when I try to access the header bytes using the same functions I am not getting any rational values. Even if I were to successfully pull the matrix I'm not sure how to replace it? FFmpeg has functions for retrieving and appending to the track header but nothing for replace it seems?
Any help would be greatly appreciated.
Thanks,
Matt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于那些无法使用 v 过滤器选项的人,经过一番搜索,我找到了一个适合我的构建的替代选项:
这会将视频顺时针翻转 90 度。希望这可以帮助所有像我一样在 ubuntu 上挣扎的人! :)
To those who cannot get the v filter option to work, after some searching I found an alternative option which works for my build:
this flips the video 90 degrees clockwise. hope this helps all those on ubuntu struggling like I was!! :)
我刚刚在 FFMPEG git master 分支上接受了一个补丁,它应该可以帮助我们所有人调整 iPhone 的方向以及应用于它发送的 .mov 文件的后续转换。 FFMPEG 现在将在元数据中发回:
“旋转”=90,180 或 270,具体取决于您需要顺时针旋转图像多少度才能获得真正的旋转。
I just had a patch accepted on the FFMPEG git master branch which should help all of us in adjusting for the iPhone's orientation and subsequent transform applied to the .mov file it sends out. FFMPEG will now send back in metadata:
'rotate'=90,180,or 270 depending on how many degrees you need to turn the image clockwise to get the true rotation.
iPhone 3GS 中录制的纵向视频在横向中奇怪地旋转,只有 Quicktime 才能正确播放它,像 VLC 等播放器以横向方式播放纵向模式视频,因为它是这样编码的!也许苹果已经设置了一些位,以便 Quicktime 正确识别和设置方向。
您可以使用 ffmpeg 的 -vfilters 选项来旋转视频。它的版本为 r21242。你必须在你的 ffmpeg 版本上修补它。
使用 --enable-vfilters 配置构建
,您可以使用选项:
旋转输入影片。
Portrait video recorded in iPhone 3GS is strangely rotated in landscape, and only quicktime plays it correctly, players like VLC etc play the portrait mode videos in landscape because it is encoded that way! Maybe apple have set some bit so that quicktime identifies and sets the orientation properly.
You can use -vfilters option of ffmpeg to rotate the video. It is available in version r21242. You have to patch it on your version of ffmpeg.
configure the build by using --enable-vfilters
and you can use the option:
to rotate the input movie.
影片是直接根据硬件相机的方向录制的。当您转动它时,相机仍然以相同的方向和相同的直接写入文件进行记录。
决定视频方向的是 变换矩阵
矩阵的设置取决于iPhone的方向。这将决定您是否必须旋转视频。该旋转可以是 90 度,也可以是 180 度。这取决于手机方向。
了解矩阵是什么以及它与图像的关系后,您将能够确定视频的方向。
the movie is recorded directly with the orientation of the hardware camera. when you turn it the camera still records with the same orientation and the same straight write to file.
What determines the orientation of the video is the Transform matrix
The matrix is set dependent on the iphone's orientation. And this is what will determine if you have to rotate the video. And that rotation could be 90 degrees and it could be 180 degrees. It depends on the phone orientation.
After you get an idea of what the matrix is and how it relates to the image you will be able to determine the orientation of the video.