30 lines
1.2 KiB
Bash
Executable file
30 lines
1.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# sf
|
|
sfdesc="Extract a part of a file."
|
|
sfargs+=("FILE;File which will be cutted")
|
|
sfargs+=("from;f;TIMESTAMP/SECONDS;0;Extract from TIMESTAMP/SECONDS")
|
|
sfargs+=("out;o;FILE;cutted_<filename>;Save extracted part to FILE")
|
|
sfargs+=("to;t;TIMESTAMP/DURATION;end;Extract to TIMESTAMP/DURATION")
|
|
sfexamples+=("ffcut -t 5 video.mp4 -o cut.webm;Extract the first five seconds of 'video.mp4' to 'cut.webm'")
|
|
sfexamples+=("ffcut -f 00:10:30 -t 00:14:15 video.mp4;Extract the part from 00:10:30 to 00:14:15 from 'video.mp4'")
|
|
|
|
source "$(dirname $0)/../lib/sf"
|
|
|
|
# Handle missing parameters
|
|
[ "$from" == 0 ] && [ "$to" == "end" ] && sferr "Set at least '--from' or '--to'"
|
|
|
|
# Set default value for output file
|
|
[ "$out" == "cutted_<filename>" ] && out="$(dirname "$FILE")/cutted_$(basename "$FILE")"
|
|
|
|
echo "Cutting file ${sftbf}$(basename "$FILE")${sftrs}"
|
|
|
|
# Set additional ffmpeg arguments
|
|
args=()
|
|
[ "$to" != "end" ] && args+=("-to" "$to")
|
|
[ "${FILE##*.}" == "${out##*.}" ] && args+=("-c" "copy")
|
|
|
|
# Execute ffmpeg
|
|
ffmpeg -hide_banner -loglevel error -i "$FILE" -ss "$from" "${args[@]}" "$out"
|
|
|
|
[ "$?" == "0" ] && echo "The extracted part was saved to ${sftbf}$out${sftrs}"
|