If you’ve ever used the record button on VLC and have found that the .avi file that was created always seems to pop up a message either asking you what you want to do about repairing the index or, because of some changed settings, will automatically try to repair the index before playing, and/or you find that you can’t use seek on an .avi file because of the index issue, and you’ve wondered how can you get VLC to fix the .avi file permanently so that it doesn’t have to keep building the index, then read on for how I overcame this issue.
While there are a multitude of ways to go about fixing the video file or something equivalent to make it work properly, unless you really need it to be in .avi format, I would go about converting the file to an .mkv using FFmpeg as a solution.
Unfortunately, that means the solution below isn’t literally “fixing the .avi” video file itself per se, whereby you would be able to use that same exact .avi file, but it does create a copy of it that should play in most modern devices, including a smart TV or Roku device.
For those who are already familiar with using FFmpeg
The command line that I use is:
ffmpeg -i "vlc-record-YYYY-MM-DD-23h56m37s-YourFile.avi" -map 0 -c copy "converted-vlc-record-YourFile.mkv"
Obviously, replace the filename in the quotation marks for your specific file and remember to include the full path if you’re not already in the directory of where the video file you wish to convert is located.
To be sure, replace the items in brackets “[ ]” and remove the brackets themselves:
ffmpeg -i "[FILEPATH/to/YOURbroken.avi]" -map 0 -c copy "[FILEPATH/to/the/NEWvideoFile.mkv]"
For those that may be wondering, you can use another file format in place of .mkv, such as .mp4 for example, but because the recorded broken .avi file can come from different sources (such as recording a RTMP stream, an RSTP stream, a security camera, etc.) and how VLC encodes it will depend on one’s settings, so I use .mkv because it has support for more codecs and because of that, it is less likely to run into errors when creating the output format.
Explanation of commands
-map 0 # Tells FFmpeg to select all streams. Although the command is generally used when you're specifying more than one input file, by default, or if you don't use the -map option, FFmpeg will NOT automatically choose ALL of the streams, only 1 stream per type will be selected. Read more on mapping here or learn the specific criteria used for automatic selection here. -c copy # Enables stream copy mode. This prevents FFmpeg from decoding and encoding for the specified stream and only does demuxing and muxing. In other words, it only changes the container format and since there's no decoding or encoding, it's very fast with no quality loss.
For Those Unfamiliar with FFmpeg
First, you’ll likely already have it installed but if not, you’ll need to download FFmpeg. FFmpeg is a free and open-source software project consisting of a suite of libraries and programs for handling video, audio, and other multimedia files and streams. We’ll be using the command-line FFmpeg tool itself which was designed for processing of video and audio files. Download it here.
To be sure, and to keep it simple for less advanced users, choose the download for your OS version under “Get packages & executable files“. Or, go straight to the source for the latest Windows/Linux versions here. If you’re downloading from the Github page and are on Windows, select the version with the word “master” in it that ends in .zip (to fair on the safe & more simple side, go with the one ending in “gpl” — it just means it includes all dependencies).
Unzip the file to a location you will remember and open the “bin” folder. There you will find 3 executable files. The one you’re interested in is the one named “ffmpeg.exe”
From here, there are a few ways you can proceed. You can either:
- Add the directory containing the .exe to your PATH
- Copy the file address to the your clipboard of where it’s located (the folder address of where you unzipped it)
- Copy the .exe file to the folder where your video files are located or move your video files to the same folder as the .exe file
If you don’t know how to do the first option, and you simply want to copy and paste the command later shown below while only replacing the file names without worrying about the file path and whatnot, then I would suggest that you just copy or move the ffmpeg.exe file to the directory where all your video files that you want to “fix” are located.
Regardless of what you decide, you’ll need to open the Windows Command Prompt. You can either press Win+R to open a run dialog where you can just type “cmd” and hit enter or run to open the command prompt, or press the Start Menu button and start typing “command” and it should be the first option that pops up as shown below.
With the command prompt open, you’ll need to navigate to the folder with your video files and/or the folder containing the FFmpeg.exe file. If your videos are in your user’s “Videos” folder and you moved/copied FFmpeg.exe there, and you haven’t changed any settings for the folder such as moving locations, you can simply type or copy and paste (using right-click on your mouse to paste) this into the command prompt window:
To be sure, the command line will look something like this:
This is because by default, Command prompt opens you to the home directory of your user account which contains the folders such as Documents, Photos, etc. so after typing that command and hitting enter, the command prompt should now show something like this:
You can make sure your video files and the ffmpeg.exe file is all there by typing “dir” and hitting enter. It will list all files and folders in the current folder (AKA Directory) you’re in, which should be the Videos folder/Directory.
Now to make the magic happen!
Type the command below, replacing [YourBrokenVideo.avi] with the filename of the .avi file with the broken index and replacing [NewFile.mkv] with what you would like to name the new copy that’s going to be made. To be sure, remove the brackets but keep the quotation marks when replacing each placeholder mentioned, then hit enter:
ffmpeg.exe -i "[YourBrokenVideo.avi]" -map 0 -c copy "[NewFile.mkv]"
You should see ffmpeg.exe start to work and report a bunch of data on your screen. When it’s all done, it will go back to the command line prompt which just means you’ll be back to seeing the same line as before when you didn’t enter the command yet. You’ll also be able to open explorer and see your new video file sitting in your Videos folder, ready to be played.
That’s it, you’re all done! You can close the command prompt by either typing “exit” and hitting enter, or simply closing the box using the “X” at the top right.