Using ffmpeg on macOS to Correct AVI Index Errors and Convert to MP4

Standard

I’ve had a dashcam in my car for several years. My first dashcam worked great but after a few years it died. I replaced it with a less expensive unit and, as they say, you get what you pay for. It works OK. The quality and perspective isn’t as good as my first dashcam – it also doesn’t record GPS and current speed. If I replace this one I’m definitely going to get one that has features more similar to my first dashcam.

In addition, the video that I pull from the SD cards it records to usually have index errors, which prevent the videos from playing in most players (it works in VLC but requires a little bit of preprocessing to correct index issues). Obviously, this isn’t very good for something recording video that might one day be provided to law enforcement, compiled into a video poking fun at bad drivers or perhaps on the rare ocassion you’re nearly hit by a horse and rider as they gallop across a busy highway. I used ffmpeg to correct this issue with the last video prevoiusly linked.

One tool, ffmpeg, is well used across multiple platforms and extremely popular. It’s often a part of many other video editing applications. After some research, I found/modified examples to create a command that will convert AVI files to MP4. In this process ffmpeg will also correct index errors. It’s worked perfectly, as far as I can tell. While I have only used it in macOS Big Sur, it’s likely that this command (or only a slightly modified version of this command) would work on other platforms.

Convert AVI Files to MP4

for f in *.avi; do /Applications/ffmpeg -i "$f" -c copy -vcodec h264 -acodec aac "${f%.avi}.mp4"; done

Note that ‘/Applications/ffmpeg’ needs to be replaced with the path to your installation of ffmpeg. This command will loop through all AVI files within the same directory and convert them to MP4. Note that if you want to do more complex operations, such as processing multiple directories, you’ll need to do some research to figure that out.

ffmpeg is a free, open source program. You can find more information and binaries for download at https://ffmpeg.org/.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.