diff options
author | Mattias Andrée <m@maandree.se> | 2024-12-02 20:51:28 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2024-12-02 20:51:28 +0100 |
commit | 37597db597c517498165946a141d6192560acf0e (patch) | |
tree | 09a98b10880f2740f7171f9d397711cf8ce155ff | |
parent | First commit (diff) | |
download | ffutils-37597db597c517498165946a141d6192560acf0e.tar.gz ffutils-37597db597c517498165946a141d6192560acf0e.tar.bz2 ffutils-37597db597c517498165946a141d6192560acf0e.tar.xz |
Second commit
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r-- | DEPENDENCIES | 1 | ||||
-rw-r--r-- | Makefile | 28 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rwxr-xr-x | ffextract-audio | 36 | ||||
-rw-r--r-- | ffextract-audio.1 | 72 | ||||
-rwxr-xr-x | ffextract-frame | 53 | ||||
-rw-r--r-- | ffextract-frame.1 | 61 | ||||
-rwxr-xr-x | ffget-audio-extension | 12 | ||||
-rw-r--r-- | ffget-audio-extension.1 | 38 | ||||
-rwxr-xr-x | ffuse-frame | 41 | ||||
-rw-r--r-- | ffuse-frame.1 | 56 |
12 files changed, 368 insertions, 34 deletions
diff --git a/DEPENDENCIES b/DEPENDENCIES index 821a288..f0bdd95 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -6,4 +6,5 @@ rmdir sed sh test +tr unlink diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a0506d --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.POSIX: + +CONFIGFILE = config.mk +include $(CONFIGFILE) + +BIN =\ + ffextract-audio\ + ffextract-frame\ + ffget-audio-extension\ + ffuse-frame + +MAN1 = $(BIN:=.1) + +all: + +install: + mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1" + cp -- $(BIN) "$(DESTDIR)$(PREFIX)/bin/" + cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1/" + +uninstall: + -cd -- "$(DESTDIR)$(PREFIX)/bin/" && rm -f -- $(BIN) + -cd -- "$(DESTDIR)$(MANPREFIX)/man1/" && rm -f -- $(MAN1) + +clean: + +.PHONY: all install uninstall clean @@ -1,3 +1 @@ -Add Makefile -Add man pages Add README diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..095d72d --- /dev/null +++ b/config.mk @@ -0,0 +1,2 @@ +PREFIX = /usr +MANPREFIX = $(PREFIX)/share/man diff --git a/ffextract-audio b/ffextract-audio index b95dd8f..24ca2c1 100755 --- a/ffextract-audio +++ b/ffextract-audio @@ -13,29 +13,19 @@ delete_in_file=no ffmpeg_flag_y= status=0 -while test "${1::1}" = '-'; do - if test "${1}" = '--'; then - shift - break - elif test "${1}" = '-'; then - break - fi - - arg="${1:1}" - while test -n "${arg}"; do - flag="${arg::1}" - arg="${arg:1}" - if test "${flag}" = r; then - recursive=yes - elif test "${flag}" = D; then - delete_in_file=yes - elif test "${flag}" = y; then - ffmpeg_flag_y=-y - else - usage - fi - do +while getopts Dry flag; do + case "$flag" in + D) + delete_in_file=yes;; + r) + recursive=yes;; + y) + ffmpeg_flag_y=-y;; + ?) + usage;; + esac done +shift $(( ${OPTIND} - 1 )) if test ! $# = 1 && test ! $# = 2; then usage @@ -59,7 +49,7 @@ getext () { } removeext () { - printf '%s\n' "$1" | sed 's/\.[^.]*$//' + printf '%s\0' "$1" | tr '\0\n' '\n\0' | sed 's/\.[^.]*$//' | tr '\0' '\n' } extract () { diff --git a/ffextract-audio.1 b/ffextract-audio.1 new file mode 100644 index 0000000..79a0eb2 --- /dev/null +++ b/ffextract-audio.1 @@ -0,0 +1,72 @@ +.TH FFEXTRACT-AUDIO 1 FFUTILS +.SH NAME +ffextract-audio \- create an audio file from a video file + +.SH SYNOPSIS +.B ffextract-audio +[-Dry] +.I in-file +.RI [ out-file ] + +.SH DESCRIPTION +.B ffextract-audio +extracts the audio track from +.I in-file +and copies it into the new file +.IR out-file . + +.SH OPTIONS +.TP +.BR \-D +Remove the original file upon success. +.TP +.BR \-r +Process all files in +.I in-file +recursively. +.TP +.BR \-y +Overwrite output file if it already exists. + +.SH OPERANDS +.TP +.I in-file +Video file or, if the +.B -r +option is used, directory of video files +to extract the audio track from. +.TP +.I out-file +Output file or output directory, if +.I in-file +is a directory. + +If +.I out-file +is omitted, +.I in-file +is used except the filename suffix is +replaced to appropriately reflect the file format +used for the audio track. +Otherwise if the +.B -r +option is used, +the files names found inside +.I in-file +are appended to +.IR out-file +and the filename suffix are likewise replaced. + +.SH EXIT VALUE +.TP +0 +Successful completely. +.TP +1 +An error occurred. + +.SH SEE ALSO +.BR ffmpeg (1), +.BR ffextract-frame (1), +.BR ffget-audio-extension (1), +.BR ffuse-frame (1) 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 diff --git a/ffextract-frame.1 b/ffextract-frame.1 new file mode 100644 index 0000000..e048414 --- /dev/null +++ b/ffextract-frame.1 @@ -0,0 +1,61 @@ +.TH FFEXTRACT-FRAME 1 FFUTILS +.SH NAME +ffextract-frame \- create an image file from a video file + +.SH SYNOPSIS +.B ffextract-frame +[-t +.IR time ] +[-y] +.I in-file +.RI [ out-file ] + +.SH DESCRIPTION +.B ffextract-frame +extracts a frame from the video track from +.I in-file +and copies it into the new file +.IR out-file . + +.SH OPTIONS +.TP +.BR \-t \ \fItime\fP +The timestamp of the frame to used. The default is 10 seconds. +.TP +.BR \-y +Overwrite output file if it already exists. + +.SH OPERANDS +.TP +.I in-file +Video file to extract the frame from. +.TP +.I out-file +The pathname for the new image file. + +If omitted, +.I in-file +is used with the suffix (if any) removed +and replaced with \(dq.png\(dq. + +If +.I in-file +is a dash +.RB ( - ), +standard out is used, and the file format will be +Portable Network Graphics (PNG) otherwise, the format +is determined by the filename suffix. + +.SH EXIT VALUE +.TP +0 +Successful completely. +.TP +1 +An error occurred. + +.SH SEE ALSO +.BR ffmpeg (1), +.BR ffextract-audio (1), +.BR ffget-audio-extension (1), +.BR ffuse-frame (1) diff --git a/ffget-audio-extension b/ffget-audio-extension index 7f0156f..8feca81 100755 --- a/ffget-audio-extension +++ b/ffget-audio-extension @@ -8,16 +8,10 @@ usage () { exit 1 } -while test "${1::1}" = '-'; do - if test "${1}" = '--'; then - shift - break - elif test "${1}" = '-'; then - break - else - usage - fi +while getopts '' flag; do + usage done +shift $(( ${OPTIND} - 1 )) if test ! $# = 1; then usage diff --git a/ffget-audio-extension.1 b/ffget-audio-extension.1 new file mode 100644 index 0000000..1aca821 --- /dev/null +++ b/ffget-audio-extension.1 @@ -0,0 +1,38 @@ +.TH FFGET-AUDIO-EXTENSION 1 FFUTILS +.SH NAME +ffget-audio-extension \- get appropriate filename suffix for a audio track in a video file + +.SH SYNOPSIS +.B ffget-audio-extension +.I in-file + +.SH DESCRIPTION +.B ffget-audio-extension +prints to standard output the appropriate filename suffix, +sans period +.RB ( . ), +for the audio track in +.IR in-file , +would the audio track be extracted and saved as an audio file. + +.SH OPTIONS +None. + +.SH OPERANDS +.TP +.I in-file +Video file to get the audio tracks file format for. + +.SH EXIT VALUE +.TP +0 +Successful completely. +.TP +1 +An error occurred. + +.SH SEE ALSO +.BR ffprobe (1), +.BR ffextract-audio (1), +.BR ffextract-frame (1), +.BR ffuse-frame (1) diff --git a/ffuse-frame b/ffuse-frame new file mode 100755 index 0000000..d556203 --- /dev/null +++ b/ffuse-frame @@ -0,0 +1,41 @@ +#!/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 ! $# = 2; then + usage +fi + +in_file="$1" +if test -z "${in_file}"; then + usage +fi + +out_file="$2" +if test -z "${out_file}"; then + usage +fi + +ffmpeg -i "${in_file}" -ss "${ss}" -update 1 -frames:v 1 -c:v png -f image2pipe - | \ + ffmpeg -f image2pipe -i - -i "${in_file}" -map 0:v:0 -map 1:a:0 -c:v png ${ffmpeg_flag_y} -- "${out_file}" diff --git a/ffuse-frame.1 b/ffuse-frame.1 new file mode 100644 index 0000000..b5df3b3 --- /dev/null +++ b/ffuse-frame.1 @@ -0,0 +1,56 @@ +.TH FFUSE-FRAME 1 FFUTILS +.SH NAME +ffuse-frame \- create an image file from a video file + +.SH SYNOPSIS +.B ffuse-frame +[-t +.IR time ] +[-y] +.I in-file +.RI [ out-file ] + +.SH DESCRIPTION +.B ffuse-frame +extracts a frame from the video track from +.I in-file +and creates an audio file tagged with this frame +(or a video file where the video track is replaced +with this frame), and stored it as +.IR out-file . +.PP +.B ffuse-frame +may transcode the audio, and the frame will always +be transcoded to Portable Network Graphics (PNG). + +.SH OPTIONS +.TP +.BR \-t \ \fItime\fP +The timestamp of the frame to used. The default is 10 seconds. +.TP +.BR \-y +Overwrite +.I out-file +if it already exists. + +.SH OPERANDS +.TP +.I in-file +Video file to extract the frame from. +.TP +.I out-file +The pathname for the new audio file. + +.SH EXIT VALUE +.TP +0 +Successful completely. +.TP +1 +An error occurred. + +.SH SEE ALSO +.BR ffmpeg (1), +.BR ffextract-audio (1), +.BR ffextract-frame (1), +.BR ffget-audio-extension (1) |