Added function for detecting proper resolution scaling

This commit is contained in:
q3aql 2023-05-22 15:31:27 +02:00
parent bb45e2fe88
commit e2e801e741
6 changed files with 234 additions and 12 deletions

View File

@ -2,12 +2,12 @@
################################################## ##################################################
# ks-av1 (ks-tools) - Convert video to AV1 codec # # ks-av1 (ks-tools) - Convert video to AV1 codec #
# Date: 09-03-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
################################################## ##################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="090323" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -48,6 +48,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -84,6 +119,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -96,6 +132,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed

View File

@ -2,12 +2,12 @@
############################################################ ############################################################
# ks-av1s (ks-tools) - Convert video to AV1 codec (Series) # # ks-av1s (ks-tools) - Convert video to AV1 codec (Series) #
# Date: 12-03-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
############################################################ ############################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="120323" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -48,6 +48,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -84,6 +119,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -96,6 +132,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed

View File

@ -2,12 +2,12 @@
############################################################### ###############################################################
# ks-avi (ks-tools) - Convert video to AVI format # # ks-avi (ks-tools) - Convert video to AVI format #
# Date: 19-02-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
############################################################### ###############################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="190223" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -51,6 +51,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -104,6 +140,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed

View File

@ -2,12 +2,12 @@
############################################################### ###############################################################
# ks-mp4 (ks-tools) - Convert video to MP4 format # # ks-mp4 (ks-tools) - Convert video to MP4 format #
# Date: 19-03-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
############################################################### ###############################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="190323" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -51,6 +51,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -104,6 +140,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed

View File

@ -2,12 +2,12 @@
############################################################### ###############################################################
# ks-mp4k (ks-tools) - Convert video to MP4 format (4K) # # ks-mp4k (ks-tools) - Convert video to MP4 format (4K) #
# Date: 19-02-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
############################################################### ###############################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="190223" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -51,6 +51,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -104,6 +140,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed

View File

@ -2,12 +2,12 @@
############################################################### ###############################################################
# ks-mp4s (ks-tools) - Convert video to MP4 format (Series) # # ks-mp4s (ks-tools) - Convert video to MP4 format (Series) #
# Date: 19-02-2023 # # Date: 22-05-2023 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
############################################################### ###############################################################
VERSION="8.5-dev" VERSION="8.5-dev"
M_DATE="190223" M_DATE="220523"
# Detect version ffmpeg for old releases # Detect version ffmpeg for old releases
ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1) ffmpeg_version=$(ffmpeg -version 2>&1 | grep version | head -1 | cut -d " " -f 3 | cut -d "." -f 1)
@ -51,6 +51,41 @@ if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
source "/usr/bin/cygwin-alias.sh" source "/usr/bin/cygwin-alias.sh"
fi fi
# Setting the correct resolution for the video file
# Sintaxis: set_resolution <resolution> <file>
function set_resolution() {
check_calc_app_directories="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin"
set_rel="${1}"
input_video_file="${2}"
calc_found="1"
for file in ${check_calc_app_directories} ; do
if [ -f ${file}/calc ] ; then
calc_found=0
fi
done
if [ ${calc_found} -eq 0 ] ; then
file_rel=$(ffmpeg -i "${2}" 2>&1 | grep Stream | grep Video: | grep -Po '\d{3,5}x\d{3,5}')
if [ -z "${file_rel}" ] ; then
echo ${set_rel}
else
file_rel_width=$(echo ${file_rel} | cut -d "x" -f 1)
file_rel_height=$(echo ${file_rel} | cut -d "x" -f 2)
set_rel_width=$(echo ${set_rel} | cut -d "x" -f 1)
aspect_rel=$(calc ${file_rel_width} / ${file_rel_height} | tr -s "~" " ")
new_rel_height=$(calc ${set_rel_width} / ${aspect_rel} | cut -d "." -f 1 | tr -s "~" " ")
even_number=$(calc ${new_rel_height} % 2)
if [ ${even_number} -ne 0 ] ; then
new_rel_height=$(calc ${new_rel_height} + 1)
fi
set_rel_width=$(echo ${set_rel_width})
new_rel_height=$(echo ${new_rel_height})
echo ${set_rel_width}x${new_rel_height}
fi
else
echo ${set_rel}
fi
}
# Create inicial config file # Create inicial config file
mkdir -p ${configFolder} mkdir -p ${configFolder}
if [ -f ${configFile} ] ; then if [ -f ${configFile} ] ; then
@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
fi fi
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
else else
echo "#!/bin/bash" > ${configFile} echo "#!/bin/bash" > ${configFile}
echo "" >> ${configFile} echo "" >> ${configFile}
@ -104,6 +140,7 @@ else
echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "default_lang_subt=${default_lang_subt}" >> ${configFile}
echo "v_ext=${v_ext}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile}
source ${configFile} source ${configFile}
rel_size=$(set_resolution ${rel_size} "${1}")
fi fi
# Check if ffmpeg is installed # Check if ffmpeg is installed