Bash scripts for common conversion tasks on multimedia (video, image, audio) files. I've put these scripts together so I don't have to look up common conversion parameters all the time. Built to work on OS X.
These scripts depend on the following libraries, which can be easily installed with apt or Homebrew:
- ffmpeg
- imagemagick
- pngquant
- jpegoptim
- optipng
- gifsicle
- LAME
- SoX
- ImageAlpha
Make sure these scripts have appropriate permissions:
chmod 755 *
In your shell, just put a ./ in front of the script name then provide parameters described in the script file. For example, using movie2gif.sh looks like this:
./videoToGif.sh /Path/to/movie/file.mov 600
- Get Ubuntu installed from the Windows Store. This requires enabling Windows Subsystem for Linux (WSL) from Turn Windows Features on/off in Control Panel
- Open the Ubuntu app installed from the Store or
CMD + Rand typewsl - Install Linuxbrew:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
- Install libraries:
brew install imagemagickbrew install ffmpegbrew install gifsiclebrew install LAMEbrew install SoXbrew install dos2unix
- Convert dos carriage returns to UNIX format with dos2unix
- Find your C: drive and path to the scripts:
cd /mnt/c/files/media-utility-scripts
SCALE TO WIDTH:
-vf "scale=960:-1"SCALE TO NEW ASPECT RATIO
-vf scale=800:600 -aspect 800:600FRAME RATE
frame rate: -r 30
frame rate: -r 60VIDEO CODEC / QUALITY
h264: -c:v libx264 -crf 1 not this: -q:v 0
mpeg4: -c:v mpeg4 -crf 1
webm: -c:v libvpx -c:a libvorbis
# https://thethemefoundry.com/blog/convert-mp4-to-webm/VIDEO PLAYBACK
# faster decoding:
-tune fastdecodeTIME CROP:
start: -ss 2.3
end: -to 4.3
example: -ss 0.5 -to 1.5ROTATE VIDEO
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
Use -vf "transpose=2,transpose=2" for 180 degrees.
# example: -vf "transpose=1"REMOVE AUDIO
-anConvert audio to mono
-af "pan=mono|c0=c1" -map 0:0 -c:v
ffmpeg -i video.mp4 -af "pan=mono|c0=c1" video.mp4AUDIO CODEC
-c:a aac -b:a 128k -ac 2KEYFRAMES ON EVERY FRAME
-vcodec libx264 -x264-params keyint=1:scenecut=0
# or for non-mp4:
-keyint_min 1 -g 1COPY CODEC (could result in non-mp4 output)
-vcodec copyEFFECTS
# Brightness/saturation/contrast
-vf eq=brightness=0.08:saturation=1.2:contrast=1.15
# Grayscale:
-vf format=gray
# Invert:
-vf lutrgb="r=negval:g=negval:b=negval"
# Frame interpolation
-vf minterpolate='fps=60:mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1'
# https://github.com/dthpham/butterflow
# Boomerang
-filter_complex "[0]reverse[r];[0][r]concat=n=2"MERGE AUDIO TO VIDEO FILE
%ffmpeg% -f concat -i _concat.txt -i %audioFile% -c:a aac -b:a 128k -ac 2 final-render\%sessionId%.mp4CONCAT VIDEO FILES & ADD AUDIO
%ffmpeg% -f concat -i _concat.txt -i %audioFile% -c:a aac -b:a 128k -ac 2 final-render\%sessionId%.mp4IMAGE SEQUENCE TO VIDEO (WINDOWS)
%ffmpeg% -r 30 -f image2 -i %%04d.tga -c:v libx264 -crf 16 -pix_fmt yuv420p -f mp4 ..\_frames-rendered.mp4BLANK SPACE PADDING
-vf "pad=width=1800:height=1200:x=100:y=100:color=black"GENERATE A TEST PATTERN
ffmpeg -f lavfi -i testsrc=duration=10:size=3840x2160:rate=60 -c:v libx264 testsrc1.mp4Alpha Channel video
# (2) commands to convert from Prores to webm w/alpha channel
ffmpeg -i input.mov -c:v libvpx-vp9 -b:v 1000k -pass 1 -an -f null -
ffmpeg -i input.mov -c:v libvpx-vp9 -b:v 1000k -pass 2 output.webmCrop and scale at the same time!
# From: https://stackoverflow.com/a/52675535
crop=iw-100:ih-200,scale=960:576 Specific recommendations for Twitter
# From: https://gist.github.com/marcduiker/abe8e4b7353b4c6430d556b727666620
# - Convert pngs to mp4
ffmpeg -framerate 10 -i frame_%04d.png -c:v h264_qsv -b:v 5M video.mp4
# - Convert and scale an existing mp4 to 1080:
ffmpeg -i input.mp4 -c:v h264_qsv -vf: scale=1080:-1 -b:v 5M output.mp4
# - Convert infinite looping gif to limited looping mp4 (no scaling)
ffmpeg -i input.gif -c:v h264_qsv -filter_complex loop=loop=<NrOfLoops>:size=<TotalFrames>:start=<FramesToSkip> -b:v 5M output.mp4Fix Waifu2x super high framterate video
-r 60 -vf: scale=1080:-1,setpts=2*PTSProRes
# Info: https://ottverse.com/ffmpeg-convert-to-apple-prores-422-4444-hq/