Skip to content
Skip to the article
In Linux: 9 articles
Linux

Media Conversion Recipes

ffmpeg and potrace recipes for still-image videos, batch audio conversion, remuxing, and vectorizing scanned TIFF images to PDF.

Updated
Applies to
  • ffmpeg 7
  • potrace 1.16
  • ImageMagick 7
Tags
  • ffmpeg
  • potrace
  • imagemagick
  • media
  • bash
Reading time
3 min

Command-line recipes for converting audio, video, and scanned images in bulk. Install the tools with apt install ffmpeg potrace imagemagick on Ubuntu, or nix profile add nixpkgs#ffmpeg nixpkgs#potrace nixpkgs#imagemagick with Nix (nix profile install on older Nix releases).

Make a Video from One Image and an Audio File

Turn a podcast episode or recording into an MP4 for video platforms by looping a single still image over the audio:

ffmpeg -loop 1 -framerate 1 -i picture.png -i audio.wav \
  -c:v libx264 -tune stillimage -pix_fmt yuv420p -vf scale=1280:720 \
  -c:a aac -b:a 192k -shortest -movflags +faststart episode.mp4
  • -loop 1 -framerate 1 repeats the image at one frame per second, which keeps the file small.

  • -tune stillimage and -pix_fmt yuv420p give an H.264 stream that plays everywhere.

  • -shortest ends the video when the audio ends.

  • -movflags +faststart lets playback start before the whole file downloads.

For smaller files on players that support HEVC, use -c:v libx265 instead (and drop -tune stillimage, which is x264-only).

Convert All Files in a Directory Tree

Convert every FLAC file under the current directory to AAC, recreating the same folder structure under an output directory:

find . -type f -iname '*.flac' -exec sh -c '
  for f; do
    out="$0/${f%.*}.m4a"
    mkdir -p "$(dirname "$out")"
    ffmpeg -nostdin -loglevel error -n -i "$f" -c:a aac -b:a 256k "$out"
  done
' <OUTPUT_DIR> {} +

Run it from the top of the source tree. <OUTPUT_DIR> is passed to the inner shell as $0. -n skips files that already exist, so you can safely re-run it after an interruption. -nostdin keeps ffmpeg from swallowing the file list. The .m4a container plays more widely than raw .aac.

Change the Container Without Re-encoding

Copy every stream into a different container format, for example MKV to MP4. This takes seconds because nothing is decoded:

ffmpeg -i input.mkv -map 0 -c copy output.mp4

If ffmpeg reports that a codec isn't supported in the target container (common with subtitles in MP4), drop that stream type, for example with -map 0 -map -0:s.

Vectorize Scanned TIFF Images to PDF

Trace black-and-white scans (line drawings, signatures, plans) into scalable vector PDFs. potrace reads bitmap formats such as PBM, so convert each TIFF to a thresholded bitmap first:

for f in *.[Tt][Ii][Ff]; do
  magick "$f" -colorspace Gray -threshold 50% "${f%.*}.pbm"
  potrace -b pdf -o "${f%.*}.pdf" "${f%.*}.pbm"
  rm "${f%.*}.pbm"
done

Adjust -threshold if thin lines vanish (raise it) or the background speckles (lower it). Use -b svg instead to get SVG files for editing in Inkscape. On ImageMagick 6, use convert instead of magick.

Note

Older notes used autotrace for this, which can also trace color images: autotrace -background-color FFFFFF -output-format svg -output-file out.svg in.tif. autotrace is no longer packaged for Ubuntu 24.04, so prefer potrace for black-and-white work, or Inkscape's Trace Bitmap for color images.

Sources

This article is in the public domain (CC0 1.0), code samples included. Use it however helps you.