#!/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_;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'") sfdeps=("ffmpeg") source "$(dirname $0)/../lib/sf" # Handle missing parameters [ "$from" == 0 ] && [ "$to" == "end" ] && sferr "Set at least ${sftbf}--from${sftrs} or ${sftbf}--to${sftrs}" # Set default value for output file [ "$out" == "cutted_" ] && out="$(dirname "$FILE")/cutted_$(basename "$FILE")" # Set additional ffmpeg arguments args=() [ "$to" != "end" ] && args+=("-to" "$to") [ "${FILE##*.}" == "${out##*.}" ] && args+=("-c" "copy") # Execute ffmpeg echo "Cutting file ${sftbf}$(basename "$FILE")${sftrs}" ffmpeg -hide_banner -loglevel error -i "$FILE" -ss "$from" "${args[@]}" "$out" [ "$?" == "0" ] && echo "The extracted part was saved to ${sftbf}$out${sftrs}"