2021-03-22 17:52:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
###############################################################
|
|
|
|
# ks-crop (ks-tools) - Crop or change aspect ratio of a video #
|
2023-02-11 14:33:51 +01:00
|
|
|
# Date: 10-02-2023 #
|
2021-03-22 17:52:11 +01:00
|
|
|
# Author: q3aql #
|
2022-01-02 17:20:24 +01:00
|
|
|
# Contact: q3aql@duck.com #
|
2021-03-22 17:52:11 +01:00
|
|
|
###############################################################
|
2023-02-10 13:20:13 +01:00
|
|
|
VERSION="8.4-dev"
|
2023-02-11 14:33:51 +01:00
|
|
|
M_DATE="100223"
|
|
|
|
|
|
|
|
# Detect version ffmpeg for old releases
|
|
|
|
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
|
|
|
|
IFS="abcdefghijklmnopqrstyvwxzABCDEFHIJKLMNOPQRSTYVWXZ@/()"
|
|
|
|
ffmpeg_version=$(echo ${ffmpeg_version})
|
2023-02-11 14:46:48 +01:00
|
|
|
IFS=$' \t\n'
|
|
|
|
unset IFS
|
2023-02-11 14:33:51 +01:00
|
|
|
if [ -z "${ffmpeg_version}" ] ; then
|
|
|
|
video_sync="vsync"
|
|
|
|
else
|
|
|
|
if [ ${ffmpeg_version} -lt 5 ] ; then
|
|
|
|
video_sync="vsync"
|
|
|
|
else
|
|
|
|
video_sync="fps_mode"
|
|
|
|
fi
|
|
|
|
fi
|
2021-03-22 17:52:11 +01:00
|
|
|
|
|
|
|
# Global parameters
|
|
|
|
dirTemp="/tmp"
|
|
|
|
listTemp="ks-tools.list"
|
|
|
|
ksToolsTempFolder="/tmp/ks-tools"
|
|
|
|
|
|
|
|
# Resolution and parameters
|
|
|
|
to4_3="1920x1440"
|
|
|
|
to16_9="1920x1080"
|
|
|
|
to5_4="1920x1540"
|
2021-03-30 00:07:54 +02:00
|
|
|
toImax="1920x1346"
|
2021-03-22 17:52:11 +01:00
|
|
|
v_preset="medium"
|
|
|
|
vcodec="libx264"
|
|
|
|
b_vcodec="5000k"
|
|
|
|
acodec="copy"
|
|
|
|
v_ext="mkv"
|
|
|
|
default_lang_audio="spa"
|
|
|
|
|
|
|
|
# Empty variables
|
|
|
|
resolution=null
|
|
|
|
modeCrop=null
|
|
|
|
inputFile="${2}"
|
|
|
|
|
2021-03-26 18:19:27 +01:00
|
|
|
# Check cygwin alias (for Windows)
|
|
|
|
if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
|
|
|
|
shopt -s expand_aliases
|
|
|
|
source "/usr/bin/cygwin-alias.sh"
|
|
|
|
fi
|
|
|
|
|
2021-03-22 17:52:11 +01:00
|
|
|
# Check if ffmpeg is installed
|
|
|
|
ffmpeg_test=$(ffmpeg --help 2>&1)
|
|
|
|
error_ffmpeg=$?
|
|
|
|
if [ ${error_ffmpeg} -ne 0 ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "+ The 'ffmpeg' tool is not installed!"
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-22 17:52:11 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Function to remove extension from file
|
|
|
|
# Syntax: removeExtension "<text>"
|
|
|
|
function removeExtension() {
|
2021-03-28 01:56:41 +01:00
|
|
|
wordToConvert=${1}
|
|
|
|
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
|
|
|
|
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
|
|
|
|
echo "${wordToConvert}" > ${ksToolsSedFile}
|
|
|
|
# Remove extensions
|
|
|
|
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
# Show file without extension
|
|
|
|
wordToConvert=$(cat ${ksToolsSedFile})
|
|
|
|
echo ${wordToConvert}
|
2021-03-22 17:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show files with spaces.
|
|
|
|
# Syntax: showFileWithSpace <file number>
|
|
|
|
function showFileWithSpace() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "${1}" > ${dirTemp}/name.tmp
|
|
|
|
sed -i 's/_/ /g' ${dirTemp}/name.tmp
|
|
|
|
DisplayName=$(cat ${dirTemp}/name.tmp)
|
|
|
|
rm -rf ${dirTemp}/name.tmp
|
|
|
|
echo ${DisplayName}
|
2021-03-22 17:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show menu again when syntax is wrong
|
|
|
|
function show_menu() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "- Crop or change aspect ratio of a video"
|
|
|
|
echo ""
|
|
|
|
echo "+ Config:"
|
|
|
|
echo ""
|
|
|
|
echo " - Resolutions: "
|
|
|
|
echo " + ${to4_3} (4:3)"
|
|
|
|
echo " + ${to16_9} (16:9)"
|
|
|
|
echo " + ${to5_4} (5:4)"
|
|
|
|
echo " + ${toImax} (IMAX)"
|
|
|
|
echo " - Video codec: ${vcodec}"
|
|
|
|
echo " - Bitrate video: ${b_vcodec}"
|
|
|
|
echo " - Preset: ${v_preset}"
|
|
|
|
echo " - Audio codec: ${acodec}"
|
|
|
|
echo " - Default Audio: ${default_lang_audio}"
|
|
|
|
echo " - Container: ${v_ext}"
|
|
|
|
echo ""
|
|
|
|
echo "+ Syntax: "
|
|
|
|
echo ""
|
|
|
|
echo " $ ks-crop -16:9-crop <video-file> --> Crop from 4:3/IMAX to 16:9 (1.77:1)"
|
|
|
|
echo " $ ks-crop -4:3-crop <video-file> --> Crop from 16:9 to 4:3 (1.33:1)"
|
|
|
|
echo " $ ks-crop -5:4-crop <video-file> --> Crop from 16:9 to 5:4 (1.25:1)"
|
|
|
|
echo " $ ks-crop -imax-crop <video-file> --> Crop from 16:9 to IMAX (1.43:1)"
|
|
|
|
echo ""
|
|
|
|
echo " $ ks-crop -16:9-aspect <video-file> --> Change aspect to 16:9 (stretched)"
|
|
|
|
echo " $ ks-crop -4:3-aspect <video-file> --> Change aspect to 4:3 (stretched)"
|
|
|
|
echo " $ ks-crop -5:4-aspect <video-file> --> Change aspect to 5:4 (stretched)"
|
|
|
|
echo ""
|
|
|
|
echo " + Examples: "
|
|
|
|
echo " ks-crop -16:9-crop /data/movies/Example.mkv"
|
|
|
|
echo " ks-crop -4:3-aspect /data/movies/Video.avi"
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-22 17:52:11 +01:00
|
|
|
}
|
|
|
|
|
2021-03-23 17:49:13 +01:00
|
|
|
# Function to show error reading file
|
|
|
|
# Syntax: errorReadingFile <file>
|
|
|
|
function errorReadingFile() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "* The file '${1}' does not exist!"
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-23 17:49:13 +01:00
|
|
|
}
|
|
|
|
|
2021-03-22 17:52:11 +01:00
|
|
|
# Conversion parameters
|
|
|
|
p_ffmpeg="ffmpeg -i"
|
|
|
|
p_ffmpeg_patched="-max_muxing_queue_size 9999"
|
2022-01-18 20:53:03 +01:00
|
|
|
# f_conversion="-vsync 1 -async 1" # Deprecated method
|
2023-02-11 14:33:51 +01:00
|
|
|
f_conversion="-${video_sync} cfr"
|
|
|
|
f_conversion_crop="-${video_sync} cfr -async 1"
|
2021-03-22 17:52:11 +01:00
|
|
|
# Check if video input uses H265 (HEVC)
|
|
|
|
codec_h265=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "h265")
|
|
|
|
codec_hevc=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "hevc")
|
|
|
|
yuv420p10le=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le")
|
2021-04-05 11:58:34 +02:00
|
|
|
hevc_main10=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "Main 10")
|
|
|
|
hevc_profile_10bit="${yuv420p10le}${hevc_main10}"
|
2021-03-22 17:52:11 +01:00
|
|
|
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
|
|
|
|
if [ -z "${codec_h265_hevc}" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
2021-03-22 17:52:11 +01:00
|
|
|
else
|
2021-04-05 11:58:34 +02:00
|
|
|
if [ -z "${hevc_profile_10bit}" ] ; then
|
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
|
|
|
else
|
2023-02-08 19:19:17 +01:00
|
|
|
#p_conversion="-c:v ${vcodec} -x264opts colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084:chromaloc=2 -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
2021-04-05 11:58:34 +02:00
|
|
|
fi
|
2021-03-22 17:52:11 +01:00
|
|
|
fi
|
|
|
|
|
2021-03-23 02:15:13 +01:00
|
|
|
# Show menu with bad syntax
|
|
|
|
if [ "${1}" == "-16:9-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-4:3-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-5:4-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-imax-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-16:9-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-4:3-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
elif [ "${1}" == "-5:4-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo > /dev/null
|
2021-03-23 02:15:13 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
show_menu
|
2021-03-23 02:15:13 +01:00
|
|
|
fi
|
2021-03-23 17:49:13 +01:00
|
|
|
if [ -f "${2}" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "detected" > /dev/null
|
2021-03-23 17:49:13 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
errorReadingFile "${2}"
|
2021-03-23 17:49:13 +01:00
|
|
|
fi
|
2021-03-23 02:15:13 +01:00
|
|
|
|
|
|
|
# Detect resolution of video file
|
|
|
|
detect_2=$(ffmpeg -i ${2} 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 2 | cut -d "[" -f 1 | tr -s " " | grep x)
|
|
|
|
detect_3=$(ffmpeg -i ${2} 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 3 | cut -d "[" -f 1 | tr -s " " | grep x)
|
|
|
|
detect_4=$(ffmpeg -i ${2} 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 4 | cut -d "[" -f 1 | tr -s " " | grep x)
|
|
|
|
detect_5=$(ffmpeg -i ${2} 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 5 | cut -d "[" -f 1 | tr -s " " | grep x)
|
|
|
|
resolution_detected="${detect_2}${detect_3}${detect_4}${detect_5}"
|
2021-03-24 15:00:34 +01:00
|
|
|
resolution_height=$(echo ${resolution_detected} | cut -d "x" -f 2)
|
2021-03-23 02:15:13 +01:00
|
|
|
|
|
|
|
# Set size crop to 16:9 (ih)
|
2021-03-24 18:05:57 +01:00
|
|
|
calculate_crop=$(expr ${resolution_height} / 4 2> /tmp/ks-tools.error)
|
|
|
|
# Check if number is correct
|
|
|
|
expr ${calculate_crop} + 1 &> /tmp/ks-tools.error
|
|
|
|
ih_error="$?"
|
|
|
|
|
|
|
|
if [ ${ih_error} -eq 0 ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
ih_size="${calculate_crop}"
|
2021-03-24 18:05:57 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
ih_size="0"
|
2021-03-24 18:05:57 +01:00
|
|
|
fi
|
2021-03-23 02:15:13 +01:00
|
|
|
|
2021-03-22 17:52:11 +01:00
|
|
|
# Function to crop videos
|
|
|
|
function crop_video() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* Information of ${inputFile}:"
|
|
|
|
echo ""
|
|
|
|
echo "+ Video Tracks:"
|
|
|
|
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
|
|
|
|
echo ""
|
|
|
|
echo "+ Audio Tracks:"
|
|
|
|
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
|
|
|
|
echo ""
|
|
|
|
# Check de video track by default
|
|
|
|
video_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
|
|
|
|
if [ -z "${video_default}" ] ; then
|
|
|
|
video_default="0:0"
|
|
|
|
else
|
|
|
|
video_default_patch=$(echo ${video_default} | cut -c4)
|
|
|
|
if [ "${video_default_patch}" == ":" ] ; then
|
|
|
|
video_default=$(echo ${video_default} | cut -c1-3)
|
|
|
|
else
|
|
|
|
video_default="${video_default}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Ask for video
|
|
|
|
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
|
|
|
|
if [ -z "${video_track}" ] ; then
|
|
|
|
video_track="${video_default}"
|
|
|
|
else
|
|
|
|
video_track="${video_track}"
|
|
|
|
fi
|
|
|
|
# Check the audio track by default
|
|
|
|
audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
|
|
|
|
if [ -z "${audio_default}" ] ; then
|
|
|
|
audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
|
|
|
|
if [ -z "${audio_default}" ] ; then
|
|
|
|
audio_default="0:1"
|
|
|
|
else
|
|
|
|
audio_default_patch=$(echo ${audio_default} | cut -c4)
|
|
|
|
if [ "${audio_default_patch}" == ":" ] ; then
|
|
|
|
audio_default=$(echo ${audio_default} | cut -c1-3)
|
|
|
|
else
|
|
|
|
audio_default="${audio_default}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
audio_default_patch=$(echo ${audio_default} | cut -c4)
|
|
|
|
if [ "${audio_default_patch}" == ":" ] ; then
|
|
|
|
audio_default=$(echo ${audio_default} | cut -c1-3)
|
|
|
|
else
|
|
|
|
audio_default="${audio_default}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Ask for audio
|
|
|
|
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
|
|
|
|
if [ -z "${audio_track}" ] ; then
|
|
|
|
audio_track="${audio_default}"
|
|
|
|
else
|
|
|
|
audio_track="${audio_track}"
|
|
|
|
fi
|
|
|
|
# Ask for bitrate video
|
|
|
|
bitrate_default="${b_vcodec}"
|
|
|
|
echo -n "* (Default: ${b_vcodec}) Type the bitrate (${vcodec}): " ; read bitrate_video
|
|
|
|
if [ -z "${bitrate_video}" ] ; then
|
|
|
|
b_vcodec="${bitrate_default}"
|
|
|
|
else
|
|
|
|
b_vcodec="${bitrate_video}"
|
|
|
|
fi
|
|
|
|
# Reload p_conversion variable
|
|
|
|
if [ -z "${codec_h265_hevc}" ] ; then
|
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
|
|
|
else
|
2021-04-05 11:58:34 +02:00
|
|
|
if [ -z "${hevc_profile_10bit}" ] ; then
|
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
|
|
|
else
|
2023-02-08 19:19:17 +01:00
|
|
|
#p_conversion="-c:v ${vcodec} -x264opts colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084:chromaloc=2 -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
|
|
|
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
|
2021-04-05 11:58:34 +02:00
|
|
|
fi
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
# Ask for patched
|
|
|
|
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
patch_thread="y"
|
|
|
|
else
|
|
|
|
patch_thread="n"
|
|
|
|
fi
|
2021-03-22 17:52:11 +01:00
|
|
|
|
2021-03-28 01:56:41 +01:00
|
|
|
# Check diferent modes
|
|
|
|
if [ "${modeCrop}" == "16:9-crop" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
inputFileSave="${inputFile}"
|
|
|
|
ih_sizeSave="${ih_size}"
|
|
|
|
if [ ${ih_size} -eq 0 ] ; then
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
echo " # Error detecting file resolution. The generic solution is applied (slower)"
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-resize.${v_ext}\""
|
|
|
|
echo ""
|
|
|
|
inputFile="${inputFileOut}-resize.${v_ext}"
|
|
|
|
ih_size="360"
|
|
|
|
else
|
|
|
|
echo " # Error detecting file resolution. The generic solution is applied (slower)"
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} \"${inputFileOut}-resize.${v_ext}\""
|
|
|
|
echo ""
|
|
|
|
inputFile="${inputFileOut}-resize.${v_ext}"
|
|
|
|
ih_size="360"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo " # File detected with resolution" ${resolution_detected} "(ih ${ih_size})"
|
|
|
|
fi
|
|
|
|
echo " # Crop '${inputFile}' from 4:3/IMAX to 16:9 (1.77:1)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
inputFile="${inputFileSave}"
|
|
|
|
ih_size="${ih_sizeSave}"
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
if [ ${ih_size} -eq 0 ] ; then
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-resize.${v_ext}"
|
|
|
|
inputFile="${inputFileOut}-resize.${v_ext}"
|
|
|
|
ih_size="360"
|
|
|
|
else
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} "${inputFileOut}-resize.${v_ext}"
|
|
|
|
inputFile="${inputFileOut}-resize.${v_ext}"
|
|
|
|
ih_size="360"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "4:3-crop" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Crop '${inputFile}' from 16:9 to 4:3 (1.33:1)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "5:4-crop" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Crop '${inputFile}' from 16:9 to 5:4 (1.25:1)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "imax-crop" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Crop '${inputFile}' from 16:9 to IMAX (1.43:1)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${f_conversion_crop} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
|
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
else
|
2022-02-04 16:25:16 +01:00
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion_crop} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "16:9-aspect" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Change '${inputFile}' aspect to 16:9 (stretched)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
else
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
else
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "4:3-aspect" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Change '${inputFile}' aspect to 4:3 (stretched)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
else
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
else
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "${modeCrop}" == "5:4-aspect" ] ; then
|
|
|
|
inputFileOut=$(removeExtension ${inputFile})
|
|
|
|
# Show commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo "* COMMAND THAT WILL BE EXECUTED:"
|
|
|
|
echo ""
|
|
|
|
echo " # File detected with resolution" ${resolution_detected}
|
|
|
|
echo " # Change '${inputFile}' aspect to 5:4 (stretched)"
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
else
|
|
|
|
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
|
|
|
|
fi
|
|
|
|
# Execute commands for conversion
|
|
|
|
echo ""
|
|
|
|
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
|
|
|
|
if [ "${run_commands_ffmpeg}" == "n" ] ; then
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
if [ "${patch_thread}" == "y" ] ; then
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
else
|
|
|
|
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
show_menu
|
|
|
|
fi
|
2021-03-22 17:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Syntax: ks-crop <option> </absolute/path/video.mkv>
|
|
|
|
if [ -z "${1}" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
show_menu
|
|
|
|
exit
|
2021-03-22 17:52:11 +01:00
|
|
|
fi
|
|
|
|
if [ -f "${2}" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "detected" > /dev/null
|
2021-03-22 17:52:11 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
errorReadingFile "${2}"
|
2021-03-22 17:52:11 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Define variables for crop_video function
|
|
|
|
if [ "${1}" == "-16:9-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="16:9-crop"
|
|
|
|
resolution="${to16_9}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-4:3-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="4:3-crop"
|
|
|
|
resolution="${to4_3}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-5:4-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="5:4-crop"
|
|
|
|
resolution="${to5_4}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-imax-crop" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="imax-crop"
|
|
|
|
resolution="${toImax}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-16:9-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="16:9-aspect"
|
|
|
|
resolution="${to16_9}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-4:3-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="4:3-aspect"
|
|
|
|
resolution="${to4_3}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
elif [ "${1}" == "-5:4-aspect" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
modeCrop="5:4-aspect"
|
|
|
|
resolution="${to5_4}"
|
|
|
|
crop_video
|
2021-03-22 17:52:11 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
show_menu
|
2021-03-22 17:52:11 +01:00
|
|
|
fi
|