Gstreamer bad aspect ratio and orientation metatags after rotation (flip-method) applied

The problem is that after applying flip-method to nvvidconv, the output file will have correctly rotated and resized frames (I think so), but the display_aspect_ratio value returned from the ffprobe command still states that it is 16:9 - which I guess should also be rotated? Because of this, the video is stretched in many video players that use this value.

Another problem is that the orientation value from the input file is also preserved in the output one. As far as I know, there is no autorotate like method/property that I can use to get rid of it and rotate the video. Therefore is there something that I can do to remove video orientation/rotation metadata in the GStreamer pipeline?

Right now, I’m using FFmpeg after the GStreamer pipeline is finished and fixing those metadata, but this is tricky and, I think, redundant. Can I achieve something similar using GStreamer?

I am using the following pipeline:

gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux. ! queue ! h265parse ! nvv4l2decoder ! nvvidconv flip-method=1 ! videorate drop-only=true max-rate=30 ! 'video/x-raw(memory:NVMM),width=1280,height=720,format=(string)NV12,framerate=(fraction)30/1' ! nvv4l2h264enc  bitrate=2000000 control-rate=1 ! h264parse ! mp4mux faststart=true fragment-duration=4000 streamable=true name=mux ! filesink location=output.mp4 demux. ! queue ! avdec_aac ! audioconvert ! avenc_aac ! mux.

The nvvidconv plugin does physical rotation, so for keeping the aspect ratio, please set rotated width and height like:

... ! nvv4l2decoder ! nvvidconv flip-method=1 ! videorate drop-only=true max-rate=30 ! 'video/x-raw(memory:NVMM),width=720,height=1280,format=(string)NV12,framerate=(fraction)30/1' ! ...

That is correct, and this is indeed what I did there. I rotate the width and height values every time the flip-method is set to 1 and 3.

The problem is with an aspect ratio value that can be read using the ffprobe command. The returned aspect_ratio value is 16:9 after rotating. Therefore multiple players are stretching the video.
So my question is whether it is possible to rotate (or even drop) the aspect_ratio value, which is returned from the ffprobe command in GStreamer? Same for the orientation value.

You may try adding ‘pixel-aspect-ratio=1/1’ into caps after nvvidconv.

Unfortunately, it is not about the pixel aspect ratio, but about the video aspect ratio.

We can see DAR is correct by setting pixel-aspect-ratio=1/1:

$ gst-launch-1.0 -e videotestsrc num-buffers=150 ! video/x-raw,width=1280,height=720 ! nvvidconv flip-method=1 ! "video/x-raw(memory:NVMM),width=720,height=1280,pixel-aspect-ratio=1/1" ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=a.mp4
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
H264: Profile = 66, Level = 0
NVMEDIA_ENC: bBlitMode is set to TRUE
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:01.228195085
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
$ ffprobe -i a.mp4
ffprobe version 3.4.11-0ubuntu0.1 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened -
-libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --ena
ble-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutl
s --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-l
ibcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfre
etype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --
enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --ena
ble-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-
libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora
--enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --ena
ble-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq -
-enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --ena
ble-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable
-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2023-02-09T05:25:52.000000Z
  Duration: 00:00:05.00, start: 0.000000, bitrate: 4393 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(bt709, progressive), 720x1280, 4390 kb/s, SAR 1:1 DAR 9:16, 30 fps, 30 tbr, 3k tbn, 6k tbc (default)
      creation_time   : 2023-02-09T05:25:52.000000Z
      handler_name    : VideoHandler

Could you try again?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.