summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-02-10 17:06:54 -0500
committerAndrew Cady <d@jerkface.net>2021-02-10 17:06:54 -0500
commita5d26c3a75f45d75b00ffa60fcbcaece162e8a33 (patch)
tree03784c57e15f02a981645b65e1da91958b34ad2f
parent8845a977db9d660515e1ca17ae2afadc0cb7b38d (diff)
twmp4
-rwxr-xr-xdot/local/bin/twmp449
1 files changed, 43 insertions, 6 deletions
diff --git a/dot/local/bin/twmp4 b/dot/local/bin/twmp4
index 3cc3dad..755c67b 100755
--- a/dot/local/bin/twmp4
+++ b/dot/local/bin/twmp4
@@ -1,19 +1,57 @@
1#!/bin/sh 1#!/bin/bash
2
3usage()
4{
5 cat <<EOF
6Usage: $0 [options] <input>
7
8 Options:
9 --help|--usage|-h
10 --start <time>
11 --end <time>
12EOF
13}
14
15[ $# -gt 0 ] || set -- --help
16ARGS=$(getopt -o 'h' --long 'usage,help,start:,end:' -n 'twmp4' -- "$@") || exit
17eval set -- "$ARGS"
18unset ARGS
19
20INPUT_OPTIONS=
21while [ $# -gt 0 ]
22do
23 case "$1" in
24 -h|--help|--usage) usage; exit ;;
25 --start) INPUT_OPTIONS="$INPUT_OPTIONS -ss $2"; OUTPUT_SUFFIX="${OUTPUT_SUFFIX:+$OUTPUT_SUFFIX.}$2"; shift;;
26 --end) INPUT_OPTIONS="$INPUT_OPTIONS -to $2"; OUTPUT_SUFFIX="${OUTPUT_SUFFIX:+$OUTPUT_SUFFIX.}$2"; shift;;
27 --) shift; break ;;
28 -*) usage; exit 1 ;;
29 *) break;;
30 esac
31 shift
32done
33
2INPUT=$1 34INPUT=$1
3set -ex 35set -ex
4 36
5[ -f "$INPUT" ] 37[ -f "$INPUT" ]
38
39OUTPUT_SUFFIX=${OUTPUT_SUFFIX:+$OUTPUT_SUFFIX.}twitter.mp4
40
6case "$INPUT" in 41case "$INPUT" in
7 *.mp4) OUTPUT=${INPUT%.mp4}.twitter.mp4 ;; 42 *.mp4) OUTPUT=${INPUT%.mp4}.$OUTPUT_SUFFIX ;;
8 *.*) OUTPUT=${INPUT%.*}.twitter.mp4 ;; 43 *.*) OUTPUT=${INPUT%.*}.$OUTPUT_SUFFIX ;;
9 *) OUTPUT=${INPUT}.twitter.mp4 ;; 44 *) OUTPUT=${INPUT}.$OUTPUT_SUFFIX ;;
10esac 45esac
11 46
47# source: https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7
48
12if [ ! -e "$OUTPUT" ] 49if [ ! -e "$OUTPUT" ]
13then 50then
14 # source: https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7
15 ffmpeg -hide_banner \ 51 ffmpeg -hide_banner \
52 $INPUT_OPTIONS \
16 -i "$INPUT" \ 53 -i "$INPUT" \
54 $OUTPUT_OPTIONS \
17 -vcodec libx264 \ 55 -vcodec libx264 \
18 -vf 'scale=640:trunc(ow/a/2)*2' \ 56 -vf 'scale=640:trunc(ow/a/2)*2' \
19 -acodec aac \ 57 -acodec aac \
@@ -27,7 +65,6 @@ fi
27 65
28video_length() 66video_length()
29{ 67{
30 # source: https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds/945604#945604
31 ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1" 68 ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1"
32} 69}
33 70