Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Last active April 3, 2017 19:40
Show Gist options
  • Select an option

  • Save cirrusUK/3474e5da07e531309d07 to your computer and use it in GitHub Desktop.

Select an option

Save cirrusUK/3474e5da07e531309d07 to your computer and use it in GitHub Desktop.
shell scripts for batch converting media
#!/bin/bash
#usage: execute script from within directory source .avi file(s) reside, the source .avi file must have no spaces in filename.
for f in *.avi;
do ffmpeg -i sf -acodec libfaac -ac 2 -ab 128k \
-vcodec libx264 -vpre hq -crf 24 -threads 0 \
${f%.avi}.mpr;
done
#!/bin/bash
for f in *.avi; do ffmpeg -i $f -strict -2 `basename $f .avi`.mp4;
done
#!/bin/bash
#usage: execute script from within directory source .flv file(s) reside, the source .flv file must have no spaces in filename.
for i in *.flv; do ffmpeg -i $i -f mp3 -vn -acodec copy `basename $i .flv`.mp3;done
#!/bin/bash
#usage: execute script from within directory source .m4a file(s) reside, the source .m4a file must have no spaces in filename.
# m4a to mp3
for i in *.m4a
do
faad "$i"
x=`echo "$i"|sed -e 's/.m4a/.wav/'`
y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
lame -h -b 192 "$x" "$y"
rm "$x"
done
#!/bin/bash
find . -type f -name "*.mkv" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -b:a 320000 -y "${FILE%.mkv}.mp3";' _ '{}' \;
#!/bin/bash
#usage: execute script from within directory source .mkv file(s) reside, the source .mkv file must have no spaces in filename.
for i in $(ls *mkv); do ffmpeg -i $i -vcodec copy -acodec copy $i.mp4; done;
#!/bin/sh
#
# mp4_to_mp3
#
echo "current directory =" `pwd`
echo "Please enter working directory ->\c"
read BASE
if cd $BASE ;
then
{
for i in *.mp4; do
out=$(ls $i | sed -e 's/.mp4//g')
echo "In = $i"
echo "Out = $out.mp3"
ffmpeg -vn -i "$i" -vn -ac 2 -ab 128k -acodec libmp3lame "$out.mp3"
# faad -o - $out.mp4 | lame - $out.mp3 #another option
done
}
else
{
echo "ERROR!!"
exit 1
}
fi
#!/bin/bash
VIDEOS=~/Desktop #define directory
find "$VIDEOS" -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "${0%%.mp4}.webm"' {} \;
exit;
#!/usr/bin/env bash
# Simple script to pipe url's opened from terminal emulator, simply set full path to this script as emulators URL handler.
# webm, mp4, avi, you tube and vodlocker URL's clicked in emulator will open with mpv, Image links will open with feh.
# A function containing a case list of options
open() {
case "$1" in
*youtube.com*|*youtu.be*|*vodlocker.com*|*.webm*|*.mp4*|*.avi) mpv "$1";;
*.png|*.jpeg|*.gif*|*.jpg) feh -. "$1";; # feh -. = opens to fit window.
*) firefox "$1"; # For everything else.;
esac
}
# Now a for loop to iterate the list of options,
for url; do
open "$url"
done
#! /bin/sh
###will listen for and output any playing rtmp stream url's being played.
SNIFF=$(sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT)
SNIFF1=$(rtmpsrv)
"SNIFF" "SNIFF1"
#!/bin/sh
#usage: ./gifenc input.mov output.gif 720 10 will output 720px wide 10fps .gif
palette="/tmp/palette.png"
filters="fps=$4,scale=$3:-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
#! /bin/bash
#move this file to folder containing the .webm files and execute.
for FILE in *.webm; do
echo -e " '\e[32mProcessing video\e[0m'";
ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;
#!/bin/bash
#############################################################
# wma2mp3 v0.12
# by Calum and Void Main
#
# e.g. wma2mp3 myfile.wma
# e.g. wma2mp3 myfile.wma myfile2.wma myfile3.wma
# e.g. wma2mp3 "my file.wma" "my file 2.wma" "my file 3.wma"
# e.g. wma2mp3 *.wma
# e.g. wma2mp3 /directory/containing/wma/files
# e.g. wma2mp3 .
#
# http://voidmain.is-a-geek.net/forums/viewtopic.php?t=407
#
# History:
# 16 May 2003 - v0.1 wma2mp3 script created
# 27 August 2005 - v0.11 -aofile had been deprecated, corrected
# 28 August 2005 - v0.12 Added "IFS=" -Void
#############################################################
# Turn off input field separation so filenames with spaces work
IFS=
#############################################################
# Move the conversion process into a function that can
# be called.
# The "&&" makes it so each step must be successful before
# the next step will be done.
#############################################################
function wma2mp3 () {
if [ ! -f "$1" ]; then
echo "File $1 not found!"
else
mplayer -ao pcm:file="${1%%.[Ww][Mm][Aa]}.wav" "$1" &&
lame -h -b 192 "${1%%.[Ww][Mm][Aa]}.wav" "${1%%.[Ww][Mm][Aa]}.mp3" &&
rm -f "${1%%.[Ww][Mm][Aa]}.wav" ||
echo "There was a problem with the conversion process!"
fi
}
#############################################################
# Not enough information to compute
#############################################################
if [ $# -lt 1 ]; then
echo "Syntax: `basename $0` <wmaFilename(s)|wmaDirectory>"
exit
fi
#############################################################
# Directory was passed so convert all wma files in directory
#############################################################
if [ $# -eq 1 -a -d "$1" ]; then
for file in $1/*.[Ww][Mm][Aa]
do
wma2mp3 "$file"
done
exit
fi
#############################################################
# One or more wma files were passed, convert them
#############################################################
for file in $*
do
wma2mp3 "$file"
done
exit
#!/bin/sh
# _________ _______ _______ _______ ______
# |\ /|\__ __// ___ )( )( ____ )/ ___ \
# ( \ / ) ) ( \/ ) || () () || ( )|\/ \ \
# \ (_) / | | / )| || || || (____)| ___) /
# \ / | | _/ / | |(_)| || _____) (___ (
# ) ( | | / _/ | | | || ( ) \
# | | | | ( (__/\| ) ( || ) /\___/ /
# \_/ )_( \_______/|/ \||/ \______/
#
# Usage: Enter URL of video to convert to .mp3 when prompted.
# ▓▓▓▓▓▓▓▓▓▓
# ░▓ author ▓ cirrus <[email protected]>
# ░▓ code ▓ https://gist.github.com/cirrusUK
# ░▓ mirror ▓ http://cirrus.turtil.net
# ░▓▓▓▓▓▓▓▓▓▓
# ░░░░░░░░░░
#
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
tput setaf 5
echo -n "Enter URL: "
read url
url="$url"
tput setaf 6
youtube-dl -c --restrict-filenames --extract-audio --audio-format mp3 "$url"
tput setaf 2
echo -n " yay ! your .mp3 file will be in directory from where you ran this script"
#!/bin/bash
# Whilst the video is playing in your chosen browser, just ./run this script (or create shortcut panel item)
# tutorial video: https://www.youtube.com/watch?v=nGSGlc9bTAg
# requires: ffmpeg wmctrl xclip xdotool youtube-dl
# browser to focus; show list using wmctrl -l
BROWSER_FOCUS=Firefox #put your browser of choice (first letter capitalised)
# set / create save location
DOWNLOAD_DIR_MP3=~/Downloads/youtube_music #put directory where mp3's will be saved
# image to use
IMAGE_LOGO=/home/cirrus/.icons/ytv.png #put path to youtube icon
# focus browser on top
wmctrl -a "$BROWSER_FOCUS"
# copy link to clipboard
sleep 0.5
xdotool key ctrl+l
sleep 0.5
xdotool key ctrl+c
mkdir -p "$DOWNLOAD_DIR_MP3"
cd "$DOWNLOAD_DIR_MP3"
notify-send -i "$IMAGE_LOGO" 'Downloading to MP3' 'Starting ...' -t 5000
# download (prevents downloading all playlist)
youtube-dl -c --restrict-filenames --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" "$(xclip -selection clipboard -o | cut -d\& -f1)"
notify-send -i "$IMAGE_LOGO" 'Downloading to MP3' 'Completed !!!' -t 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment