diff options
Diffstat (limited to 'dot')
-rwxr-xr-x | dot/local/bin/twmp4 | 46 |
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 ;; |
10 | esac | 10 | esac |
11 | 11 | ||
12 | # source: https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7 | ||
13 | |||
14 | if [ ! -e "$OUTPUT" ] | 12 | if [ ! -e "$OUTPUT" ] |
15 | then | 13 | then |
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" | ||
25 | fi | 26 | fi |
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 | 28 | video_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 | ||
29 | CHUNKS=${OUTPUT%.mp4}.%03d.mp4 | 34 | chunk_seconds=135 # twitter max is 140, but ffmpeg can run over specified time |
30 | ffmpeg -i "$OUTPUT" \ | 35 | video_length=$(video_length "$OUTPUT") |
31 | -c copy \ | ||
32 | -map 0 \ | ||
33 | -segment_time 2:15 -f segment -reset_timestamps 1 "$CHUNKS" | ||
34 | 36 | ||
37 | if [ "${video_length%.*}" -gt "$chunk_seconds" ] | ||
38 | then | ||
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" | ||
46 | fi | ||