Rotation info not preserved?

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
efiten
Posts: 6
Joined: Thu Jun 21, 2012 9:29 am

Rotation info not preserved?

Post by efiten »

Please detail your question or problem in as much detail as possible:
In my original video the media info is :

Code: Select all

Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Rotation                                 : 270°
I already fond out that handbrake can't auto-rotate the video because it's not reading this rotation field from the mediainfo.
But is there a way that handbrake could preserve this info inside the encoded file, so that the encoded file has the original rotation info included?
If that's the case, most programs & streaming engines prcess the file correctly and show it in portrait mode.

Tell us about your environment. What version of HandBrake? What operating system are you running. etc.
WIndows 10 64-bit
HandBrake-0.10.5

We use Ngnix to stream those files, and it uses the 'rotation' field to show the file in the correct orientation.


Erwin Fiten
mduell
Veteran User
Posts: 8198
Joined: Sat Apr 21, 2007 8:54 pm

Re: Rotation info not preserved?

Post by mduell »

No, but you can actually rotate the video using the rotation filter instead of this silly flagging business.
efiten
Posts: 6
Joined: Thu Jun 21, 2012 9:29 am

Re: Rotation info not preserved?

Post by efiten »

Yes, that's correct, but the encoding is done automatically for all files in a folder, so then I have to find out a way to read out this info, and depending on that, change the arguments of handbrakeCLI.
It would be easier if I just could pass on this 'rotation' info to the encoded file, just because ngnix uses this info to show the video correct.

Erwin
mduell
Veteran User
Posts: 8198
Joined: Sat Apr 21, 2007 8:54 pm

Re: Rotation info not preserved?

Post by mduell »

Patches welcome.
Deleted User 11865

Re: Rotation info not preserved?

Post by Deleted User 11865 »

One day (no idea when), HandBrake will read the flag and automatically set up the rotate filter for you.
alxcy
Posts: 2
Joined: Sat May 06, 2017 7:55 am

Re: Rotation info not preserved?

Post by alxcy »

I just discovered the greatness of handbrake and I'm starting to shrink all my phone recorded videos to a more acceptable size. However, this little bug is ruining the whole experience!

@efiten How can I get that rotation info.I tried looking through VLC's media info window but couldn't find it anywhere.
efiten
Posts: 6
Joined: Thu Jun 21, 2012 9:29 am

Re: Rotation info not preserved?

Post by efiten »

I found this info with MediaInfo : https://sourceforge.net/projects/mediainfo/
alxcy
Posts: 2
Joined: Sat May 06, 2017 7:55 am

Re: Rotation info not preserved?

Post by alxcy »

I wrote a simple bash script to set the rotation flags on the output files by reading the original flag from the input files. In my case I'm using handbrake to shrink mp4 files to m4v files. The script creates a copy of the m4v files with the flag set as per the original mp4 file. You can run bash from within Windows 10 with WSL (Windows Subsystem for Linux). You'll need to apt-get ffmpeg and mediainfo.

Code: Select all

#!/bin/bash

DIR1='/mnt/c/Users/alex/Desktop/Vids/src'  # Original sources (mp4's)
DIR2='/mnt/c/Users/alex/Desktop/Vids/out'  # Converted Handbrake files (m4v's)
DIR3='/mnt/c/Users/alex/Desktop/Vids/out2' # Destination for fixed files (with rotated flag)

PAT='^.*Rotation.*$'

cd $DIR1

for file in *.mp4
do

  echo Reading file: $DIR1/$file 
  
  ROT=$( mediainfo $file | grep Rotation )

  if [[ $ROT =~ $PAT ]];
  then 
    DEG=$(echo $ROT | grep -oP 'Rotation : \K([0-9]+)');
	echo "Rotate by DEG="$DEG;
  
	SRC_FILE="${file/.mp4/.m4v}"
  
	FFMPEG="ffmpeg -i $DIR2/$SRC_FILE -c copy -metadata:s:v:0 rotate=$DEG $DIR3/$SRC_FILE"
	$( $FFMPEG )

  else 
	echo "No Rotation";
  fi
  
done
Post Reply