Automatic rotation detection and video rotation respectively using mencoder, handbrake cli or ffmpeg

I found questions about video rotation using mencoder and ffmpeg, however after an automated solution.

Can anyone help with this.

I want to

  • Video orientation detection
  • Turn if necessary
  • Reset metadata on the video (otherwise viewing on the iOS device will result in unwanted rotation)
  • Save video in the desired format

The reason for this is the desire to use processed videos in the HTML5 video player. If I spin without reloading the metadata, iOS devices will read the meta and spin further, causing the video to go out another 90 degrees.

+4
source share
2 answers

For this, I use a little script and HandBrakeCLI.

Attention, the "-rotate" parameter has changed using HandBrake 1.0, this will work with 1.0.7:

for i in *.mp4 do r=$(exiftool -Rotation $i | cut -d ":" -f2 | sed 's/^[ ]*//') HandBrakeCLI -i $i -o ./out/$i --rotate=angle=$r -e x264 -q 21 -X 1000 done 
+1
source

Like Andy, here's the PowerShell and Handbrake version

 $SourceVideoPath = "C:\Videos\" $ListOfVideos = Get-ChildItem -path $SourceVideoPath -Filter *.mpg ForEach ($InputFile in $ListOfVideos){ $rotationFromEXIF = 0 Write-Host "Now processing: $InputFile" $InputFullName = $InputFile.Fullname $OutputFullName = $InputFile.DirectoryName + "\output\" + $InputFile; $rotationFromEXIF = ((& 'C:\Utilities\exiftool.exe' -rotation $InputFullName) -split ": ")[1] if ($rotationFromEXIF -gt 0){Write-Host "Rotating $rotationFromEXIF degrees"} (& 'C:\Program Files\HandBrake\HandBrakeCLI.exe' -i $InputFullName -o $OutputFullName --rotate=angle=$rotationFromEXIF) } 
0
source

All Articles