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 thefind
command in the current directory (.
).find
is used to search for files and directories in a directory hierarchy.-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
.-exec
: This option offind
allows you to execute a command on each file found.sh -c '...' sh {} \;
This complex construction executes a shell command.sh -c
tellsfind
to execute the following command in a new shell.- The
{}
is a placeholder for each filefind
locates. \;
marks the end of the command to be executed by-exec
.
ffmpeg -i "$1"
ffmpeg
is a command-line tool used for converting multimedia files.-i "$1"
tellsffmpeg
to take the input file.$1
is the first argument passed to the shell script fromfind
(i.e., each .asf file found).
-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.
-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.
"${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 wasvideo.asf
, it becomesvideo.mp4
.