dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit be515b63beb65689295c96d290b68c86980d269e
parent 778761849ce942213944dddecb473ab63e8a6a6e
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun,  4 Aug 2019 23:30:02 +0200

Move ffmpeg functions to a ffmpeg-preset script


Former-commit-id: 05fc375b8f825400ef9e250a6b7a82ae879a5ae3
Diffstat:
Dscripts/anythingtogif | 8--------
Ascripts/ffmpres | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Dscripts/gif2mp4 | 5-----
Mshell/commonprofile | 21---------------------
4 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/scripts/anythingtogif b/scripts/anythingtogif @@ -1,8 +0,0 @@ -#!/bin/sh - -palette="/tmp/palette.png" - -filters="fps=24,scale=0:-1:flags=lanczos" - -ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y "$palette" -ffmpeg -v warning -i "$1" -i "$palette" -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$2" diff --git a/scripts/ffmpres b/scripts/ffmpres @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +if ! command -v ffmpeg &> /dev/null; then echo "ffmpeg not found" && exit 1; fi +if ! [ -f "$1" ] ; then echo "$1 not found." && exit 1; fi + +main() { + case "$1" in + *.gif) + echo "GIF: $1" + process_gif "$1" + ;; + *.mp4|*.mov|*.webm) + echo "VIDEO: $1" + process_video "$1" + ;; + *) + ;; + esac +} +process_gif() { + select to_fmt in "MP4"; do + case "$to_fmt" in + "MP4") + ffmpeg -i "$1" -r 30 -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "${1%%.gif}.mp4" + break;; + *) + break;; + esac + done +} +process_video() { + select to_fmt in "MP4" "MP3" "GIF"; do + case "$to_fmt" in + "MP4") + ffmpeg -i "$1" -qscale 0 "${1%%.*}.mp4" + break;; + "MP3") + ffmpeg -i "$1" "${1%%.*}.mp3" + break;; + "GIF") + local palette="/tmp/palette.png" + local filters="fps=24,scale=0:-1:flags=lanczos" + ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y "$palette" + ffmpeg -v warning -i "$1" -i "$palette" -lavfi "$filters [x]; [x][1:v] paletteuse" -y "${1%%.*}.gif" + break;; + *) + ;; + esac + done +} +main "$@" diff --git a/scripts/gif2mp4 b/scripts/gif2mp4 @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -if ! command -v ffmpeg &> /dev/null; then echo "ffmpeg not found" && exit 1; fi -if ! [ -f "$1" ] ; then echo "$1 not found." && exit 1; fi -if ! [[ "$1" == *.gif ]]; then echo "$1 is not a gif." && exit 1; fi -ffmpeg -i "$1" -r 30 -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "${1%%.gif}.mp4" diff --git a/shell/commonprofile b/shell/commonprofile @@ -186,27 +186,6 @@ gemmaster() { } -# Webm to mp4 video -webm_mp4() { - ffmpeg -i "$1" -qscale 0 "$1".mp4 -} - -# Extract audio from mp4 -mp4_mp3() { - ffmpeg -i "$1" "$1".mp3 -} - -# Anything to a gif -gifify() { - ffmpeg -i "$1" -r 25 -f image2pipe -vcodec ppm - | \ - convert -delay 4 -loop 0 - output.gif - } - -# Gif to mp4 -gif_mp4() { - ffmpeg -i "$1" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "$(echo "$1"|cut -d. -f1).mp4" -} - # Extract any archive extract () { if [ -f "$1" ] ; then