Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation in certain images isn't correctly detected #228

Open
Nowaker opened this issue Sep 23, 2023 · 1 comment · May be fixed by #229
Open

Rotation in certain images isn't correctly detected #228

Nowaker opened this issue Sep 23, 2023 · 1 comment · May be fixed by #229

Comments

@Nowaker
Copy link

Nowaker commented Sep 23, 2023

I came across a video file whose native resolution is 1920x1080 with 90 degree rotation. However, it uses a non-standard rotation tag, so the operations on that file are inconsistent:

  • movie.transcode works fine (the final result is a 1080x1920 video)
  • movie.width and movie.height don't work correctly (1920x1080 is reported, with no rotation)

Here's an excerpt from ffprobe:

ffprobe version 6.0 Copyright (c) 2007-2023 the FFmpeg developers
  built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-rotate-bug.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2021-04-28T01:45:44.000000Z
    com.android.version: 10
    com.android.capture.fps: 30.000000
  Duration: 00:00:18.31, start: 0.000000, bitrate: 14818 kb/s
  Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 1920x1080, 14560 kb/s, SAR 1:1 DAR 16:9, 29.98 fps, 30 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2021-04-28T01:45:44.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of 90.00 degrees

And here's an excerpt from the JSON output:

            "side_data_list": [
                {
                    "side_data_type": "Display Matrix",
                    "displaymatrix": "\n00000000:            0      -65536           0\n00000001:        65536           0           0\n00000002:            0           0  1073741824\n",
                    "rotation": 90
                }
            ]

Unfortunately, I cannot share the video file.

@Nowaker
Copy link
Author

Nowaker commented Sep 23, 2023

Here's a fix:

          @rotation = if video_stream.key?(:tags) and video_stream[:tags].key?(:rotate)
                        video_stream[:tags][:rotate].to_i
                      elsif video_stream.key?(:side_data_list)
                        rotation_data = video_stream[:side_data_list].find { |data| data.key?(:rotation) }
                        rotation_data ? rotation_data[:rotation].to_i : nil
                      else
                        nil
                      end

Will submit a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant