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:
find .This initiates thefindcommand in the current directory (.).findis used to search for files and directories in a directory hierarchy.-iname "*.asf"The-inameoption enables case-insensitive matching. Here, it’s used to find all files with the.asfextension.*.asfmatches any file that ends with.asf.-exec: This option offindallows you to execute a command on each file found.sh -c '...' sh {} \;This complex construction executes a shell command.sh -ctellsfindto execute the following command in a new shell.- The
{}is a placeholder for each filefindlocates. \;marks the end of the command to be executed by-exec.
ffmpeg -i "$1"ffmpegis a command-line tool used for converting multimedia files.-i "$1"tellsffmpegto take the input file.$1is the first argument passed to the shell script fromfind(i.e., each .asf file found).
-c:v copy-c:vspecifies the codec for the video.copymeans it will copy the video stream from the source file without re-encoding.
-c:a aac-c:aspecifies the audio codec.aacis the audio codec used for the output file. It converts the audio stream to the AAC format.
"${1%.*}.mp4"- This part is used to name the output file.
"${1%.*}strips the extension from the input filename($1)and.mp4adds the new extension. So, if your file wasvideo.asf, it becomesvideo.mp4.