在网上浏览了大量文档后,iPhone似乎总是以480x360的宽高比拍摄视频,并在视频轨道上应用变换矩阵。(480x360可能会改变,但对于给定的设备,它始终是相同的)
下面是一种在iOS项目中修改ffmpeg源代码并访问矩阵http://www.seqoy.com/correct-orientation-for-iphone-recorded-movies-with-ffmpeg/的方法
下面是在iOS-4 How to detect (iPhone SDK) if a video file was recorded in portrait orientation, or landscape.中查找变换矩阵的一种更简洁的方法
如何在以下任一选项中提取视频的方向-
任何帮助都将不胜感激。
发布于 2011-07-04 14:19:55
由于大多数相机将它们的旋转/方向存储在exif元数据中,我建议使用exifttool和一个名为mini_exiftool的ruby包装器gem,它是主动维护的。
安装exiftool:
apt-get exiftool || brew install exiftool || port install exiftool
或者使用任何可用的包管理器。
安装mini_exiftool:
gem install mini_exiftool
试试看:
irb>
require 'mini_exiftool'
movie = MiniExiftool.new('test_movie.mov')
movie.orientation #=> 90干杯
发布于 2011-07-03 13:00:54
据我目前所知,ffmpeg不具备检测iPhone方向的能力。但是,开源库mediainfo可以。命令行示例:
$ mediainfo test.mp4 | grep Rotation
Rotation : 90°来自同一个iphone视频的更多示例输出:
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Baseline@L3.0
Format settings, CABAC : No
Format settings, ReFrames : 1 frame
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 7s 941ms
Bit rate mode : Variable
Bit rate : 724 Kbps
Width : 480 pixels
Height : 360 pixels
Display aspect ratio : 4:3
Rotation : 90°
Frame rate mode : Variable
Frame rate : 29.970 fps
Minimum frame rate : 28.571 fps
Maximum frame rate : 31.579 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.140
Stream size : 702 KiB (91%)
Title : Core Media Video
Encoded date : UTC 2011-06-22 15:58:25
Tagged date : UTC 2011-06-22 15:58:34
Color primaries : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M
Transfer characteristics : BT.709-5, BT.1361
Matrix coefficients : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M发布于 2016-12-24 02:40:22
您可以使用ffprobe。不需要任何grep,或任何其他附加进程,或任何正则表达式操作来解析输出,如其他答案所示。
如果需要旋转元数据,请执行以下操作:
命令:
ffprobe -loglevel error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1:nk=1 input.mp4输出示例:
90如果您想要显示矩阵旋转侧数据:
命令:
ffprobe -loglevel error -select_streams v:0 -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4输出示例:
-90如果您想要显示矩阵:
命令:
ffprobe -loglevel error -select_streams v:0 -show_entries side_data=displaymatrix -of default=nw=1:nk=1 input.mp4输出示例:
00000000: 0 65536 0
00000001: -65536 0 0
00000002: 15728640 0 1073741824选项的含义
-loglevel error从output.-select_streams v:0中省略头部和其他信息,只处理第一个视频流,而忽略其他所有信息。如果您的输入包含多个视频流并且您只想要来自one.-show_entries stream_tags=rotate的信息选择从视频stream.-of default=nw=1:nk=1输出rotate标签使用 output format,但忽略包括节头/页脚包装和每个字段键,则非常有用。输出格式
ffprobe的输出可以是formatted in several ways。例如,JSON:
ffprobe -loglevel error -show_entries stream_tags=rotate -of json input.mp4
{
"streams": [
{
"tags": {
"rotate": "90"
},
"side_data_list": [
{
}
]
}
]https://stackoverflow.com/questions/5287603
复制相似问题