General Release (#1)
* Add two new location shorcuts and a fix for ffmpeg. * Add comments and a quick commit function. * More fixes and enhancements. * Enhance ffmpeg command with resolution changing. * Try fixing the test function. * Prevent situations such as possibly deleting a home directory. * Use dev branch for testing. Add man to software. * Always accept. * Do not cd as part of bashrc. * Try fixing path issue. * Try fixing PROG from just saying bash. * More path and PROG fixes. * Final cleanups. Seems good now. * test-termux works great now! * Add aliases for reloading the Termux config project (this Git repo). * Add missing slash. * Fix double flagging bitrates. * Show the ffmpeg command. Print file sizes. Planning to come back later with a laptop and clean up tabs vs spaces. Difficult to manage on a phone. * Move input to be before options. * Fix filter parameters. * Remove single quotes. * Fix typos. * Add more shortcut aliases. * Add more packages. * Update instructions and mention shortcut aliases. * Fix extra period. * Add more aliases. * Add extra detail to final instruction. * Better formatting on new text. * Add aliases, fix spaces to tabs. * Change order of parameters so that size is first. * Add wget to default packages. * Add two-pass processing. * More changes for 2-pass. * Add ability to still do 1 pass. Add sync before filesize check. Clean 2-pass files. * Add better chance of getting correct filesize with a sleep. Make ffmpeg 2 pass file name more explicit. * Change to maxrate from b:v so that ffmpeg can determine the best rate per frame. * First attempt at adding basic-process for a more flexible ffmpeg experience. * Multiple bugfixes and enhancements for video functions. * Only remove first pass files if everything succeeded. Sleep before doing IF for file size.
This commit is contained in:
parent
f1887073ec
commit
6a9f363771
10
README.md
10
README.md
@ -22,8 +22,8 @@ Hyperling's scripts for a productive Termux environment.
|
|||||||
chmod 755 *.sh
|
chmod 755 *.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Make any modifications to the env.example file
|
1. Make any modifications to the env.example file.
|
||||||
- Only if you do not already have a ~/.env file
|
- Only if you do not already have ~/.env already.
|
||||||
|
|
||||||
1. Run the deployment script.
|
1. Run the deployment script.
|
||||||
|
|
||||||
@ -31,12 +31,14 @@ Hyperling's scripts for a productive Termux environment.
|
|||||||
./setup.sh
|
./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
1. All done!
|
1. All done. Be sure to source your new `.bashrc`!
|
||||||
|
|
||||||
# Updates
|
# Updates
|
||||||
|
|
||||||
Each program is developed to be run numerous times, so all that needs done is following the Install instructions again.
|
Each program is developed to be run numerous times, so all that needs done is following the Install instructions again.
|
||||||
|
|
||||||
|
Shortcuts for this exist after the initial install, such as running `termux-reload` then `bash-reload`.
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|
||||||
Since the project self-destructs, it is recommended to copy the folder for each run, then execute the copied files.
|
Since the project self-destructs, it is recommended to copy the folder for each run, then execute the copied files.
|
||||||
@ -47,3 +49,5 @@ cd ~/termux-copy
|
|||||||
chmod 755 *.sh
|
chmod 755 *.sh
|
||||||
./setup.sh
|
./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or use the `test-termux` command if the project is already loaded.
|
||||||
|
268
bashrc.sh
268
bashrc.sh
@ -14,73 +14,257 @@ else
|
|||||||
alias prod="echo 'ERROR: .env not set up properly, please fix and reload RC.'"
|
alias prod="echo 'ERROR: .env not set up properly, please fix and reload RC.'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Easily get to storage device.
|
# Quickies
|
||||||
export SS="~/storage/shared/"
|
alias reload-bash="source ~/.bashrc"
|
||||||
|
alias bash-reload="reload-bash"
|
||||||
|
alias reload="reload-bash"
|
||||||
|
|
||||||
|
# Easily get to storage devices.
|
||||||
|
export SS="~/storage/shared"
|
||||||
alias ss="cd $SS"
|
alias ss="cd $SS"
|
||||||
alias sd="ss"
|
alias sd="ss"
|
||||||
alias storage="ss"
|
alias storage="ss"
|
||||||
alias home="ss"
|
alias home="ss"
|
||||||
|
|
||||||
# Help Prevent Mistakes
|
# Shortcut to media.
|
||||||
|
export DCIM="$SS/DCIM/Camera"
|
||||||
|
alias dcim="cd $DCIM"
|
||||||
|
|
||||||
|
# Shortcut to Code
|
||||||
|
export CODE="$SS/Code"
|
||||||
|
alias code="cd $CODE"
|
||||||
|
|
||||||
|
# Shortcuts for TRASH.
|
||||||
|
export TRASH="$SS/TRASH"
|
||||||
|
alias trash="cd $TRASH"
|
||||||
|
alias clean-trash="bash -c 'rm -rfv $TRASH/*'"
|
||||||
|
alias trash-clean="clean-trash"
|
||||||
|
alias check-trash="du -h $TRASH"
|
||||||
|
alias trash-check="check-trash"
|
||||||
|
|
||||||
|
# Help prevent mistakes.
|
||||||
alias cp="cp -v"
|
alias cp="cp -v"
|
||||||
alias mv="mv -v"
|
alias mv="mv -v"
|
||||||
alias rm="echo 'Move to ~/storage/shared/TRASH/ instead!'"
|
alias rm="echo 'Move to ~/storage/shared/TRASH/ instead!'"
|
||||||
|
|
||||||
|
# Quickies
|
||||||
|
alias update="pkg update && pkg upgrade"
|
||||||
|
alias bye="exit"
|
||||||
|
alias goodbye="update -y && bye"
|
||||||
|
alias install="pkg install"
|
||||||
|
|
||||||
## Functions ##
|
## Functions ##
|
||||||
|
|
||||||
|
# Optimize the bitrate and audio levels for an edited video.
|
||||||
function process-video-usage {
|
function process-video-usage {
|
||||||
echo "USAGE: process-video oldFile newFile [videoBitrate] [audioBitrate]"
|
echo "USAGE: process-video oldFile newFile [videoBitrate] [audioBitrate] [sizeRating]"
|
||||||
echo "Call ffmpeg with preferred video posting settings."
|
echo -n "Purpose: Call ffmpeg with preferred video posting settings. "
|
||||||
|
echo -n "Bitrates default to 2000k and 192k, size is 720. "
|
||||||
|
echo "These work well on Odysee and are fairly small as backups."
|
||||||
|
echo "Examples:"
|
||||||
|
echo "- Create a small file for quick streaming."
|
||||||
|
echo " process-video youcut.mp4 20240210.mp4 1200k 128k 480"
|
||||||
|
echo "- Create a larger file for something like YouTube."
|
||||||
|
echo " process-video youcut.mp4 20240210_1080p.mp4 5000k 256k 1080"
|
||||||
}
|
}
|
||||||
|
|
||||||
function process-video {
|
function process-video {
|
||||||
# Parameters
|
# Parameters
|
||||||
file="$1"
|
file="$1"
|
||||||
newfile="$2"
|
newfile="$2"
|
||||||
video="$3"
|
video="$3"
|
||||||
audio="$4"
|
audio="$4"
|
||||||
|
size="$5"
|
||||||
|
passes="$6"
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
if [[ -z $file || ! -e $file ]]; then
|
if [[ -z $file || ! -e $file ]]; then
|
||||||
echo "ERROR: Original file '$file' does not exist." >&2
|
echo "ERROR: Original file '$file' does not exist." >&2
|
||||||
process-video-usage
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z $newfile || -e $newfile ]]; then
|
|
||||||
echo "ERROR: New file '$newfile' already exists." >&2
|
|
||||||
process-video-usage
|
|
||||||
elif [[ -e $newfile ]]; then
|
|
||||||
echo "ERROR: New file '$newfile' already exists." >&2
|
|
||||||
process-video-usage
|
process-video-usage
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $video ]]; then
|
if [[ -z $newfile ]]; then
|
||||||
video="-b:v 2000k"
|
echo "ERROR: New file's name must be provided." >&2
|
||||||
else
|
process-video-usage
|
||||||
video="-b:v $video"
|
return 1
|
||||||
fi
|
elif [[ -e $newfile ]]; then
|
||||||
|
echo "ERROR: New file '$newfile' already exists." >&2
|
||||||
|
du -h "$newfile"
|
||||||
|
process-video-usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z $audio ]]; then
|
echo "`date` - Converting '$file' to '$newfile'."
|
||||||
audio="-b:a 192k"
|
|
||||||
else
|
|
||||||
audio="-b:a $audio"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "`date` - Converting '$file' to '$newfile' using '$video $audio'"
|
if [[ -z $video ]]; then
|
||||||
|
video="2000k"
|
||||||
|
fi
|
||||||
|
video="-maxrate $video"
|
||||||
|
|
||||||
# Main
|
if [[ -z $audio ]]; then
|
||||||
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
audio="192k"
|
||||||
$video $audio -movflags +faststart \
|
fi
|
||||||
-af "dynaudnorm=f=33:g=65:p=0.66:m=33." \
|
audio="-b:a $audio"
|
||||||
-i "$file" "$newfile"
|
|
||||||
|
if [[ -z $size ]]; then
|
||||||
|
size="720"
|
||||||
|
fi
|
||||||
|
size="-filter:v scale=-1:$size"
|
||||||
|
|
||||||
|
if [[ $passes != 1 ]]; then
|
||||||
|
passes=2
|
||||||
|
pass="-pass 2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
# More information on two-pass processing with ffmpeg
|
||||||
|
# https://cinelerra-gg.org/download/CinelerraGG_Manual/Two_pass_Encoding_with_FFmp.html
|
||||||
|
if [[ $passes == 2 ]]; then
|
||||||
|
set -x
|
||||||
|
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||||
|
-i "$file" $size $video $audio \
|
||||||
|
-filter:a "dynaudnorm=f=33:g=65:p=0.66:m=33.3" \
|
||||||
|
-vcodec libx264 -movflags +faststart \
|
||||||
|
-pass 1 -f mp4 /dev/null -y &&
|
||||||
|
set +x &&
|
||||||
|
echo "`date` - Done with the first pass." ||
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -x &&
|
||||||
|
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||||
|
-i "$file" $size $video $audio \
|
||||||
|
-filter:a "dynaudnorm=f=33:g=65:p=0.66:m=33.3" \
|
||||||
|
-vcodec libx264 -movflags +faststart \
|
||||||
|
$pass "$newfile"
|
||||||
status="$?"
|
status="$?"
|
||||||
|
set +x
|
||||||
|
echo "`date` - Done with the final pass."
|
||||||
|
|
||||||
|
if [[ $passes == 2 && $status == 0 ]]; then
|
||||||
|
mv -v ffmpeg2pass*.log* ~/TRASH/
|
||||||
|
fi
|
||||||
|
|
||||||
|
sync
|
||||||
|
sleep 5
|
||||||
|
if [[ -s $newfile ]]; then
|
||||||
|
echo "`date` - Getting file sizes."
|
||||||
|
du -h "$file"
|
||||||
|
du -h "$newfile"
|
||||||
|
else
|
||||||
|
echo "ERROR: New file not created or has a 0 size." >&2
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "\n`date` - Finished with status '$status'."
|
echo -e "\n`date` - Finished with status '$status'."
|
||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
|
alias pv="process-video"
|
||||||
|
|
||||||
cd ~/storage/shared/
|
# Quickly commit code to a repo.
|
||||||
|
function commit {
|
||||||
|
message="$1"
|
||||||
|
if [[ -z $message ]]; then
|
||||||
|
echo "ERROR: A message is required." >&2
|
||||||
|
echo 'USAGE: commit "My commit message."' >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
git add . && git commit -m "$message" && git push
|
||||||
|
}
|
||||||
|
|
||||||
echo "'$0' completed!"
|
# Easily test this project after committing changes.
|
||||||
|
# Otherwise can just source this file unless testing setup.sh.
|
||||||
|
function test-termux {
|
||||||
|
sh -c "rm -rf ~/termux-deleteme ~/TRASH/termux-deleteme" 2>/dev/null
|
||||||
|
git clone https://github.com/Hyperling/Termux ~/termux-deleteme --branch=dev
|
||||||
|
chmod 755 ~/termux-deleteme/*.sh
|
||||||
|
~/termux-deleteme/setup.sh
|
||||||
|
}
|
||||||
|
alias reload-termux="test-termux"
|
||||||
|
alias termux-test="test-termux"
|
||||||
|
alias termux-reload="reload-termux"
|
||||||
|
|
||||||
|
# Allow converting video to audio ad other smaller
|
||||||
|
# tasks than what process-video is intended to do.
|
||||||
|
function basic-process-usage {
|
||||||
|
echo "basic-process INPUT OUTPUT NORMALIZE [EXTRA]"
|
||||||
|
echo -n "Pass a file through ffmpeg with the option"
|
||||||
|
echo "to easily normalize the audio with a Y."
|
||||||
|
echo "Examples:"
|
||||||
|
echo "- Normalize audio on a video."
|
||||||
|
echo " basic-process video.mp4 normalized.mp4 Y"
|
||||||
|
echo "- Convert a video to audio at 192k."
|
||||||
|
echo " basic-process video.mp4 audio.mp3 N '-b:a 192k'"
|
||||||
|
}
|
||||||
|
function basic-process {
|
||||||
|
# Parameters
|
||||||
|
input="$1"
|
||||||
|
output="$2"
|
||||||
|
typeset -u normalize
|
||||||
|
normalize="$3"
|
||||||
|
extra="$4"
|
||||||
|
|
||||||
|
echo "`date` - Starting basic-process"
|
||||||
|
|
||||||
|
# Validations
|
||||||
|
if [[ -z $input || ! -e $input ]]; then
|
||||||
|
echo "ERROR: Input file '$input' does not exist." >&2
|
||||||
|
basic-process-usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $output ]]; then
|
||||||
|
echo "ERROR: Output file's name must be provided." >&2
|
||||||
|
basic-process-usage
|
||||||
|
return 1
|
||||||
|
elif [[ -e $output ]]; then
|
||||||
|
echo "ERROR: Output file '$output' already exists." >&2
|
||||||
|
du -h "$output"
|
||||||
|
basic-process-usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $normalize == "Y" ]]; then
|
||||||
|
echo "Normalize set to TRUE."
|
||||||
|
normal="-filter:a dynaudnorm=f=33:g=65:p=0.66:m=33.3"
|
||||||
|
else
|
||||||
|
echo "No audio normalization is being done."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main
|
||||||
|
echo "`date` - Converting '$input' to '$output'."
|
||||||
|
set -x
|
||||||
|
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||||
|
-i "$input" $extra $normal "$output"
|
||||||
|
status=$?
|
||||||
|
set +x
|
||||||
|
|
||||||
|
if [[ $status != 0 ]]; then
|
||||||
|
echo "`date` - WARNING: ffmpeg exited with status '$status'." >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Finish
|
||||||
|
if [[ ! -s $output ]]; then
|
||||||
|
echo "`date` - ERROR: Output '$output' not created or has 0 size." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sync
|
||||||
|
echo "`date` - '$output' has been created successfully."
|
||||||
|
sleep 3
|
||||||
|
du -h "$input"
|
||||||
|
du -h "$output"
|
||||||
|
|
||||||
|
echo "`date` - Finished basic-process"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
alias v2a="basic-process"
|
||||||
|
alias vta="v2a"
|
||||||
|
alias va="v2a"
|
||||||
|
alias pa="v2a"
|
||||||
|
alias fix-audio="basic-process"
|
||||||
|
|
||||||
|
# Go to normal storage. DISABLED, use shortcut aliases instead.
|
||||||
|
#cd ~/storage/shared/
|
||||||
|
|
||||||
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||||
|
echo "'$PROG' completed!"
|
||||||
|
@ -5,4 +5,5 @@ PROD_USER=username
|
|||||||
PROD_NAME=example.com
|
PROD_NAME=example.com
|
||||||
PROD_PORT=2222
|
PROD_PORT=2222
|
||||||
|
|
||||||
echo "'$0' completed!"
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||||
|
echo "'$PROG' completed!"
|
||||||
|
46
setup.sh
46
setup.sh
@ -1,40 +1,43 @@
|
|||||||
# No Shebang For Termux
|
# No Shebang For Termux
|
||||||
# 2024-02-10 Hyperling
|
# 2024-02-10 Hyperling
|
||||||
|
|
||||||
echo "`date` - Starting Hyperling's Termux Setup"
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||||
|
echo "`date` - Starting $PROG"
|
||||||
|
|
||||||
DIR="`dirname $0`"
|
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||||
cd $DIR
|
cd $DIR
|
||||||
DIR="`pwd`"
|
DIR="`pwd`"
|
||||||
|
echo "Working in '$DIR'."
|
||||||
|
|
||||||
echo -e "\n`date` - Upgrade Package Repos"
|
echo -e "\n`date` - Upgrade Package Repos"
|
||||||
pkg update &&
|
pkg update &&
|
||||||
pkg upgrade
|
pkg upgrade -y
|
||||||
|
|
||||||
echo -e "\n`date` - Check Storage Permission"
|
echo -e "\n`date` - Check Storage Permission"
|
||||||
if [[ ! -e ~/storage/shared ]]; then
|
if [[ ! -e ~/storage/shared ]]; then
|
||||||
sleep 3
|
sleep 3
|
||||||
termux-setup-storage
|
termux-setup-storage
|
||||||
if [[ -e ~/storage/shared/ ]]; then
|
if [[ -e ~/storage/shared/ ]]; then
|
||||||
echo "~/storage/shared/ now exists. :)"
|
echo "~/storage/shared/ now exists. :)"
|
||||||
else
|
else
|
||||||
echo "ERROR: Something ain't right, Jim! Abort!" >&2
|
echo "ERROR: Something ain't right, Jim! Abort!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Everything looks good already, pal."
|
echo "Everything looks good already, pal."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\n`date` - Install Software"
|
echo -e "\n`date` - Install Software"
|
||||||
pkg install \
|
pkg install -y \
|
||||||
openssh tsu vim htop git cronie \
|
openssh tsu vim htop git cronie man \
|
||||||
nmap traceroute \
|
nmap traceroute wget \
|
||||||
ffmpeg
|
ffmpeg imagemagick \
|
||||||
|
kotlin php nodejs python libllvm
|
||||||
|
|
||||||
echo -e "\n`date` - BASH Environment"
|
echo -e "\n`date` - BASH Environment"
|
||||||
if [[ ! -e ~/.env ]]; then
|
if [[ ! -e ~/.env ]]; then
|
||||||
if [[ -e env.example ]]; then
|
if [[ -e env.example ]]; then
|
||||||
mv -v env.example ~/.env
|
mv -v env.example ~/.env
|
||||||
else
|
else
|
||||||
echo "ERROR: Neither .env or env.example found." >&2
|
echo "ERROR: Neither .env or env.example found." >&2
|
||||||
fi
|
fi
|
||||||
@ -46,7 +49,7 @@ fi
|
|||||||
if [[ -e bashrc.sh ]]; then
|
if [[ -e bashrc.sh ]]; then
|
||||||
mv -v bashrc.sh ~/.bashrc
|
mv -v bashrc.sh ~/.bashrc
|
||||||
else
|
else
|
||||||
echo "ERROR: bashrc.sh not found, skipping." >&2
|
echo "ERROR: bashrc.sh not found, skipping." >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\n`date` - Cleanup"
|
echo -e "\n`date` - Cleanup"
|
||||||
@ -58,16 +61,21 @@ if [[ ! -e ~/storage/shared/TRASH ]]; then
|
|||||||
fi
|
fi
|
||||||
ln -s ~/storage/shared/TRASH ~/TRASH
|
ln -s ~/storage/shared/TRASH ~/TRASH
|
||||||
|
|
||||||
cd ..
|
if [[ -n $DIR && $DIR != "/" && -d .git ]]; then
|
||||||
if [[ -n $DIR && $DIR != "/" ]]; then
|
echo "We are in a git clone, remove the project."
|
||||||
|
cd ..
|
||||||
mv -v $DIR ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" |
|
mv -v $DIR ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" |
|
||||||
grep -v '/.git/'
|
grep -v '/.git/'
|
||||||
|
else
|
||||||
|
echo "File was used individually, remove it."
|
||||||
|
mv "$PROG" ~/TRASH/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\n*******"
|
echo -e "\n*******"
|
||||||
echo "Don't forget to reload your environment!"
|
echo "Don't forget to reload your environment!"
|
||||||
echo " source .bashrc"
|
echo " source ~/.bashrc"
|
||||||
echo "*******"
|
echo "*******"
|
||||||
|
|
||||||
echo -e "\n`date` - Finished Hyperling's Termux Setup"
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||||
|
echo -e "\n`date` - Finished $PROG"
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user