首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从视频中提取方向信息?

如何从视频中提取方向信息?
EN

Stack Overflow用户
提问于 2011-03-13 13:15:07
回答 6查看 19.2K关注 0票数 19

在网上浏览了大量文档后,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.中查找变换矩阵的一种更简洁的方法

如何在以下任一选项中提取视频的方向-

  • iOS 3.2
  • ffmpeg (通过命令行服务器端)
  • ruby

任何帮助都将不胜感激。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 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

试试看:

代码语言:javascript
运行
复制
irb>
require 'mini_exiftool'
movie = MiniExiftool.new('test_movie.mov')
movie.orientation #=> 90

干杯

票数 11
EN

Stack Overflow用户

发布于 2011-07-03 13:00:54

据我目前所知,ffmpeg不具备检测iPhone方向的能力。但是,开源库mediainfo可以。命令行示例:

代码语言:javascript
运行
复制
$ mediainfo test.mp4 | grep Rotation
Rotation                         : 90°

来自同一个iphone视频的更多示例输出:

代码语言:javascript
运行
复制
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
票数 10
EN

Stack Overflow用户

发布于 2016-12-24 02:40:22

您可以使用ffprobe。不需要任何grep,或任何其他附加进程,或任何正则表达式操作来解析输出,如其他答案所示。

如果需要旋转元数据,请执行以下操作:

命令:

代码语言:javascript
运行
复制
ffprobe -loglevel error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1:nk=1 input.mp4

输出示例:

代码语言:javascript
运行
复制
90

如果您想要显示矩阵旋转侧数据:

命令:

代码语言:javascript
运行
复制
ffprobe -loglevel error -select_streams v:0 -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4

输出示例:

代码语言:javascript
运行
复制
-90

如果您想要显示矩阵:

命令:

代码语言:javascript
运行
复制
ffprobe -loglevel error -select_streams v:0 -show_entries side_data=displaymatrix -of default=nw=1:nk=1 input.mp4

输出示例:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
ffprobe -loglevel error -show_entries stream_tags=rotate -of json input.mp4
{
    "streams": [
        {
            "tags": {
                "rotate": "90"
            },
            "side_data_list": [
                {

                }
            ]
        }
    ]
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5287603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档