mp4 和旋转 - 删除标志但设置旋转

问题描述 投票:0回答:2

我在旋转某些 mp4 文件时遇到了困难。这很可能是我的理解能力差,所以如果我列出我所知道的(或认为我知道的)然后我想要发生什么,请原谅我。

mp4 显然有一个正确的显示方式 - 也就是说,您希望它在观看时显示的方式。称之为方向。这不是元数据 - 这只是您作为一个人想要查看图像的方式,人们的头位于屏幕顶部,脚位于屏幕底部。

作为元数据的一部分,mp4 文件有一个值/参数(我相信称为“旋转”),它告诉 mp4 需要旋转多少度(0、90、180、270 度)才能正确定向。某些玩家观察到该值/参数,而另一些玩家则观察不到。因此,如果我使用此播放器播放视频,一切都很好(因为它观察值/参数) - 但如果我使用其他播放器播放视频,则一切都是横向的(因为它不观察值/参数)。

我想要做的是正确定向 mp4,将值/参数设置为 0,这样无论哪个玩家播放它,它总是会以正确的方向播放(因为那些观察值/参数的玩家会看到它是 0并且什么都不做)。所以我认为我需要做的是以某种方式删除值/参数,然后将 mp4 旋转到正确的方向而不使用旋转值/参数。我正在考虑 FastStone Image Viewer 可以对 JPG 执行的操作 - 无损旋转它们而不设置旋转值。

我使用过 ffmpeg,并相信它删除了旋转值/参数(或将其设置为 0),因为在我使用它之后,突然我的视频在 Windows 资源管理器中出现在侧面,而之前它是正确出现的。但是现在如何在不更改旋转值/参数的情况下将其旋转到正确的方向?

抱歉,这是非常冗长和混乱的。就像我一样。

ffmpeg rotation mp4
2个回答
2
投票

ffmpeg重新编码时会自动旋转

示例:输入的光栅尺寸为 1920x1080,侧面数据顺时针旋转 90°。运行

ffmpeg -i input.mp4 output.mp4
将导致视频根据旋转侧数据顺时针旋转 90°。输出将为 1080x1920,删除旋转侧数据。

避免重新编码时自动旋转

使用

-noautorotate
输入选项:

ffmpeg -noautorotate -i input.mp4 output.mp4

更改旋转侧数据而无需重新编码

添加

-c copy
以启用流复制模式并使用
-metadata
选项:

ffmpeg -i input.mp4 -c copy -metadata:s:v rotate=90 output.mp4

显示旋转侧数据

ffprobe -v error -select_streams v -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4

0
投票

我尝试过这个(2024 年 4 月)...实际上使用了精确的 C&P 行(因此选项顺序不受干扰)...它不起作用...ffprobe 显示了完全相同的输入和输出数据。

$ ffprobe -v error -select_streams v -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4
-90
-90
-90
...

$ ffmpeg -i input.mp4 -c copy -metadata:s:v rotate=90 output.mp4
ffmpeg version 6.1.1-1 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13 (Debian 13.2.0-9)
  configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libharfbuzz --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-libjxl --enable-pocketsphinx --enable-librsvg --enable-libvpl --disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libsvtav1 --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2024-04-07T07:23:29.000000Z
    location        : +51.3688-000.8220/
    location-eng    : +51.3688-000.8220/
    com.android.version: 12
  Duration: 00:01:49.54, start: 0.000000, bitrate: 42145 kb/s
  Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 3840x2160, 41995 kb/s, 30.01 fps, 30 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2024-04-07T07:23:29.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -90.00 degrees
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2024-04-07T07:23:29.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
File 'output.mp4' already exists. Overwrite? [y/N] y
[vost#0:0/copy @ 0x5583cdbe0540] Conversion of a 'rotate' metadata key to a proper display matrix rotation is deprecated. See -display_rotation for setting rotation instead.Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    com.android.version: 12
    location        : +51.3688-000.8220/
    location-eng    : +51.3688-000.8220/
    encoder         : Lavf60.16.100
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 3840x2160, q=2-31, 41995 kb/s, 30.01 fps, 30 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2024-04-07T07:23:29.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -90.00 degrees
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2024-04-07T07:23:29.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[out#0/mp4 @ 0x5583cdb53bc0] video:561229kB audio:1283kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.017338%
size=  562610kB time=00:01:49.50 bitrate=42089.5kbits/s speed=74.2x    

d$ ffprobe -v error -select_streams v -show_entries side_data=rotation -of default=nw=1:nk=1 output.mp4
-90
-90
...

但是我在https://superuser.com/questions/1307158/change-rotation-flag-in-mp4-video-without-losing-metadata

找到了该条目

即:

exiftool -rotation=90 video.mp4

这效果很好!

顺便说一句。我有一个旧脚本,其中包含“-metadata:s:vrotate=90”逻辑,所以看起来过去工作得很好。 (在上面的输出中搜索“已弃用”)

© www.soinside.com 2019 - 2024. All rights reserved.