4

I have found questions on rotating videos with mencoder and ffmpeg however I am after a fully automated solution.

Can anybody help with this.

I want to

  • Detect the video orientation
  • Rotate if needed
  • Reset the meta data on the video (otherwise watching on a iOS device will cause unwanted rotation)
  • Save video in desired format

The reason for this is a wish to use the processed videos in a HTML5 video player. If I rotate without resetting the meta data iOS devices will read the meta and further rotate causing the video to be out by another 90 degrees.

2 Answers2

2

I use a little script and HandBrakeCLI for this.

Attention, the "--rotate" parameter has changed with 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
Andy
  • 7,931
  • 4
  • 25
  • 45
0

Similar to Andy's answer, here is a 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)
    }
rpertusio
  • 1
  • 1