在网上浏览了大量文档后,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.中查找变换矩阵的一种更简洁的方法
如何在以下任一选项中提取视频的方向-
Ruby3.2ffmpeg(通过命令行服务器端) iOS
任何帮助都将不胜感激。
发布于 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
发布于 2013-01-09 22:41:00
ffmpeg使用.mov文件的旋转值报告元数据:
ffmpeg -i myrotatedMOV.mov
……
Duration: 00:00:14.31, start: 0.000000, bitrate: 778 kb/s
Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x360, 702 kb/s, 29.98 fps, 30 tbr, 600 tbn, 1200 tbc
Metadata:
rotate : 180
creation_time : 2013-01-09 12:47:36
handler_name : Core Media Data Handler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, s16, 62 kb/s
Metadata:
creation_time : 2013-01-09 12:47:36
handler_name : Core Media Data Handler
在我的应用程序中,我使用正则表达式将其提取出来,即在python中:
import subprocess, re
cmd = 'ffmpeg -i %s' % pathtofile
p = subprocess.Popen(
cmd.split(" "),
stderr = subprocess.PIPE,
close_fds=True
)
stdout, stderr = p.communicate()
reo_rotation = re.compile('rotate\s+:\s(?P<rotation>.*)')
match_rotation = reo_rotation.search(stderr)
rotation = match_rotation.groups()[0]
我还没有尝试过广泛的视频,只有几个用iphone5录制的.movs,使用的是FMPEG1.0版本。但到目前为止一切都很好。
https://stackoverflow.com/questions/5287603
复制相似问题