- $AUDIO_CODEC=`$ffmpeg -i "$video" 2>&1 | grep "Audio" | sed -r -e 's/.*?Audio: (\\S+),.*?/\\1/'`; chomp($AUDIO_CODEC);
- if($AUDIO_CODEC eq "") { die "-E- Unable to extract audio track encoding from input video file: $video\n"; }
- $handbrake_options .= " -E copy:$AUDIO_CODEC";
+ if($opt_v) { print " $ffmpeg -i \"$video\" 2>&1 | grep \"Audio\" | sed -r -e 's/.*?Audio: (\\S+).*?/\\1/' | tail -n 1\n"; }
+ $AUDIO_CODEC=`$ffmpeg -i "$video" 2>&1 | grep "Audio" | sed -r -e 's/.*?Audio: (\\S+).*?/\\1/' | tail -n 1`; chomp($AUDIO_CODEC);
+ $AUDIO_CODEC =~ s/,$//g;
+ if($AUDIO_CODEC eq "") { print "-W- Unable to extract audio track encoding from input video file: $video\n"; $handbrake_options .= " -E copy"; }
+ else { $handbrake_options .= " -E copy:$AUDIO_CODEC"; }
+ }
+
+ # Set our rotate option accordingly to rotate videos taken in portrait mode to landscape
+ my $rotate = `$ffprobe "$video" 2>&1 | grep -e rotate | awk '{print \$3}'`; chomp($rotate);
+ if($rotate ne "") {
+ print " Detected rotated input video ($rotate). Rotating video to: $video_mp4\n";
+ if($rotate eq "90") { $handbrake_options .= " --rotate=4"; $rotated = "90"; }
+ if($rotate eq "180") { $handbrake_options .= " --rotate=3"; $rotated = "none"; }