FFMPEG Fixes Your… Everything!

This is quite a popular post: iCompile- FFMPEG Fixes Your Video Files.

You can make FFMPEG fix pretty much every media-type (while still preserving important data such as cover-art and other meta-tags)

@echo off

set FILE_INPUT="%~s1"
set FILE_OUTPUT="%~d1%~p1%~n1__FIXED%~x1"

call ffmpeg.exe -y -hide_banner -loglevel "info" -stats        ^
-flags             "-loop+naq+low_delay+global_header"         ^
-fflags            "-fastseek+genpts+discardcorrupt+nofillin"  ^
-flags2            "+fast+ignorecrop+showall+export_mvs"       ^
-avoid_negative_ts "make_zero"                                 ^
-analyzeduration   "2000000"                                   ^
-threads 16                                                    ^
-i %FILE_INPUT%                                                ^
-movflags          "+rtphint+dash+disable_chpl+faststart"      ^
-map_metadata      "0" -write_id3v2 "1" -id3v2_version "3"     ^
-c copy                                                        ^
%FILE_OUTPUT%

pause

It is, also, super-fast, since there is no actual-encoding happening, just mux’ing.

 _______              ______________            ________
|       |            |              |          |        |
| input |  demuxer   | encoded data |  muxer   | output |
| file  | ---------> | packets      | -------> | file   |
|_______|            |______________|          |________|


The __FIXED suffix, can help you quickly identify the fixed-files in the entire folder,
for example, here is how to list them all:

@echo off

echo # Media-List(%DATE% %TIME%) >list.txt
for %%e in (*__FIXED.*) do (
  echo file '%%e' >>list.txt
)

The list above can be used to concatenate all of the media-files, into one container:

@echo off

call ffmpeg.exe -y -hide_banner -loglevel "info" -stats        ^
-safe "0"  -f concat  -i "list.txt"                            ^
-c copy                                                        ^
-threads 16                                                    ^
-flags             "-loop+naq+low_delay+global_header"         ^
-fflags            "-fastseek+genpts+discardcorrupt+nofillin"  ^
-flags2            "+fast+ignorecrop+showall+export_mvs"       ^
-movflags          "+rtphint+dash+disable_chpl+faststart"      ^
-avoid_negative_ts "make_zero"                                 ^
-analyzeduration   "2000000"                                   ^
-map_metadata      "0" -write_id3v2 "1" -id3v2_version "3"     ^
output.mkv

pause

Fix A Lot Of Files At The Same Time

Say you have couple of audio files:

Copy&paste this to _file.cmd:

@echo off

set FILE_INPUT=%~s1
set FOLDER_OUTPUT=%~d1%~p1FIXED
set FILE_OUTPUT=%~n1%~x1

if NOT exist "%FOLDER_OUTPUT%\"    mkdir "%FOLDER_OUTPUT%\"

call ffmpeg.exe -y -hide_banner -loglevel "info" -stats        ^
-flags             "-loop+naq+low_delay+global_header"         ^
-fflags            "-fastseek+genpts+discardcorrupt+nofillin"  ^
-flags2            "+fast+ignorecrop+showall+export_mvs"       ^
-avoid_negative_ts "make_zero"                                 ^
-analyzeduration   "2000000"                                   ^
-threads 16                                                    ^
-i "%FILE_INPUT%"                                              ^
-movflags          "+rtphint+dash+disable_chpl+faststart"      ^
-map_metadata      "0" -write_id3v2 "1" -id3v2_version "3"     ^
-c copy                                                        ^
"%FOLDER_OUTPUT%\%FILE_OUTPUT%"

exit

and this to _start_all.cmd:

@echo off
echo I am the runner
for %%e in (*.mp3 *.acc *.m4a) do (
  start /low "cmd /c "call _file.cmd "%%e"""
)

Note: you may modify (*.mp3 *.acc *.m4a) to include any other media-file!

Place the cmd files at the same folder as the media-files:

and run the _start_all.cmd,
all the files will be fixed in parallel, instead of one-after-the-other.
overall it will take about ~2 seconds :]

Fixed files will be placed under a new folder named: FIXED (the files will have the same name as the original).

Leave a Reply