/bash-scripts

Some simple bash scripts for image/video conversion, image management, and video editing.

Primary LanguageShellGNU Affero General Public License v3.0AGPL-3.0

Bash scripts

License

Scripts marked with a 🌟 are ones I use a lot or am particularly proud of.

Image manipulation

  • 🌟 imagedate.sh: Rewrite file and metadata dates on images to increment in the order of the alphabetized filenames. Useful when you have a system (Snapfish) that will only order by date, but you want images ordered by filename.
  • minpic.sh: Minify JPEG and PNG images, losslessly, for the web. Really just a more convenient wrapper for Trimage.
  • 🌟 modimg.sh: Create optimized image formats for the web. Generate WebP, AVIF, and JXL images for browsers that support them, then optimize the fallback JPEG, PNG and GIF images. See the file for additional options and details.
  • webpjpg.sh: Convert webp images to lossless PNG first, then to JPEG.
  • 🌟 pdf2jpg.sh: Convert each page of a PDF to JPEG images, each with the same name as the PDF and the page number appended. Page range, image resolution and quality are configurable. Defaults to progressive JPEGs optimized for the web.

Video manipulation

  • avimp4.sh: Convert AVI videos to MP4 format. More thorough than ffmpeg's default process, resulting in both smaller and better-quality videos.
  • 🌟 convertvid.sh: Convert any video files readable by ffmpeg (including but not limited to MP4, MPG, M4V, MOV, WEBM, WMV, AVI, 3GP) into modern H265-encoded MP4 file. This will generally be smaller in file size and more widely playable than other video formats.
  • copyvid.sh: Quick conversion of any file format to MP4.
  • fadevid.sh: Add a fade-in and fade-out, both visually (from/to black) and audially (from/to silence) to a video clip.
  • joinvid.sh: Combine videos.
  • markvid.sh: Add a watermark image to a video.
  • minvid.sh: Minify a video by re-encoding it and stripping metadata.
  • minsmvid.sh: Reduce video size even more than minvid, with second argument for bitrate.
  • stripvid.sh: Strip metadata from a video.
  • trimvid.sh: Trim MP4 videos with a starting timecode and a duration or stop timecode.
  • 🌟 vidcap.sh: Create screencaps of a video, that is, individual images from different time codes of the video. (Not to be confused with video captioning.)

Boilerplate code

A collection of patterns and snippets I use when writing scripts, many derived from William E. Shotts, Jr. See boilerplate for an overview.

Test files

See test for sample files and sources.

Usage

Download the script files you want. You might need to run chmod +x *.sh to make them executable.

You can use them only in the folder in which they reside, or you can make them system-wide. To do the latter, move them to ~/bin. Then, if you're not doing so already, export this directory to your PATH in .bash_profile, .bashrc, .zshrc, etc.:

export PATH="$HOME/bin:$PATH"

If you wish, you can also add aliases for them, saving three whole characters!

alias minvid="minvid.sh"

Dependencies

All scripts note any dependencies required.

I have tested these on Linux (Linux Mint, based on Ubuntu/Debian) using the Z Shell, but they should run in any Bash-compatible environment.

Linting

All scripts have shellcheck run on them with every save and are auto-formatted with shfmt using the Sublime Text plugin.

Other resources

You may also be interested in my local dotfiles (Linux), which also has flavors in Mac and Windows, as well as a hosted (Linux) setup.

License

GNU Affero General Public License v3.0 or later (AGPL 3+). See LICENSE.