aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2024-11-26 22:08:22 +0100
committerMattias Andrée <m@maandree.se>2024-11-26 22:08:22 +0100
commit5da5e89beec8ad11f3dc7c9598ab69d97ad82468 (patch)
treedcb65e9afe179583dec3a54fd142dc2b8f483e00
downloadffutils-5da5e89beec8ad11f3dc7c9598ab69d97ad82468.tar.gz
ffutils-5da5e89beec8ad11f3dc7c9598ab69d97ad82468.tar.bz2
ffutils-5da5e89beec8ad11f3dc7c9598ab69d97ad82468.tar.xz
First commit
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--DEPENDENCIES9
-rw-r--r--LICENSE15
-rw-r--r--TODO3
-rwxr-xr-xffextract-audio108
-rwxr-xr-xffget-audio-extension26
6 files changed, 163 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1189c62
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*\#*
+*~
diff --git a/DEPENDENCIES b/DEPENDENCIES
new file mode 100644
index 0000000..821a288
--- /dev/null
+++ b/DEPENDENCIES
@@ -0,0 +1,9 @@
+basename
+ffmpeg
+mkdir
+printf
+rmdir
+sed
+sh
+test
+unlink
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f930ea6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+© 2024 Mattias Andrée <m@maandree.se>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..ed46b49
--- /dev/null
+++ b/TODO
@@ -0,0 +1,3 @@
+Add Makefile
+Add man pages
+Add README
diff --git a/ffextract-audio b/ffextract-audio
new file mode 100755
index 0000000..b95dd8f
--- /dev/null
+++ b/ffextract-audio
@@ -0,0 +1,108 @@
+#!/bin/sh
+# See LICENSE file for copyright and license details.
+
+set -e
+
+usage () {
+ printf 'usage %s: [-Dry] in-file [out-file]\n' "$0" >&2
+ exit 1
+}
+
+recursive=no
+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
+done
+
+if test ! $# = 1 && test ! $# = 2; then
+ usage
+fi
+
+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
+fi
+
+getext () {
+ ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -- "$1"
+}
+
+removeext () {
+ printf '%s\n' "$1" | sed 's/\.[^.]*$//'
+}
+
+extract () {
+ printf '\033[1m%s\033[m\n' "Extracting audio track from ${1}" >&2
+ printf '\033[1m%s\033[m\n' "and storing as ${2}" >&2
+ if ffmpeg -i "${1}" -vn -acodec copy ${ffmpeg_flag_y} -- "${2}"; then
+ if test ${delete_in_file} = yes; then
+ unlink -- "${1}"
+ fi
+ fi
+}
+
+if test ${recursive} = no || test ! -d "${in_file}"; then
+ if test -z "${out_file}"; then
+ out_file="$(removeext "${in_file}").$(getext "${in_file}")"
+ fi
+ extract "${in_file}" "${out_file}"
+ exit $?
+fi
+
+recursive () {
+ for in_file in "${1}/"*; do
+ out_file="$2/$(basename -- "${in_file}")"
+ if test -d "$f"; then
+ mkdir -p -- "${out_file}"
+ recursive "${in_file}" "${out_file}"
+ else
+ out_file="$(removeext "${out_file}").$(getext "${in_file}")"
+ if ! extract "${in_file}" "${out_file}"; then
+ status=1
+ fi
+ fi
+ done
+ if test ${delete_in_file} = yes; then
+ rmdir -- "${1}" 2>/dev/null || :
+ fi
+}
+
+if test -z "${out_file}"; then
+ out_file="${in_file}"
+else
+ mkdir -p -- "${out_file}"
+fi
+recursive "${in_file}" "${out_file}"
+
+exit $status
diff --git a/ffget-audio-extension b/ffget-audio-extension
new file mode 100755
index 0000000..7f0156f
--- /dev/null
+++ b/ffget-audio-extension
@@ -0,0 +1,26 @@
+#!/bin/sh
+# See LICENSE file for copyright and license details.
+
+set -e
+
+usage () {
+ printf 'usage %s: in-file\n' "$0" >&2
+ exit 1
+}
+
+while test "${1::1}" = '-'; do
+ if test "${1}" = '--'; then
+ shift
+ break
+ elif test "${1}" = '-'; then
+ break
+ else
+ usage
+ fi
+done
+
+if test ! $# = 1; then
+ usage
+fi
+
+exec ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -- "$1"