+ # Set our output video filename
+ my $video_mp4 = $video; $video_mp4 =~ s/\.[^.]*$//; $video_mp4 .= ".hb.mp4";
+
+ # Don't recompress certain file extensions
+ # Unless the video is not progressive or is rotated, then we do need to recompress it to deinterlace or unrotate it
+ my $no_recompress = 0;
+ if($no_recompress_file_ext && $progressive && ($video =~ $no_recompress_file_ext)) { $no_recompress = 1; }
+
+ # 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"; }
+ $no_recompress = 0; # We have to recompress this video to unrotate it
+ }
+
+ # Set our requantize factor accordingly
+ if(defined $opt_q and ! -f $video_mp4) {
+ print " Re-quantizing input video content to: $video_mp4\n";
+ $handbrake_options = $handbrake_requantize_options;
+ if(!$progressive) { $handbrake_options = "-q $interlaced_requantize_quality"; }
+ else { $handbrake_options = "-q $progressive_requantize_quality"; }
+ };
+
+ # Set our recompress options accordingly
+ if(defined $opt_z and ! -f $video_mp4 and ! $no_recompress) {
+ print " Re-compressing input video content to: $video_mp4\n";
+ $handbrake_options = $handbrake_recompress_options;
+ # We want our audio to be passed-through by default, so detect how the audio of the input is encoded, and tell handbrake to make the output match
+ 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"; }
+ }