- my $requantize_option = "";
- if(!$progressive) { $requantize_option = "-q $interlaced_requantize_quality"; }
- else { $requantize_option = "-q $progressive_requantize_quality"; }
+ 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"; }
+ }
+
+ # 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"; }
+ }