[READ-ONLY] Mirror of https://github.com/probablykasper/to. CLI audio, video and image file converter
aiff audio cli flac gif image jp2 jpg mov mp3 mp4 ogg png video webm webp
0

Configure Feed

Select the types of activity you want to include in your feed.

Making the repo exclusively for the "to" script

+2 -278
+2 -90
README.md
··· 1 - # my-bash-scripts 2 - 3 - These are the basic bash scripts I've made for myself. They're made for macOS, so there's no guarantee they'll work on other OSes. 4 - 5 - # Install 6 - 7 - 1. Download the scripts and put them in whatever folder you want. In my case, they are in `~/dev/my-bash-scripts/bin`. 8 - 2. Now you need to make the scripts executable. You can do that by running `chmod +x <YOUR_FOLDER>/*`. 9 - 3. Lastly, add the folder to your PATH, so you can call the scripts by their filename in your terminal from anywhere. Edit the file named `.bash_profile` (or create it if it does not exist). Add the following line to it: `export PATH=<YOUR_FOLDER>:$PATH`. 10 - 11 - # Scripts 12 - 13 - ## welp 14 - Super simple script that lists the files in the same folder as the script is in. In other words, it lists the scripts here. 15 - 16 - ## chill 17 - Stops execution for a specified amount of time. Useful for scheduling stuff. `chill` shows the syntax: 18 - ``` 19 - Syntax: chill #h 20 - Syntax: chill #m 21 - Syntax: chill #h #m 22 - ``` 23 - 24 - ## d-c 25 - Basic wrapper around the `docker-compose` command (which you should have if you got Docker installed). The command works the same as `docker-compose`, except: 26 - - When running `d-c run`, it automatically adds the `--rm` argument 27 - - When running `d-c up`, it automatically runs `docker-compose down` afterwards. 28 - 29 - ## render 30 - This will render [After Effects](https://www.adobe.com/products/aftereffects.html) projects, assuming you have After Effects installed in `/Applications/Adobe After Effects CC 2019` (Specifically, the `aerender` file needs to be in there). Running `render` shows the syntax: 31 - ``` 32 - Usage: 33 - render <file> [file...] 34 - 35 - Options: 36 - file After Effects .aep file for After Effects' aerender to render. 37 - ``` 38 - It was made to be able to support multiple path arguments, as well as taking folders as path arguments to render every .aep file inside those folders, but I don't think that works. Might fix that someday if I need it. 39 - 40 - ## reset-permissions 41 - Resets permissions of a directory. You should probably know what you're doing before running this. 42 - 43 - Running `reset-permissions` shows the syntax: 44 - ``` 45 - reset-permissions 46 - usage: reset-permissions <username> <directory> 47 - ``` 48 - 49 - This is the command it will run: 50 - ``` 51 - sudo chmod -RN <DIRECTORY> && \ 52 - sudo chown -R <USERNAME> <DIRECTORY> && \ 53 - sudo chmod -R 755 <DIRECTORY> 54 - ``` 55 - 56 - ## sleepy 57 - Hibernates your computer. I usually run this after `render` or `chill`. 58 - 59 - ## to 60 - Requires [ImageMagick](https://imagemagick.org) for images and [FFmpeg](https://ffmpeg.org) for audio and video. I recommend installing them using [Brew](https://brew.sh) by running `brew install ffmpeg imagemagick`. 61 - 62 - Converts audio and video. Running `to` shows this help message: 63 - ``` 64 - Usage: 65 - to <format> [options] <file1> [file2...] 66 - 67 - Options: 68 - format Format to convert to. 69 - --formats List all supported formats. 70 - -v, --verbose If you love logs. 71 - -h, --help Show this help message. 72 - 73 - Video/audio formats support FFmpeg options (see $ ffmpeg -h). 74 - Image formats support ImageMagick options (see $ man magick). 75 - Long arguments must have quotes (like "-b:a 128k"). 76 - ``` 77 - 78 - ## to-gif 79 - Requires [ffmpeg](https://ffmpeg.org) (which I recommend installing using [Brew](https://brew.sh)). 1 + # to 80 2 81 - Converts videos into gifs. If you do this frequently I would probably use some app instead. 82 - 83 - Running `to-gif` shows the syntax: 84 - ``` 85 - Syntax: to-gif <file> [fps] [scale] [duration] [start_at] 86 - file: File to convert to gif. Required. 87 - fps: Defaults to 15. 88 - scale: GIF resolution. Defaults to 1. 89 - duration: How long the gif will be, in seconds. Defaults to 999999. 90 - start_at: Where the video starts, in seconds. Defaults to 0 91 - ``` 3 + Pretty simple bash script that converts audio, video and image files using FFmpeg and ImageMagick.
-38
bin/chill
··· 1 - #! /bin/bash 2 - 3 - FILENAME=${0##*/} 4 - 5 - if [[ $1 == *h ]] 6 - then 7 - HOURS=${1%h} 8 - 9 - if [[ $2 == *m ]] 10 - then 11 - MINUTES=${2%m} 12 - (( SECONDS=HOURS * 60 * 60 + MINUTES * 60 )) 13 - echo "Sleeping for $HOURS hours and $MINUTES minutes ($SECONDS seconds)" 14 - sleep $SECONDS 15 - else 16 - (( SECONDS=HOURS * 60 * 60 )) 17 - echo "Sleeping for $HOURS hours ($SECONDS seconds)" 18 - sleep $SECONDS 19 - fi 20 - 21 - elif [[ $1 == *m ]] 22 - then 23 - MINUTES=${1%m} 24 - (( SECONDS=MINUTES * 60 )) 25 - echo "Sleeping for $MINUTES minutes ($SECONDS seconds)" 26 - sleep $SECONDS 27 - else 28 - echo "Syntax: $FILENAME #h" 29 - echo "Syntax: $FILENAME #m" 30 - echo "Syntax: $FILENAME #h #m" 31 - fi 32 - 33 - # target="$1.$2" 34 - # cur=$(date '+%H.%M') 35 - # while test $target != $cur; do 36 - # sleep 59 37 - # cur=$(date '+%H.%M') 38 - # done
-9
bin/d-c
··· 1 - #! /bin/bash 2 - 3 - if [[ $1 == "run" ]]; then 4 - docker-compose run --rm "${@:2}" 5 - elif [[ $1 == "up" ]]; then 6 - docker-compose up "${@:2}"; docker-compose down 7 - else 8 - docker-compose "${@:1}" 9 - fi
-75
bin/render
··· 1 - #! /bin/bash 2 - 3 - color() { 4 - echo -n "`tput setaf $1`${@:2}" 5 - # reset color if there are arguments: 6 - if [[ "$#" > 1 ]]; then echo -n "`tput setaf 7`"; fi 7 - } 8 - red() { color 1 "$@"; } 9 - green() { color 2 "$@"; } 10 - cyan() { color 6 "$@"; } 11 - reset() { color 7 "$@"; echo -n `tput sgr0`; } 12 - 13 - aerender=/Applications/Adobe\ After\ Effects\ CC\ 2019/aerender 14 - 15 - help() { 16 - FILENAME=${0##*/} 17 - echo " 18 - `green Usage:` 19 - `cyan $FILENAME` <file> [file...] 20 - 21 - `green Options:` 22 - `cyan file` After Effects .aep file for After Effects' aerender to render. 23 - " 24 - } 25 - 26 - # no args 27 - if [[ "$#" < 1 ]]; then help; exit 0; fi 28 - 29 - # proactively check for errors 30 - for ARG in "$@"; do 31 - if [[ ! -f "$ARG" ]]; then 32 - echo "`red Error:` File does not exist: $ARG" 33 - ERRORS=true 34 - elif [[ "$ARG" != *.aep ]]; then 35 - echo "`red Error:` File must be .aep: $ARG" 36 - ERRORS=true 37 - else 38 - FILES+=() 39 - fi 40 - done 41 - 42 - # exit if there were errors 43 - if [[ $ERRORS == true ]]; then exit 1; fi 44 - 45 - ERRORS=() 46 - err() { 47 - ERRORS+=("$1") 48 - echo `red ✖ Error:` "$1" 49 - } 50 - # render 51 - for ARG in "$@"; do 52 - if [[ ! -f "$ARG" ]]; then 53 - err "File does not exist: $ARG" 54 - elif [[ "$ARG" != *.aep ]]; then 55 - err "File must be .aep: $ARG" 56 - else 57 - echo "" 58 - FILE="$(cd "$(dirname "$ARG")" && pwd)/$(basename "$ARG")" # get absolute path 59 - command "$aerender" -project "$FILE" || err "Render failed: $ARG" 60 - fi 61 - done 62 - 63 - # recap errors 64 - # if more than one render 65 - if [[ "$#" > 1 && ${#FILES[@]} ]]; then 66 - # if errors 67 - if [[ ${#FILES[@]} == 0 ]]; then 68 - printf "\n\n\n" 69 - echo "`tput bold``red`Errors occured while rendering:`reset`" 70 - for ERROR in "$ERRORS"; do 71 - echo " `red ✖ Error:` $ERROR" 72 - done 73 - printf "\n\n\n" 74 - fi 75 - fi
-21
bin/reset-permissions
··· 1 - #! /bin/bash 2 - 3 - if [[ $2 == '' ]]; then 4 - 5 - SCRIPT_FILENAME=${0##*/} 6 - 7 - # Colors 8 - GREEN='\033[0;32m' 9 - RESET='\033[0m' 10 - 11 - echo "" 12 - echo -e "${GREEN}$SCRIPT_FILENAME${RESET}" 13 - echo -e "usage: $SCRIPT_FILENAME <username> <directory>" 14 - echo "" 15 - else 16 - 17 - USERNAME=$1 18 - DIR=$2 19 - sudo chmod -RN "${DIR}" && sudo chown -R ${USERNAME} "${DIR}" && sudo chmod -R 755 "${DIR}" 20 - 21 - fi
-3
bin/sleepy
··· 1 - #! /bin/bash 2 - 3 - pmset sleepnow
bin/to to
-35
bin/to-gif
··· 1 - #!/bin/sh 2 - 3 - FILE=$1 4 - FPS=$2 5 - SCALE=$3 6 - DURATION=$4 7 - START_AT=$5 8 - 9 - if [[ $FILE ]] 10 - then 11 - 12 - if ! [[ $FPS ]]; then FPS=15; fi 13 - if ! [[ $SCALE ]]; then SCALE=1; fi 14 - if ! [[ $DURATION ]]; then DURATION=999999; fi 15 - if ! [[ $START_AT ]]; then START_AT=0; fi 16 - 17 - PALETTE=palette-rp7w8zsw2dx83dsxrgqmt6f5.png 18 - 19 - echo "Generate a palette:" 20 - ffmpeg -y -ss $START_AT -t $DURATION -i $FILE -vf fps=$FPS,scale=w=${SCALE}*iw:h=${SCALE}*ih:-1:flags=lanczos,palettegen ${PALETTE} 21 - 22 - echo "Output the GIF using the palette:" 23 - ffmpeg -ss $START_AT -t $DURATION -i $FILE -i ${PALETTE} -filter_complex "fps=${FPS},scale=w=${SCALE}*iw:h=${SCALE}*ih:flags=lanczos[x];[x][1:v]paletteuse" ${FILE%.*}.gif 24 - 25 - rm -f ${PALETTE} 26 - 27 - else 28 - SCRIPT_FILENAME=${0##*/} 29 - echo "Syntax: $SCRIPT_FILENAME <file> [fps] [scale] [duration] [start_at]" 30 - echo " file: File to convert to gif. Required." 31 - echo " fps: Defaults to 15." 32 - echo " scale: GIF resolution. Defaults to 1." 33 - echo " duration: How long the gif will be, in seconds. Defaults to 999999." 34 - echo " start_at: Where the video starts, in seconds. Defaults to 0" 35 - fi
-7
bin/welp
··· 1 - #! /bin/bash 2 - 3 - # get the dir that the file is in 4 - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 5 - 6 - echo These scripts are installed in $DIR: 7 - ls -1 $DIR