Using FFmpeg to save old movies from ASF format

Recently, I was rummaging through my digital archives and bumped into many old videos with a .ASF extension. Now, I’m no stranger to odd file formats, but this one had me scratching my head. Thankfully, VLC Player came to my rescue for playback, but when it came to converting these to a format I could drop into my Apple Photos library, I needed something usable like MP4. I tried using VLC to do the conversion, but when using VLC it kept dropping the audio and wouldn’t do a batch, so I had to figure out another way to do it. In the end, I decided to go with FFmpeg in the terminal.

Getting it installed on macOS is very easy with Homebrew just run:

brew install ffmpeg

Once installed you can use terminal command to find and convert all the .ASF in the current directory:

find . -iname ".asf" -exec sh -c 'ffmpeg -i "$1" -c:v copy -c:a aac "${1%.}.mp4"' sh {} \;

After that, just wait for it to convert everything and then you should be good to go! If your are curious what the command does, here is a breakdown:

  1. find . This initiates the find command in the current directory (.). find is used to search for files and directories in a directory hierarchy.
  2. -iname "*.asf" The -iname option enables case-insensitive matching. Here, it’s used to find all files with the .asf extension. *.asf matches any file that ends with .asf.
  3. -exec: This option of find allows you to execute a command on each file found.
  4. sh -c '...' sh {} \; This complex construction executes a shell command.
    • sh -c tells find to execute the following command in a new shell.
    • The {} is a placeholder for each file find locates.
    • \; marks the end of the command to be executed by -exec.
  5. ffmpeg -i "$1"
    • ffmpeg is a command-line tool used for converting multimedia files.
    • -i "$1" tells ffmpeg to take the input file. $1 is the first argument passed to the shell script from find (i.e., each .asf file found).
  6. -c:v copy
    • -c:v specifies the codec for the video.
    • copy means it will copy the video stream from the source file without re-encoding.
  7. -c:a aac
    • -c:a specifies the audio codec.
    • aac is the audio codec used for the output file. It converts the audio stream to the AAC format.
  8. "${1%.*}.mp4"
    • This part is used to name the output file.
    • "${1%.*} strips the extension from the input filename ($1) and .mp4 adds the new extension. So, if your file was video.asf, it becomes video.mp4.

Leave a Reply