summaryrefslogtreecommitdiff
path: root/dot
diff options
context:
space:
mode:
Diffstat (limited to 'dot')
-rwxr-xr-xdot/local/bin/twmp446
1 files changed, 29 insertions, 17 deletions
diff --git a/dot/local/bin/twmp4 b/dot/local/bin/twmp4
index 9b80425..3cc3dad 100755
--- a/dot/local/bin/twmp4
+++ b/dot/local/bin/twmp4
@@ -9,26 +9,38 @@ case "$INPUT" in
9 *) OUTPUT=${INPUT}.twitter.mp4 ;; 9 *) OUTPUT=${INPUT}.twitter.mp4 ;;
10esac 10esac
11 11
12# source: https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7
13
14if [ ! -e "$OUTPUT" ] 12if [ ! -e "$OUTPUT" ]
15then 13then
16 ffmpeg -i "$INPUT" -vcodec libx264 \ 14 # source: https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7
17 -vf 'scale=640:trunc(ow/a/2)*2' \ 15 ffmpeg -hide_banner \
18 -acodec aac \ 16 -i "$INPUT" \
19 -vb 1024k \ 17 -vcodec libx264 \
20 -minrate 1024k -maxrate 1024k \ 18 -vf 'scale=640:trunc(ow/a/2)*2' \
21 -bufsize 1024k -ar 44100 \ 19 -acodec aac \
22 -strict experimental \ 20 -vb 1024k \
23 -r 30 \ 21 -minrate 1024k -maxrate 1024k \
24 "$OUTPUT" 22 -bufsize 1024k -ar 44100 \
23 -strict experimental \
24 -r 30 \
25 "$OUTPUT"
25fi 26fi
26 27
27# source: https://unix.stackexchange.com/questions/1670/how-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks/212518#212518 28video_length()
29{
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"
32}
28 33
29CHUNKS=${OUTPUT%.mp4}.%03d.mp4 34chunk_seconds=135 # twitter max is 140, but ffmpeg can run over specified time
30ffmpeg -i "$OUTPUT" \ 35video_length=$(video_length "$OUTPUT")
31 -c copy \
32 -map 0 \
33 -segment_time 2:15 -f segment -reset_timestamps 1 "$CHUNKS"
34 36
37if [ "${video_length%.*}" -gt "$chunk_seconds" ]
38then
39 # source: https://unix.stackexchange.com/questions/1670/how-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks/212518#212518
40 CHUNKS=${OUTPUT%.mp4}.%03d.mp4
41 ffmpeg -hide_banner \
42 -i "$OUTPUT" \
43 -c copy \
44 -map 0 \
45 -segment_time "$chunk_seconds" -f segment -reset_timestamps 1 "$CHUNKS"
46fi