aXe*_*-HH 19 video metadata ffmpeg video-conversion exiftool
我只想更改 .mp4 视频文件中的旋转标志。存在许多类似的问题,大多数答案建议使用
ffmpeg -i input.mp4 -map_metadata 0 -metadata:s:v rotate=90 -codec copy output.mp4
Run Code Online (Sandbox Code Playgroud)
我对这些解决方案的问题是,即使它复制了大部分元数据,也会丢失一些部分,并且文件小 700kb。附件是来自 ffprobe 和 exifer 的元数据之前和之后。
另一个奇怪的发现是 ffmpeg rotate=90 命令进行 ccw 旋转,在 ffprobe 中元数据中为 (cw) 270°,但在 displaymatrix 侧数据中为 (ccw)90°。
= equal attributes
* altered attributes
- removed attributes
+ added attributes
Run Code Online (Sandbox Code Playgroud)
*Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\input.mp4':
= Metadata:
* major_brand : avc1
* minor_version : 0
* compatible_brands: avc1isom
= creation_time : 2016-10-29T12:10:41.000000Z
- firmware : HD3.11.03.03
* Duration: 00:00:06.01, start: 0.000000, bitrate: 32072 kb/s
= Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1440 [SAR 1:1 DAR 4:3], 30945 kb/s, 47.95 fps, 47.95 tbr, 720k tbn, 95.90 tbc (default)
= Metadata:
= creation_time : 2016-10-29T12:10:41.000000Z
* handler_name : GoPro AVC
- encoder : GoPro AVC encoder
- Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
- Metadata:
- creation_time : 2016-10-29T12:10:41.000000Z
- handler_name : GoPro AAC
Run Code Online (Sandbox Code Playgroud)
*Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\output.mp4':
= Metadata:
* major_brand : isom
* minor_version : 512
* compatible_brands: isomiso2avc1mp41
= creation_time : 2016-10-29T12:10:41.000000Z
+ encoder : Lavf58.10.100
* Duration: 00:00:06.01, start: 0.000000, bitrate: 30948 kb/s
= Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1440 [SAR 1:1 DAR 4:3], 30945 kb/s, 47.95 fps, 47.95 tbr, 720k tbn, 95.90 tbc (default)
= Metadata:
+ rotate : 270
= creation_time : 2016-10-29T12:10:41.000000Z
* handler_name : VideoHandler
+ Side data:
+ displaymatrix: rotation of 90.00 degrees
Run Code Online (Sandbox Code Playgroud)
=ExifTool Version Number : 10.87
*File Name : input.mp4
=Directory : C:/
*File Size : 23 MB
*File Modification Date/Time : 2016:10:29 13:10:48+02:00
*File Access Date/Time : 2018:03:22 22:51:11+01:00
*File Creation Date/Time : 2018:03:22 22:51:11+01:00
=File Permissions : rw-rw-rw-
=File Type : MP4
=File Type Extension : mp4
=MIME Type : video/mp4
*Major Brand : MP4 Base w/ AVC ext [ISO 14496-12:2005]
*Minor Version : 0.0.0
*Compatible Brands : avc1, isom
=Movie Header Version : 0
=Create Date : 2016:10:29 12:10:41
=Modify Date : 2016:10:29 12:10:41
*Time Scale : 90000
=Duration : 6.01 s
=Preferred Rate : 1
=Preferred Volume : 100.00%
=Preview Time : 0 s
=Preview Duration : 0 s
=Poster Time : 0 s
=Selection Time : 0 s
=Selection Duration : 0 s
=Current Time : 0 s
*Next Track ID : 3
-Firmware Version : HD3.11.03.03
-Lens Serial Number : LW13121003000141
-Camera Serial Number Hash : 4833422b363033313530636432356400
=Track Header Version : 0
=Track Create Date : 2016:10:29 12:10:41
=Track Modify Date : 2016:10:29 12:10:41
=Track ID : 1
=Track Duration : 6.01 s
=Track Layer : 0
=Track Volume : 0.00%
=Image Width : 1920
=Image Height : 1440
=Graphics Mode : srcCopy
=Op Color : 0 0 0
=Compressor ID : avc1
=Source Image Width : 1920
=Source Image Height : 1440
=X Resolution : 72
=Y Resolution : 72
-Compressor Name : .GoPro AVC encoder
=Bit Depth : 24
-Color Representation : nclc 1 1 1
-Gamma : 2.2
=Video Frame Rate : 47.952
-Matrix Structure : 1 0 0 0 1 0 0 0 1
=Media Header Version : 0
=Media Create Date : 2016:10:29 12:10:41
=Media Modify Date : 2016:10:29 12:10:41
-Media Time Scale : 48000
-Media Duration : 5.99 s
*Handler Type : Audio Track
-Handler Description : .GoPro AAC
-Balance : 0
-Audio Format : mp4a
-Audio Channels : 2
-Audio Bits Per Sample : 16
-Audio Sample Rate : 48000
-Movie Data Size : 24045320
-Movie Data Offset : 32768
*Avg Bitrate : 32 Mbps
=Image Size : 1920x1440
=Megapixels : 2.8
*Rotation : 0
Run Code Online (Sandbox Code Playgroud)
=ExifTool Version Number : 10.87
*File Name : output.mp4
=Directory : C:/
*File Size : 22 MB
*File Modification Date/Time : 2018:03:23 12:29:19+01:00
*File Access Date/Time : 2018:03:23 12:28:18+01:00
*File Creation Date/Time : 2018:03:23 12:28:18+01:00
=File Permissions : rw-rw-rw-
=File Type : MP4
=File Type Extension : mp4
=MIME Type : video/mp4
*Major Brand : MP4 Base Media v1 [IS0 14496-12:2003]
*Minor Version : 0.2.0
*Compatible Brands : isom, iso2, avc1, mp41
+Movie Data Size : 23232544
+Movie Data Offset : 48
=Movie Header Version : 0
=Create Date : 2016:10:29 12:10:41
=Modify Date : 2016:10:29 12:10:41
*Time Scale : 1000
=Duration : 6.01 s
=Preferred Rate : 1
=Preferred Volume : 100.00%
=Preview Time : 0 s
=Preview Duration : 0 s
=Poster Time : 0 s
=Selection Time : 0 s
=Selection Duration : 0 s
=Current Time : 0 s
*Next Track ID : 2
=Track Header Version : 0
=Track Create Date : 2016:10:29 12:10:41
=Track Modify Date : 2016:10:29 12:10:41
=Track ID : 1
=Track Duration : 6.01 s
=Track Layer : 0
=Track Volume : 0.00%
+Matrix Structure : 0 1 0 -1 0 0 0 0 1
=Image Width : 1920
=Image Height : 1440
=Media Header Version : 0
=Media Create Date : 2016:10:29 12:10:41
=Media Modify Date : 2016:10:29 12:10:41
+Media Time Scale : 720000
+Media Duration : 6.01 s
+Media Language Code : eng
+Handler Description : VideoHandler
=Graphics Mode : srcCopy
=Op Color : 0 0 0
=Compressor ID : avc1
=Source Image Width : 1920
=Source Image Height : 1440
=X Resolution : 72
=Y Resolution : 72
=Bit Depth : 24
+Pixel Aspect Ratio : 1:1
=Video Frame Rate : 47.952
*Handler Type : Metadata
+Handler Vendor ID : Apple
+Encoder : Lavf58.10.100
*Avg Bitrate : 30.9 Mbps
=Image Size : 1920x1440
=Megapixels : 2.8
*Rotation : 270
Run Code Online (Sandbox Code Playgroud)
我在记事本++中比较了 ffmpeg rotate=0 和 rotate=90 .mp4 文件以识别旋转标志/矩阵,但没有运气,只是胡言乱语。我宁愿只编辑标志(就像 exiftool 为各种元数据做的那样,但不能在视频中旋转)而不是将内容流式传输到新容器中,也为了更快的处理(所有视频都在 NAS 上) .
aXe*_*-HH 24
exiftool 10.89 版现在支持在不更改其他元数据的情况下旋转 mp4 视频。
用法:
exiftool -rotation=90 video.mp4
Run Code Online (Sandbox Code Playgroud)
aXe*_*-HH 23
为了获得真正的无损旋转,我找不到解决方案,所以我抓住了一个十六进制编辑器(例如HxD)并分析了旋转的视频文件。
vide以查找视频轨道的元数据trak...\tkhd@标志(HEX 40)无轮换:
00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
Run Code Online (Sandbox Code Playgroud)180°:
FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
Run Code Online (Sandbox Code Playgroud)90°顺时针:
00 00 00 00 00 01 00 00 00 00 00 00 FF FF 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
Run Code Online (Sandbox Code Playgroud)90°逆时针:
00 00 00 00 FF FF 00 00 00 00 00 00 00 01 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
Run Code Online (Sandbox Code Playgroud)根据需要更改文件,它应该在支持旋转标志的播放器中旋转(大多数当前播放器都这样做)。
如果您的视频包含立体声音频,显然不会切换,因此如果您希望声音与视频旋转(180°)相匹配,则需要切换左右声道。