From e2e801e7412a43d916a6634df3a12853e13bdfed Mon Sep 17 00:00:00 2001 From: q3aql Date: Mon, 22 May 2023 15:31:27 +0200 Subject: [PATCH] Added function for detecting proper resolution scaling --- src/ks-av1 | 41 +++++++++++++++++++++++++++++++++++++++-- src/ks-av1s | 41 +++++++++++++++++++++++++++++++++++++++-- src/ks-avi | 41 +++++++++++++++++++++++++++++++++++++++-- src/ks-mp4 | 41 +++++++++++++++++++++++++++++++++++++++-- src/ks-mp4k | 41 +++++++++++++++++++++++++++++++++++++++-- src/ks-mp4s | 41 +++++++++++++++++++++++++++++++++++++++-- 6 files changed, 234 insertions(+), 12 deletions(-) diff --git a/src/ks-av1 b/src/ks-av1 index dd7e679..65524a3 100755 --- a/src/ks-av1 +++ b/src/ks-av1 @@ -2,12 +2,12 @@ ################################################## # ks-av1 (ks-tools) - Convert video to AV1 codec # -# Date: 09-03-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ################################################## VERSION="8.5-dev" -M_DATE="090323" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -84,6 +119,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -96,6 +132,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed diff --git a/src/ks-av1s b/src/ks-av1s index 7745fa5..e4bc05e 100755 --- a/src/ks-av1s +++ b/src/ks-av1s @@ -2,12 +2,12 @@ ############################################################ # ks-av1s (ks-tools) - Convert video to AV1 codec (Series) # -# Date: 12-03-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################ VERSION="8.5-dev" -M_DATE="120323" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -84,6 +119,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -96,6 +132,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed diff --git a/src/ks-avi b/src/ks-avi index d45a231..f30dd81 100755 --- a/src/ks-avi +++ b/src/ks-avi @@ -2,12 +2,12 @@ ############################################################### # ks-avi (ks-tools) - Convert video to AVI format # -# Date: 19-02-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################### VERSION="8.5-dev" -M_DATE="190223" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -104,6 +140,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed diff --git a/src/ks-mp4 b/src/ks-mp4 index d39188f..16af41b 100755 --- a/src/ks-mp4 +++ b/src/ks-mp4 @@ -2,12 +2,12 @@ ############################################################### # ks-mp4 (ks-tools) - Convert video to MP4 format # -# Date: 19-03-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################### VERSION="8.5-dev" -M_DATE="190323" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -104,6 +140,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed diff --git a/src/ks-mp4k b/src/ks-mp4k index 583bd5b..826d3d4 100755 --- a/src/ks-mp4k +++ b/src/ks-mp4k @@ -2,12 +2,12 @@ ############################################################### # ks-mp4k (ks-tools) - Convert video to MP4 format (4K) # -# Date: 19-02-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################### VERSION="8.5-dev" -M_DATE="190223" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -104,6 +140,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed diff --git a/src/ks-mp4s b/src/ks-mp4s index 5befc7b..829bb1e 100755 --- a/src/ks-mp4s +++ b/src/ks-mp4s @@ -2,12 +2,12 @@ ############################################################### # ks-mp4s (ks-tools) - Convert video to MP4 format (Series) # -# Date: 19-02-2023 # +# Date: 22-05-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################### VERSION="8.5-dev" -M_DATE="190223" +M_DATE="220523" # Detect version ffmpeg for old releases 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" fi +# Setting the correct resolution for the video file +# Sintaxis: set_resolution +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 mkdir -p ${configFolder} if [ -f ${configFile} ] ; then @@ -91,6 +126,7 @@ if [ -f ${configFile} ] ; then echo "v_ext=${v_ext}" >> ${configFile} fi source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") else echo "#!/bin/bash" > ${configFile} echo "" >> ${configFile} @@ -104,6 +140,7 @@ else echo "default_lang_subt=${default_lang_subt}" >> ${configFile} echo "v_ext=${v_ext}" >> ${configFile} source ${configFile} + rel_size=$(set_resolution ${rel_size} "${1}") fi # Check if ffmpeg is installed