Last active
December 15, 2018 20:38
-
-
Save edouard-lopez/e928ac0e05c283aca66509488cc1ef4f to your computer and use it in GitHub Desktop.
extract-and-encode.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# see: https://askubuntu.com/q/56022/22343 | |
# REQUIREMENT: | |
# sudo apt install --yes ffmpeg libav-tools | |
# USAGE | |
# bash -x ./scripts/extract-and-encode.bash "$path/to/videos" [path/to/timing.tsv] | |
IS_RUNNING_TESTS="${IS_RUNNING_TESTS:=false}" | |
FAIL=1 | |
extract-and-encode() { | |
local video_source="$1" | |
local mot="$2" | |
local start="$3" | |
local end="$4" | |
ffmpeg_args=( | |
-ss "$start" \ | |
-to "$end" \ | |
-r 14 # framerate | |
-vf scale=640x480 | |
-b:v 512k | |
-minrate 256k | |
-maxrate 742k | |
-quality good | |
-speed 4 | |
-crf 37 # maximum quality level. | |
-c:v libvpx-vp9 # video codec | |
-loglevel error | |
) | |
local target_file="videos/$mot.webm" | |
ffmpeg -y \ | |
-i "$video_source" \ | |
"${ffmpeg_args[@]}" \ | |
"$target_file" < /dev/null # to prevent ffmpeg from swallowing input | |
} | |
process-all() { | |
if [[ $# -eq 0 ]] ; then | |
echo 'missing arguments.' | |
echo 'usage:' | |
echo " extract-and-encode.bash path/to/video.mkv [path/to/timing.tsv]" | |
exit $FAIL | |
fi | |
if [[ -z $2 ]]; then | |
echo 'missing argument: path/to/timing.tsv' | |
exit $FAIL | |
fi | |
local video_source="$1" | |
local video_timing="$2" | |
while read -r start end mot; do | |
echo "Extracting: $mot" "$start" "$end" | |
extract-and-encode "$video_source" "$mot" "${start}" "${end}" | |
done < "$video_timing" | |
} | |
if [[ $IS_RUNNING_TESTS == false ]]; then process-all "$@"; fi |
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0:00:01.64 0:00:04.07 bonjour | |
0:00:04.09 0:00:07.00 bonsoir | |
0:00:07.00 0:00:10.36 au revoir | |
0:00:10.36 0:00:13.28 merci | |
0:00:13.28 0:00:16.10 non merci | |
0:00:16.10 0:00:19.11 de rien | |
0:00:19.11 0:00:21.93 ça va | |
0:00:21.93 0:00:24.75 oui | |
0:00:24.75 0:00:28.84 non | |
0:00:28.84 0:00:32.26 pardon | |
0:00:32.26 0:00:35.47 s'il vous plait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment