diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad45f5e --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Pressor + +WARNING : THIS PROGRAM IS EXPERIMENTAL AND COULD BREAK YOUR SYSTEM IF USED BADLY + +## Windows version (pressor.bat) : + +- Pressor is a utility which simplify media batch compressions +- Targetted file formats and default options are editable in the batch file +- Renaming multiple files that have the same exact last + modification date will result in a failure of this feature +- The custom output directory option isn't available yet + +WARNING : THIS FILE IS NO LONGER MAINTAINED + +## Linux version (pressor) : + +- For now, it can be used to compress folders and their subdirectories. +- All options need to be specified in the code itself +- Very experimental, don't use without undertanding the code diff --git a/bin/aomenc b/bin/aomenc new file mode 100755 index 0000000..ee67fc4 Binary files /dev/null and b/bin/aomenc differ diff --git a/bin/avifenc b/bin/avifenc new file mode 100755 index 0000000..48dd3c3 Binary files /dev/null and b/bin/avifenc differ diff --git a/bin/opusdec b/bin/opusdec new file mode 100755 index 0000000..643f6c8 Binary files /dev/null and b/bin/opusdec differ diff --git a/bin/opusenc b/bin/opusenc new file mode 100755 index 0000000..2f4e110 Binary files /dev/null and b/bin/opusenc differ diff --git a/bin/vvenc b/bin/vvenc new file mode 100755 index 0000000..aad0048 Binary files /dev/null and b/bin/vvenc differ diff --git a/experimental/renammer b/experimental/renammer new file mode 100755 index 0000000..bb0ae4e --- /dev/null +++ b/experimental/renammer @@ -0,0 +1,31 @@ +#!/bin/bash + +readarray -t files <<< $(find . -type f) +readarray -t dates <<< $(find . -type f -printf '%CY%Cm%Cd-%CH%CM%CS\n' -type f | sed -E 's:.{11}$::g') +index=0 + +for i in "${files[@]}"; do + if [[ "$i" =~ '20'[1-2][0-9][-|\.|_]*[0-1][0-9][-|\.|_]*[0-3][0-9][-|\.|_]{0,1}[0-9]{0,2}[-|\.|_]{0,1}[0-9]{0,2}[-|\.|_]{0,1}[0-9]{0,2} ]]; then + date="${BASH_REMATCH//[^0-9]/}" + if [[ "${#date}" == 14 ]]; then + date="${date:0:8}_${date:8}" + echo -ne "\e[32m" + else + date="${date:0:8}_000000" + echo -ne "\e[33m" + fi + else + date="${dates[index]}" + echo -ne "\e[31m" + fi + increment=1 + while [[ "$log" =~ "$date" ]]; do + date="${date:0:15}_$increment" + ((increment++)) + done + echo -e "$date\e[35m > \e[0m$i" + log+="$date\n" + ((index++)) +done + +echo -e "${log::-2}" > log diff --git a/experimental/shazam.py b/experimental/shazam.py new file mode 100644 index 0000000..d1bbf87 --- /dev/null +++ b/experimental/shazam.py @@ -0,0 +1,7 @@ +from ShazamAPI import Shazam +import json + +audioFile = open('test/sample.opus', 'rb').read() +shazam = Shazam(audioFile) +recognize = shazam.recognizeSong() +print(json.dumps(next(recognize), sort_keys=True, indent=2)) diff --git a/pressor b/pressor new file mode 100755 index 0000000..38f645b --- /dev/null +++ b/pressor @@ -0,0 +1,250 @@ +#!/bin/bash + +#=-----=# CONFIG #=-----=# + +workingDirectory="$1" +timeAsNames='y' +overwrite='y' +warnings='y' +logging='y' + +videoFormat='av1' +imageFormat='avif' + +threads='12' +crf='45' + +compressVideos='y' +compressImages='y' +compressMusics='n' + +musicBitrate='128' +audioBitrate='64' + +av1Quality='2' +vp9Quality='-5' +avifQuality='0' + +avifMaxQuality='63' +avifMinQuality='0' + +crop='368:448' +doCrop='n' +maxSize='500' +doMaxSize='y' + +#=-=# END OF CONFIG #=-=# + +# initialisation +trap 'echo;exit' 2 3 +if [[ "$compressVideos" != 'y' && "$compressImages" != 'y' && "$compressMusics" != 'y' ]]; then + echo "Compression is disabled in the config" + exit +fi +if [[ -z "$workingDirectory" ]]; then workingDirectory='.'; fi +readarray -t initDates <<< $(find "$workingDirectory" -printf '%Cy%Cm%Cd-%CH%CM%CS\n' -type f | sed -E 's:.{11}$::g') +readarray -t initNames <<< $(find "$workingDirectory" -type f) +readarray -t directories <<< $(find "$workingDirectory" -type d) +if [[ -n "$overwrite" ]]; then + overwrite="-$overwrite" +fi +if [[ -z "${initNames[@]}" ]]; then + echo "Nothing to compress" + exit +fi +if [[ "$doCrop" == 'y' ]]; then + if [[ "$crop" =~ [0-9]*':'[0-9]* ]]; then + args=" -vf scale=$crop:force_original_aspect_ratio=increase,crop=$crop" + fi +fi +if [[ "$doMaxSize" == 'y' ]]; then + if [[ "$maxSize" =~ [0-9]* ]]; then + args=" -vf scale=if(gte(iw\,ih)\,min($maxSize\,iw)\,-2):if(lt(iw\,ih)\,min($maxSize\,ih)\,-2)" + fi +fi + +# compression +for ((i=0; i < "${#initNames[@]}"; i++)); do + + if [[ ! "${initNames[i]}" =~ 'ffmpeg' ]]; then + + if [[ "$timeAsNames" == 'y' ]]; then + finalName="${initNames[i]%/*}/${initDates[i]}" + else + finalName="${initNames[i]%.[a-z]*}" + fi + + type=$(file -i "${initNames[i]}") + type="${type#*: }" + + case "$type" in + + *"image"*) + if [[ "$compressImages" == 'y' ]]; then + + if [[ "$finalName" =~ 'DCIM/' ]]; then + finalName="${finalName/DCIM\//DCIM-ffmpeg\/}" + mkdir -p "${finalName%/*}" + fi + if [[ -z "$checkDCIM" ]]; then + echo "DCIM folder detected. Saving to ${finalName%/*}" + checkDCIM='true' + fi + + if [[ "$imageFormat" == 'avif' ]]; then + if [[ -f "$finalName-ffmpeg.avif" ]]; then echo "This file was already compressed. Skipping"; continue; fi + if [[ "$doMaxSize" == 'y' && "$maxSize" =~ [0-9]* ]]; then + ffmpeg -loglevel error -stats -i "${initNames[i]}" -crf 0 -vf "scale=if(gte(iw\,ih)\,min($maxSize\,iw)\,-2):if(lt(iw\,ih)\,min($maxSize\,ih)\,-2)" "$finalName-temp.png" + toDel="$finalName-temp.png" + initNames[i]="$finalName-temp.png" + fi + avifenc -c aom -j "$threads" -d 8 --min "$avifMinQuality" --max "$avifMaxQuality" -s "$avifQuality" "${initNames[i]}" "$finalName-ffmpeg.avif" + rm "$toDel" + exit + elif [[ "$imageFormat" == 'jpg' ]]; then + if [[ -f "$finalName-ffmpeg.jpg" ]]; then echo "This file was already compressed. Skipping"; continue; fi + ffmpeg -i "${initNames[i]}" "$finalName-ffmpeg.jpg" + else + echo "No valid image format specified" + fi + fi + ;; + + *"audio"*) + if [[ "$compressMusics" == 'y' ]]; then + echo "> ${initNames[i]}" + if [[ "$finalName" =~ [Mm]'usic/' ]]; then + if [[ "$finalName" =~ 'Music/' ]]; then + finalName="${finalName/Music\//Music-ffmpeg\/}" + elif [[ "$finalName" =~ 'music/' ]]; then + finalName="${finalName/music\//music-ffmpeg\/}" + fi + if [[ -z "$checkMusic" ]]; then + echo "Music folder detected. Saving to ${finalName%/*}" + checkMusic='true' + fi + fi + if [[ -f "$finalName-ffmpeg.opus" || "${initNames[i]##*.}" == 'opus' ]]; then + echo "This file was already compressed. Skipping" + else + metadata=$(mediainfo --Output=JSON "${initNames[i]}") + bitrate=$(jq -r .media.track[1].BitRate <<< "$metadata") + metadata=$(jq .media.track[0] <<< "$metadata") + title=$(jq -r .Title <<< "$metadata") + album=$(jq -r .Album <<< "$metadata") + artist=$(jq -r .Performer <<< "$metadata") + genre=$(jq -r .Genre <<< "$metadata") + tracknumber=$(jq -r .Track_Position <<< "$metadata") + date=$(jq -r .Recorded_Date <<< "$metadata") + lyrics=$(jq -r .Lyrics <<< "$metadata") + comment=$(jq -r .Comment <<< "$metadata") + if [[ -z "$title" || -z "$album" || -z "$artist" || -z "$date" || -z "$genre" || -z "$lyrics" || -z "$tracknumber" ]]; then + echo 'WARNING : Metadata is incomplete' + fi + if (( "${bitrate:0:-3}" < "$musicBitrate" )); then + musicBitrate="${bitrate:0:-3}" + echo "WARNING : birate in config > bitrate of music : selecting the original bitrate" + fi + mkdir -p "${finalName%/*}" + ffmpeg -i "${initNames[i]}" -y -loglevel warning -r 1 '/tmp/cover.jpg' + ffmpeg -i "${initNames[i]}" -loglevel warning -f wav - | opusenc --quiet --bitrate "$musicBitrate" --picture '/tmp/cover.jpg' --title "$title" --artist "$artist" --album "$album" --genre "$genre" --date "$date" --tracknumber "$tracknumber" --comment lyrics="$lyrics" --comment comment="$comment" - "$finalName-ffmpeg.opus" 2> /dev/null + if [[ "$?" == '1' ]]; then + echo DEBUG : ffmpeg -i "${initNames[i]}" -loglevel warning -f wav - \| opusenc --quiet --bitrate "$musicBitrate" --picture '/tmp/cover.jpg' --title "$title" --artist "$artist" --album "$album" --genre "$genre" --date "$date" --tracknumber "$tracknumber" --comment lyrics="$lyrics" --comment comment="$comment" - "$finalName-ffmpeg.opus" 2> /dev/null + fi + rm -f '/tmp/cover.jpg' + fi + fi + ;; + + *"video"*|*"binary"*) + + if [[ "$compressVideos" == 'y' ]]; then + if [[ "$type" =~ "video" || "${initNames[i]##*.}" == 'y4m' || "${initNames[i]##*.}" == 'yuv' ]]; then + if [[ -f "$finalName-ffmpeg.mkv" ]]; then echo "This file was already compressed. Skipping"; continue; fi + + if [[ "$finalName" =~ 'DCIM/' ]]; then + finalName="${finalName/DCIM\//DCIM-ffmpeg\/}" + mkdir -p "${finalName%/*}" + fi + if [[ -z "$checkDCIM" ]]; then + echo "DCIM folder detected. Saving to ${finalName%/*}" + checkDCIM='true' + fi + + if [[ "$videoFormat" == 'vp9' ]]; then + + nice ffmpeg -y -i "${initNames[i]}" -loglevel error -stats \ + -c:v libvpx-vp9 -b:v 0 -crf "$crf" $args \ + -aq-mode 2 -an -pix_fmt yuv420p \ + -tile-columns 0 -tile-rows 0 \ + -frame-parallel 0 -cpu-used 8 \ + -auto-alt-ref 1 -lag-in-frames 25 -g 999 \ + -pass 1 -f webm -threads "$threads" \ + /dev/null && \ + nice ffmpeg "$overwrite" -i "${initNames[i]}" -loglevel error -stats \ + -c:v libvpx-vp9 -b:v 0 -crf "$crf" $args \ + -aq-mode 2 -pix_fmt yuv420p -c:a libopus -b:a "$audioBitrate"k \ + -tile-columns 2 -tile-rows 2 \ + -frame-parallel 0 -cpu-used "$vp9Quality" \ + -auto-alt-ref 1 -lag-in-frames 25 \ + -pass 2 -g 999 -threads "$threads" \ + "$finalName-ffmpeg.mkv" && \ + rm ffmpeg2pass-0.log + + elif [[ "$videoFormat" == 'av1' ]]; then + + random="$RANDOM" + nice ffmpeg -y -i "${initNames[i]}" -strict -1 -loglevel error $args \ + -f yuv4mpegpipe - | aomenc - --passes=2 --pass=1 \ + --cpu-used="$av1Quality" --threads="$threads" \ + --end-usage=q --cq-level="$crf" --bit-depth=8 \ + --enable-fwd-kf=1 --kf-max-dist=300 --kf-min-dist=12 \ + --tile-columns=0 --tile-rows=0 --sb-size=64 \ + --lag-in-frames=48 \ + --arnr-strength=2 --arnr-maxframes=3 \ + --aq-mode=0 --deltaq-mode=1 --enable-qm=1 \ + --tune=psnr --tune-content=default \ + --fpf="/tmp/pass-$random" -o NUL && \ + nice ffmpeg "$overwrite" -i "${initNames[i]}" -strict -1 -loglevel error $args \ + -f yuv4mpegpipe - | aomenc - --passes=2 --pass=2 \ + --cpu-used="$av1Quality" --threads="$threads" \ + --end-usage=q --cq-level="$crf" --bit-depth=8 \ + --enable-fwd-kf=1 --kf-max-dist=300 --kf-min-dist=12 \ + --tile-columns=0 --tile-rows=0 --sb-size=64 \ + --lag-in-frames=48 \ + --arnr-strength=2 --arnr-maxframes=3 \ + --aq-mode=0 --deltaq-mode=1 --enable-qm=1 \ + --tune=psnr --tune-content=default \ + --fpf="/tmp/pass-$random" -o "$finalName-video.mkv" && \ + ffmpeg "$overwrite" -loglevel warning -i "$finalName-video.mkv" -i "${initNames[i]}" -map 0:v -c:v copy -map 1:a? -c:a libopus -b:a "$audioBitrate"k -map 0:s? -max_interleave_delta 0 "$finalName-ffmpeg.mkv" && \ + rm "$finalName-video.mkv" + + # elif [[ "$videoFormat" == 'vvc' ]]; then + + # DOES NOT WORK FOR NOW + # vvenc -i "${initNames[i]}" -c yuv420 --preset medium --qp 31 --qpa 0 -ip 64 -t 4 -o "$finalName-ffmpeg.vvc" + + else + echo "No valid video format specified" + fi + fi + fi + ;; + + *) + if [[ "$logging" == 'y' ]]; then + echo "unsupported -> ${initNames[i]} ($type)" >> log + fi + if [[ "$warnings" == 'y' ]]; then + echo -e "\e[31munsupported -> ${initNames[i]} ($type) \e[0m" +# echo "DEBUG : ${initNames[i]##*.} $compressVideos" + fi + ;; + + esac + + else + echo "> ${initNames[i]} (skipped)" + fi + +done diff --git a/pressor.bat b/pressor.bat new file mode 100755 index 0000000..f873ad4 --- /dev/null +++ b/pressor.bat @@ -0,0 +1,258 @@ +@ECHO off + +::--------------------- You can modify the batch file in this area ---------------------- + +:: Edit the file formats targetted here - Do not add any space before and after the line +SET VideoFormats=mp4 mkv m4a m4v f4v f4a m4b m4r f4b mov wmv wma webm flv avi +SET ImageFormats=jpg jpeg png webp tiff tif raw bmp heif heic +SET MusicFormats=mp3 aac flac aiff alac m4a cda wav opus ogg + +:: Edit the default settings here - To remove a default setting, leave empty (spaces aren't allowed) +SET "DisplayText=" &::Display title, warning, documentation, known bugs text (y/n) (blank=y) +SET "input=" &::Set a default path for the input folder (e.g. C:\Users\username\Desktop - Do not add quotation marks) +SET "output=" &::Set a default path for the output folder. Will automatically set CustomOutput to "y" +SET "CustomOutput=n" &::Default answer for the custom output directory prompt. Ignored if the variable "output" has a default path. (y/n) +SET "target=" &::Default answer for types of file targetted (v nor i nor m) (v = videos - i = images - m = musics) +REM SET "SubfolderSearch=" &::Default answer for searching subfolders (y/n) +SET "RenameOutput=" &::Default answer for the rename input option (y/n) +SET "RenameInput=" &::Default answer for the rename output option (y/n). Will set RenameOutput to y +SET "ExcludeCompressed=n" &::Default answer for the exlude already compressed files option (y/n) + +::---------------------------------------------------------------------------------------- + +:: Prerequisites +SETLOCAL enableextensions enabledelayedexpansion +IF /I "%DisplayText%" == "n" GOTO INPUTFORMATTING +FOR /F "delims=: tokens=*" %%A IN ('findstr /B ::: "%~f0"') do @echo(%%A +FOR /F %%A IN ('copy /Z "%~dpf0" NUL') DO SET "CR=%%A" +:RETRYCHOICE0 +IF NOT EXIST "%appdata%\ffmpeg\ffmpeg.exe" NUL && EXIT /B +::: +::: _____ ______ _______ _______ _______ _____ ______ +::: |_____] |_____/ |______ |______ |______ | | |_____/ +::: | | \_ |______ ______| ______| |_____| | \_ +::: +::: WARNING : THIS PROGRAM IS EXPERIMENTAL AND COULD BREAK YOUR SYSTEM IF USED BADLY +::: +::: DOCUMENTATION & BUGS : +::: - Pressor is a utility which simplify media batch compressions. +::: - Targetted file formats and default options are editable in the batch file +::: - Renaming multiple files that have the same exact last +::: modification date will result in a failure of this feature. +::: + +:INPUTFORMATTING +SET BatchVideoFormats1=%VideoFormats: =" "*.% +SET BatchVideoFormats1="*.%BatchVideoFormats1%" +SET BatchImageFormats1=%ImageFormats: =" "*.% +SET BatchImageFormats1="*.%BatchImageFormats1%" +SET BatchMusicFormats1=%MusicFormats: =" "*.% +SET BatchMusicFormats1="*.%BatchMusicFormats1%" +SET BatchVideoFormats2=%VideoFormats: = *.% +SET BatchVideoFormats2=*.%BatchVideoFormats2% +SET BatchImageFormats2=%ImageFormats: = *.% +SET BatchImageFormats2=*.%BatchImageFormats2% +SET BatchMusicFormats2=%MusicFormats: = *.% +SET BatchMusicFormats2=*.%BatchMusicFormats2% +SET PSVideoFormats=%VideoFormats: =','*.% +SET PSVideoFormats='*.%PSVideoFormats%' +SET PSImageFormats=%ImageFormats: =','*.% +SET PSImageFormats='*.%PSImageFormats%' +SET PSMusicFormats=%MusicFormats: =','*.% +SET PSMusicFormats='*.%PSMusicFormats%' + +:INPUT +SET InvalidSkip=false +IF NOT "%input%" == "" GOTO RETRYCHOICE1 +NUL && IF ERRORLEVEL 1 (BREAK) ELSE (SET input=) +IF "%InvalidSkip%" == "true" SET /P retry1= Do you want to retry? (y/n) (blank=n) : +IF "%InvalidSkip%" == "true" SET InvalidSkip=false && GOTO SKIP2 +IF NOT EXIST "%input%" ECHO Invalid input directory && SET /P retry1=Do you want to retry? (y/n) (blank=n) : +:SKIP2 +IF NOT EXIST "%input%" IF /I "%retry1%" == "y" SET input=&& SET retry1=&& GOTO INPUT +IF NOT EXIST "%input%" IF /I "%retry1%" == "n" ECHO Exiting... && PAUSE>NUL && EXIT /B +IF NOT EXIST "%input%" IF "%retry1%" == "" ECHO Exiting... && PAUSE>NUL && EXIT /B +IF NOT EXIST "%input%" IF NOT "%retry1%" == "" ECHO Invalid input "%retry1%" && SET InvalidSkip=true&& GOTO RETRYCHOICE1 +ECHO Input : %input% +CD "%input%" + +:CHECKING +NUL 2>NUL DIR /a-d /s %BatchVideoFormats1% && SET VideoExist=video&& SET FileExist=video&& SET FExist=v&& SET Vexist=v&& SET ToCountFormats=%BatchVideoFormats2%&& SET SLASH1=/&& SET SLASH2=/ +>NUL 2>NUL DIR /a-d /s %BatchImageFormats1% && SET ImageExist=image&& SET FileExist=%FileExist%%SLASH1%image&& SET FExist=%FExist%%SLASH1%i&& SET Iexist=i&& SET ToCountFormats=%ToCountFormats% %BatchImageFormats2%&& SET SLASH2=/ +>NUL 2>NUL DIR /a-d /s %BatchMusicFormats1% && SET MusicExist=music&& SET FileExist=%FileExist%%SLASH2%music&& SET FExist=%FExist%%SLASH2%m&& SET Mexist=m&& SET ToCountFormats=%ToCountFormats% %BatchMusicFormats2% +SET TotalCount=0&& FOR /R %%A IN (%ToCountFormats%) DO SET /a TotalCount+=1 +SET VideoCount=0&& FOR /R %%A IN (%BatchVideoFormats2%) DO SET /a VideoCount+=1 +SET ImageCount=0&& FOR /R %%A IN (%BatchImageFormats2%) DO SET /a ImageCount+=1 +SET MusicCount=0&& FOR /R %%A IN (%BatchMusicFormats2%) DO SET /a MusicCount+=1 +IF "%TotalCount%" LSS "2" (SET TotalCountText=file) ELSE (SET TotalCountText=files) +IF "%VideoCount%" LSS "2" (SET VideoCountText=video) ELSE (SET VideoCountText=videos) +IF "%ImageCount%" LSS "2" (SET ImageCountText=image) ELSE (SET ImageCountText=images) +IF "%MusicCount%" LSS "2" (SET MusicCountText=music) ELSE (SET MusicCountText=musics) +ECHO Detected : %TotalCount% %TotalCountText% (%VideoCount% %VideoCountText%, %ImageCount% %ImageCountText%, %MusicCount% %MusicCountText%) +IF "%VideoExist%" == "" IF "%ImageExist%" == "" IF "%MusicExist%" == "" ECHO Input doesn't contain convertable files && SET InvalidSkip=true&& SET input=&& GOTO RETRYCHOICE1 + +:CUSTOMOUTPUT +IF NOT "%output%" == "" GOTO OUTPUTCHECK +IF NOT "%CustomOutput%" == "" GOTO SKIP1 +SET /P CustomOutput=Set a custom output directory? (y/n) (blank=n) : && !CR! +:SKIP1 +IF /I "%CustomOutput%" == "y" GOTO OUTPUT +IF /I "%CustomOutput%" == "n" GOTO TARGET +IF /I "%CustomOutput%" == "" GOTO TARGET +ECHO Invalid custom input "%CustomOutput%" +SET CustomOutput=&& GOTO CUSTOMOUTPUT + +:OUTPUT +SET output= +NUL && IF ERRORLEVEL 1 (BREAK) ELSE (SET output=) +IF NOT EXIST "%output%" ECHO Invalid output directory "%output%" && SET /P retry2=Do you want to retry? (y/n) (blank=n) : +IF NOT EXIST "%output%" IF /I "%retry2%" == "y" GOTO OUTPUT +IF NOT EXIST "%output%" IF /I "%retry2%" == "n" ECHO Exiting... && PAUSE>NUL && EXIT /B +IF NOT EXIST "%output%" IF /I "%retry2%" == "" ECHO Exiting... && PAUSE>NUL && EXIT /B +IF "%output%" == "%input%" SET CustomOutput=n +ECHO Output : %output% + +:TARGET +IF "%Vexist%" == "v" IF "%Iexist%" == "" IF "%Mexist%" == "" SET TargetVideo=true&& GOTO SENDTO1 +IF "%Vexist%" == "" IF "%Iexist%" == "i" IF "%Mexist%" == "" SET TargetImage=true&& GOTO SENDTO1 +IF "%Vexist%" == "" IF "%Iexist%" == "" IF "%Mexist%" == "m" SET TargetMusic=true&& GOTO SENDTO1 +IF NOT "%target%" == "" GOTO SKIP2 +SET /P target=Target !FileExist! files? (!FExist!) (blank=!Vexist!!Iexist!!Mexist!) : +IF "%target%" == "" IF "%Vexist%" == "v" SET TargetVideo=true +IF "%target%" == "" IF "%Iexist%" == "i" SET TargetImage=true +IF "%target%" == "" IF "%Mexist%" == "m" SET TargetMusic=true +:SKIP2 +ECHO %target% | find /I "v" >NUL && IF ERRORLEVEL 1 (BREAK) ELSE (IF "%Vexist%" == "v" SET TargetVideo=true) +ECHO %target% | find /I "i" >NUL && IF ERRORLEVEL 1 (BREAK) ELSE (IF "%Iexist%" == "i" SET TargetImage=true) +ECHO %target% | find /I "m" >NUL && IF ERRORLEVEL 1 (BREAK) ELSE (IF "%Mexist%" == "m" SET TargetMusic=true) +:SENDTO1 +IF "%TargetVideo%" == "true" SET PSformats=%PSVideoFormats%&& SET VIRGULE1=,&&SET VIRGULE2=, +IF "%TargetImage%" == "true" SET PSformats=%PSFormats%%VIRGULE1%%PSImageFormats%&& SET VIRGULE2=, +IF "%TargetMusic%" == "true" SET PSformats=%PSFormats%%VIRGULE2%%PSMusicFormats% +IF NOT "%PSFormats%" == "" GOTO RENAMEOPTIONS +ECHO Invalid file format input "!target!" +SET target=&& GOTO TARGET + +:RENAMEOPTIONS +IF "%RenameInput%" == "y" SET RenameOutput=y&& powershell -command "Get-ChildItem -Recurse %PSformats% | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + ' input' + $_.Extension }" && GOTO EXCLUDECOMPRESSED +IF "%RenameInput%" == "n" GOTO EXCLUDECOMPRESSED +IF NOT "%RenameInput%" == "" ECHO Invalid "rename input" answer. +IF "%RenameOutput%" == "y" GOTO RENAMEADDINPUT +IF "%RenameOutput%" == "n" GOTO RENAMEADDINPUT +IF NOT "%RenameOutput%" == "" ECHO Invalid "rename output" answer. +SET /P rename=Rename files to timestamps ? (i=input+output / o=output / e=exclusively / n) (blank=n) : +:SKIP3 +IF "%rename%" == "" GOTO RENAMEADDINPUT +ECHO %rename% | find /I "i" >NUL && IF ERRORLEVEL 1 (BREAK) ELSE (SET RenameInput=y) +ECHO %rename% | find /I "o" >NUL && IF ERRORLEVEL 1 (BREAK) ELSE (SET RenameOutput=y) +IF "%RenameInput%" == "y" SET RenameOutput=y&& powershell -command "Get-ChildItem -Recurse %PSformats% | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + ' input' + $_.Extension }" && GOTO EXCLUDECOMPRESSED +IF "%RenameOutput%" == "y" GOTO RENAMEADDINPUT +IF /I "%rename%" == "e" powershell -command "Get-ChildItem -Recurse %PSformats% | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + $_.Extension }" && ECHO Done && PAUSE>NUL && EXIT /B +IF /I "%rename%" == "n" GOTO EXCLUDECOMPRESSED +IF /I "%rename%" == "" GOTO EXCLUDECOMPRESSED +SET RenameInput=&& SET RenameOutput= +ECHO Invalid renaming option "%rename%" +SET rename=&& GOTO RENAMEOPTIONS + +:RENAMEADDINPUT +powershell -command "Get-ChildItem -Recurse %PSformats% | Rename-Item -NewName {$_.Name -replace ' input', '' }" +powershell -command "Get-ChildItem -Recurse %PSformats% | Rename-Item -NewName { $_.Basename + ' input' + $_.Extension }" + +:EXCLUDECOMPRESSED +SET excluded= ffmpeg +IF "%ExcludeCompressed%" == "y" GOTO SENDTO2 +IF "%ExcludeCompressed%" == "n" SET excluded=&& GOTO SENDTO2 +IF NOT "%ExcludeCompressed%" == "" ECHO Invalid input "%ExcludeCompressed%" as the answer for the exclude compressed files prompt +SET ExcludeCompressed=undefined +SET BatchFormats=%PSFormats:'=% +SET BatchFormats=%BatchFormats:,= % +FOR /R %%i IN (%BatchFormats%) DO ((ECHO "%%i" | FIND " ffmpeg" 1>NUL) && (SET ConvertedFiles=true)) +IF "%ConvertedFiles%" == "true" SET /P ExcludeCompressed=Exclude already compressed files (ending with "ffmpeg") ? (y/n) (blank=y) : +IF "%ExcludeCompressed%" == "y" GOTO SENDTO2 +IF "%ExcludeCompressed%" == "undefined" GOTO SENDTO2 +IF "%ExcludeCompressed%" == "n" SET excluded=&& GOTO SENDTO2 +ECHO Invalid input "%ExcludeCompressed%" + +:SENDTO2 +IF "%TargetVideo%" == "true" GOTO VIDEOOPTIONS +IF "%TargetImage%" == "true" GOTO IMAGEOPTIONS +IF "%TargetMusic%" == "true" GOTO MUSICOPTIONS + +:VIDEOOPTIONS +:: options here +::-vf "transpose=1,2,3" +::-b:v 5000k +IF "%TargetImage%" == "true" GOTO IMAGEOPTIONS +IF "%TargetMusic%" == "true" GOTO MUSICOPTIONS +GOTO SENDTO3 + +:IMAGEOPTIONS +:: options here +::-vf "transpose=1,2,3" +IF "%TargetMusic%" == "true" GOTO MUSICOPTIONS +GOTO SENDTO3 + +:MUSICOPTIONS +:: options here +GOTO SENDTO3 + +:SENDTO3 +IF "%TargetVideo%" == "true" GOTO COMPRESSIONVIDEO +IF "%TargetImage%" == "true" GOTO COMPRESSIONIMAGE +IF "%TargetMusic%" == "true" GOTO COMPRESSIONMUSIC + +:COMPRESSIONVIDEO +FOR /R %%i IN (%BatchVideoFormats2%) DO ( + (ECHO "%%i" | FIND "%excluded%" 1>NUL) || ( + %appdata%\ffmpeg\ffmpeg.exe -loglevel error -stats -i "%%~fi" -c:v hevc_amf -c:a libopus -b:a 128k -maxrate 192k -minrate 64k -strict -2 -b:v 5000k "%%~dpni ffmpeg.mp4" + powershell ^(ls '%%~dpni ffmpeg.mp4'^).CreationTime = ^(ls '%%~fi'^).CreationTime + powershell ^(ls '%%~dpni ffmpeg.mp4'^).LastWriteTime = ^(ls '%%~fi'^).LastWriteTime + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.mp4' | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + ' ffmpeg' + $_.Extension }" + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.mp4' | Rename-Item -NewName {$_.Name -replace ' input', '' }" + ) + ) +IF "%TargetImage%" == "true" GOTO COMPRESSIONIMAGE +IF "%TargetMusic%" == "true" GOTO COMPRESSIONMUSIC +GOTO END + +:COMPRESSIONIMAGE +FOR /R %%i IN (%BatchImageFormats2%) DO ( + (ECHO "%%i" | FIND "%excluded%" 1>NUL) || ( + %appdata%\ffmpeg\ffmpeg.exe -loglevel error -stats -i "%%~fi" "%%~dpni ffmpeg.jpg" + powershell ^(ls '%%~dpni ffmpeg.jpg'^).CreationTime = ^(ls '%%~fi'^).CreationTime + powershell ^(ls '%%~dpni ffmpeg.jpg'^).LastWriteTime = ^(ls '%%~fi'^).LastWriteTime + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.jpg' | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + ' ffmpeg' + $_.Extension }" + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.jpg' | Rename-Item -NewName {$_.Name -replace ' input', '' }" + ) + ) +IF "%TargetMusic%" == "true" GOTO COMPRESSIONMUSIC +GOTO END + +:COMPRESSIONMUSIC +FOR /R %%i IN (%BatchMusicFormats2%) DO ( + (ECHO "%%i" | FIND "%excluded%" 1>NUL) || ( + %appdata%\ffmpeg\ffmpeg.exe -loglevel error -stats -i "%%~fi" -b:a 128k -maxrate 192k "%%~dpni ffmpeg.mp3" + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.mp3' | Rename-Item -NewName { $_.LastWriteTime.toString(\"yyyy MM-dd HH-mm\") + ' ffmpeg' + $_.Extension }" + IF "%RenameOutput%" == "y" powershell -command "Get-ChildItem '%%~dpni ffmpeg.mp3' | Rename-Item -NewName {$_.Name -replace ' input', '' }" + ) + ) + +:END +ENDLOCAL && ECHO Done && IF NOT "%output%" == "" (explorer "%output%") ELSE (explorer "%input%") +PAUSE>NUL && EXIT /B