From 37597db597c517498165946a141d6192560acf0e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 2 Dec 2024 20:51:28 +0100 Subject: Second commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- ffextract-frame | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 ffextract-frame (limited to 'ffextract-frame') diff --git a/ffextract-frame b/ffextract-frame new file mode 100755 index 0000000..b946550 --- /dev/null +++ b/ffextract-frame @@ -0,0 +1,53 @@ +#!/bin/sh +# See LICENSE file for copyright and license details. + +set -e + +usage () { + printf 'usage %s: [-t time] [-y] in-file [out-file]\n' "$0" >&2 + exit 1 +} + +ffmpeg_flag_y= +ss=10 + +while getopts t:y flag; do + case "$flag" in + t) + ss="${OPTARG}";; + y) + ffmpeg_flag_y=-y;; + ?) + usage;; + esac +done +shift $(( ${OPTIND} - 1 )) + +if test ! $# = 1 && test ! $# = 2; then + usage +fi + +removeext () { + printf '%s\0' "$1" | tr '\0\n' '\n\0' | sed 's/\.[^.]*$//' | tr '\0' '\n' +} + +in_file="$1" +if test -z "${in_file}"; then + usage +fi + +out_file="" +if test $# = 2; then + out_file="$2" + if test -z "${out_file}"; then + usage + fi +else + out_file="$(removeext "${in_file}").png" +fi + +if test "${out_file}" = -; then + exec ffmpeg -i "${in_file}" -ss "${ss}" -update 1 -frames:v 1 -c:v png -f image2pipe - +else + exec ffmpeg -i "${in_file}" -ss "${ss}" -update 1 -frames:v 1 ${ffmpeg_flag_y} -- "${out_file}" +fi -- cgit v1.2.3-70-g09d2