VideoHelp Forum
+ Reply to Thread
Results 1 to 21 of 21
Thread
  1. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    Hi

    Based on a previous post by jagabo, I have used this batch file to check for errors in an individual file where I drag and drop a mp4 file onto the batch file:

    c:\ffmpeg\bin\ffmpeg.exe -v error -i "%~dpnx1" -f null - >"%~dpnx1.error.txt" 2>&1

    Sample output:
    [h264 @ 000002175c2ed3a0] top block unavailable for requested intra4x4 mode -1 at 13 0
    [h264 @ 000002175c2ed3a0] error while decoding MB 13 0, bytestream 7

    How would I make a similar batch file for a folder of files?

    Also, I tried using mp4box to get info on a mp4 file:
    c:\gpac\mp4box.EXE -v -info "d:\This is My File.mp4"
    pause

    which does provide lots of information

    Again how would I make a batch file to get info on a folder of mp4 files?

    TIA
    Quote Quote  
  2. Try this. Run from within the folder with all the .mp4 files

    Code:
    for %f in (*.mp4) do ffmpeg.exe -v error -i "%~f1f" -f null - > "%~nff.error.txt" 2>&1
    Quote Quote  
  3. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Hi jack_666, can that me modified to iterate through the current folder and sub folders ?
    Last edited by JN-; 8th Feb 2023 at 14:41.
    Quote Quote  
  4. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @jack_666

    Thanks for your input - it kind of works

    I had to add the full path of ffmpeg and I had to change the % to %% and I had to remove the lf from "%~flf"

    when I tried

    for %%f in (*.mp4) do "c:\ffmpeg\bin\ffmpeg.exe" -v error -i "%%~f" -f null - > "%%~nff.error.txt" 2>&1
    pause

    I got this text output:

    MyFile.mp41f: No such file or directory

    when I removed the lf and tried this

    for %%f in (*.mp4) do "c:\ffmpeg\bin\ffmpeg.exe" -v error -i "%%~f" -f null - > "%%~nff.error.txt" 2>&1
    pause

    the command window did not separate the text files with a line break

    and the text output was:
    ^C

    but for some strange reason when I used this:

    for %%f in (*.mp4) do "c:\ffmpeg\bin\ffmpeg.exe" -v error -i "%%~f" lf -f null - > "%%~nff.error.txt" 2>&1
    pause

    text output for mp4 with no error
    [NULL @ 0000029f4697d200] Unable to find a suitable output format for 'lf'
    lf: Invalid argument

    text output for mp4 with error
    [mov,mp4,m4a,3gp,3g2,mj2 @ 000002a21987a4a0] moov atom not found
    MyFile1.mp4: Invalid data found when processing input

    and when I used 1 instead of lf

    for %%f in (*.mp4) do "c:\ffmpeg\bin\ffmpeg.exe" -v error -i "%%~f" i -f null - > "%%~nff.error.txt" 2>&1
    pause

    text output for mp4 file with no error
    [NULL @ 000001f60f7cd200] Unable to find a suitable output format for '1'
    1: Invalid argument

    text output for mp4 with error
    [mov,mp4,m4a,3gp,3g2,mj2 @ 000001e05781a4a0] moov atom not found
    MyFile1.mp4: Invalid data found when processing input

    so, for some reason when an "invalid argument", i.e. the use of lf or 1 is used the command prompt output show lines breaks when displaying the filenames and processes each outputted text file

    Obviously a better way to do this is to find the correct code to add line breaks
    Quote Quote  
  5. Please try
    Code:
    for /R %%f in (*.mp4) do ffmpeg.exe -v error -i "%%~ff" -f null - >  "%%~nff.error.txt"  2>&1
    echo.
    echo press any key to exit ... & pause>nul & exit


    The previous code was for running from the terminal. It looks like you prefer to run from a script.
    (for cmd scripts you need to change % to %%)


    Therefore, copy the above code and paste in the folder with all your other mp4 files. Save as "whatever.cmd"


    Double click to run.


    @JN-
    I have added the /R in the above script so as enable subfolder searches.
    Quote Quote  
  6. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Thanks Jack, ive been struggling for a while now, found the /R option, but cannot output the filename. Will look at that now and get back.

    for /R %%G in (*.mp4, *.mov) do echo --------------------------------------------------------------------------->>Error-List.txt& ffmpeg -v error -i "%%G" -f null - >>Error-List.txt 2>&1


    Typical output ... two files, 2 lines per file.
    --------------------------------------------------------------------------- Section 2 START
    [null @ 000001bbb9e05d00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 671 >= 667
    [null @ 000001bbb9e05d00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 671 >= 671
    [mov,mp4,m4a,3gp,3g2,mj2 @ 00000272ed8b34c0] moov atom not found
    PRETEND-Video-file-4.mp4: Invalid data found when processing input
    --------------------------------------------------------------------------- Section 2 END

    As you can see the top 2 lines is 1 file with problems, but I couldn't manage to output the filename.
    The third and fourth lines is also a single file, but it does give the filename.

    I will check out what you posted now and get back, thanks.
    Last edited by JN-; 8th Feb 2023 at 21:32.
    Quote Quote  
  7. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Well done Jack. I hope I am not intruding on the OP here, what I was hoping to achieve is to output to a "Single" text file with the file names of the problem files, with the errors.

    Your method works but involves a separate output file for all problem files.

    This nearly works but I cannot figure out how to output say the filename with the errors ...
    for /R %%G in (*.mp4, *.mov) do echo --------------------------------------------------------------------------->>Error-List.txt& ffmpeg -v error -i "%%G" -f null - >>Error-List.txt 2>&1

    I don't know how to insert that line into the "box"

    Some errors from the above syntax do output the filename as in my earlier post "6" but some file errors don't. What I am after may not be possible.

    My interest in this thread is that a few months back I accidently discovered that quite a few of my videos were corrupt, no idea how it happened. A buddy of mine noticed that the "Explorer" files icon on the corrupt files was different, so I was able to track down all of them and replace with a backup video.

    Using something like this, which I never knew existed would be a great way to say once or twice a year check it out. It would take a while to run be still extremely useful.
    Last edited by JN-; 8th Feb 2023 at 21:31.
    Quote Quote  
  8. @wiseant .... you have not been forgotten

    @ JN- please try this


    Code:
    type NUL >  Error-List.txt
    
    
    for /R %%G in (*.mp4, *.mov) do echo ------------------  Testing : "%%~fG" -------------------------------->> Error-List.txt & ffmpeg -v error -i "%%~fG" -f null - >> Error-List.txt 2>&1
    
    
    
    
    echo.
    echo press any key to exit ... & pause>nul & exit
    Quote Quote  
  9. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Fantastic, thank you. I was gone to bed (4AM)when I saw this post and now back at laptop, will really pay for this tomorrow, today.

    This is great. Will study it, but looks really great. Brilliant.
    Quote Quote  
  10. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    The FOR command is always tricky, for me anyway. I tried for a long time and couldn't get it, so I think I get it now, the way you got it working within the FOR command is using the f like Parameter Extensions,. "%%~fG"

    Thanks to your code I was able to get what I wanted, very useful, thanks Jack and thanks wiseant for bringing this issue up, I intend to make use of it.

    FWIW This is what I finished up with. I didn't include the "duration" code as it would be too long but have included the reference.

    @echo off
    cls
    color 0A
    SETLOCAL EnableDelayedExpansion
    mode CON:cols=150 lines=20
    TITLE Get video files Errors. Start Date and Time [%DATE%] ... [%TIME%].

    REM Get duration var reference ...
    REM by Yinon, 7th-Oct-2014
    REM http://stackoverflow.com/questions/9922498/calculate-time-difference-in-windows-batch-file
    CALL URATION_PART1

    REM Parameter Extensions, some used below: Example C:\utils\MyFile.txt

    REM %~f1 = Expand %1 to a Fully qualified path name - C:\utils\MyFile.txt
    REM %~d1 = Expand %1 to a drive letter only - C:
    REM %~p1 = Expand %1 to a PATH - \utils\ this includes a trailing \ which will be interpreted as an escape char by some commands.
    REM %~n1 = Expand %1 to a file Name only - MyFile
    REM %~x1 = Expand %1 to a file eXtension only - .txt

    REM Use next line to reset/delete output file.
    REM type NUL > Error-List.log
    REM If exist Error-List.log del Error-List.log

    echo.>>Error-List.log
    echo ------------------------------------------------------------------------------------------ [%DATE%] ... [%TIME%] --------------------------------------------------------------------------- START>>Error-List.log
    REM the extension is not case sensitive i.e. .mts can catch .MTS also. "%%~fG" has to be enclosed in "" to handle filenames with spaces in them.

    SET /A _FILES_FOUND=0

    for /R %%G in (*.mp4, *.mov, *.mts, *.avi) do (
    echo.>>Error-List.log
    echo ------------------------------------------------------------------------------------------------------------------------- [%%~nxG] ... [%%~pG]>>Error-List.log
    ffmpeg -v error -i "%%~fG" -f null - >> Error-List.log 2>&1
    SET /A _FILES_FOUND+=1
    TITLE Get video files Errors. Start Date and Time [%DATE%] ... [%TIME%]. Files found = [ !_FILES_FOUND! ].
    )

    CALL URATION_PART3
    echo.>>Error-List.log
    echo -------------------------------------------->>Error-List.log
    echo Duration = [%_TOTAL_TIME_TAKEN_%]. Files found = [%_FILES_FOUND%].
    echo Duration = [%_TOTAL_TIME_TAKEN_%]. Files found = [%_FILES_FOUND%].>>Error-List.log
    echo -------------------------------------------->>Error-List.log
    echo.>>Error-List.log
    echo ------------------------------------------------------------------------------------------ [%DATE%] ... [%TIME%] --------------------------------------------------------------------------- END>>Error-List.log
    echo  & REM To notify processing has ended.
    echo   & REM Black on Black, to hide the TIMEOUT countdown display.
    TIMEOUT 2 & REM If I don't use a short delay, the bell won't sound.
    cls
    color
    SET _FILES_FOUND=
    EXIT
    Last edited by JN-; 9th Feb 2023 at 19:55.
    Quote Quote  
  11. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @jack_666

    Code:
    for /R %%f in (*.mp4) do ffmpeg.exe -v error -i "%%~ff" -f null - >  "%%~nff.error.txt"  2>&1
    echo.
    echo press any key to exit ... & pause>nul & exit
    Unfortunately this code does not work - it only processes the first mp4 and the text file is blank

    But if I add an invalid argument i.e. 1 as I did before, it gets the same result as before:

    text output for mp4 file with no error
    [NULL @ 000001f60f7cd200] Unable to find a suitable output format for '1'
    1: Invalid argument

    text output for mp4 with error
    [mov,mp4,m4a,3gp,3g2,mj2 @ 000001e05781a4a0] moov atom not found
    MyFile1.mp4: Invalid data found when processing input

    it does process sub-directories
    Quote Quote  
  12. @JN- ... You are most welcome. The pleasure was mine. Also, sorry I kept you up so late and thanks you sharing your script.
    Quote Quote  
  13. @wiseant

    Usage instructions:


    1) Within your folder containing all your mp4 files, right click ==> New ==>
    2) name the txt document whatever.txt
    3) double click whatever.txt and a blank file opens in Notepad
    4) Copy the required code that I posted and paste into the blank Notepad document. (Ctrl C, Ctrl V)
    5) Click File ==>Save As ==> whatever.cmd (note the extension change)
    6) double click whatever.cmd
    7) the code will now run.


    It may take a long time to complete a mp4 file especially if it is large. You have to wait until "press any key to exit" is displayed


    Suggest that you create a new folder with, say, three mp4 files (the smallest ones). Execute the process.


    Another suggestion is to use the code that I provided to JN-. This is possible a better solution to your challenge.


    Hope this helps.

    Another suggestion is for you to upload your file with error so that someone can have a look.


    My unerstanding is that a blank output means that ffmpeg did not find an error
    Quote Quote  
  14. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    @jack_666 "sorry I kept you up so late" Worth it ! I'm currently running it against 2 separate folders of 194 and 234 video clips, two separate instances, it'll take a while.

    Useful to have.


    "My unerstanding is that a blank output means that ffmpeg did not find an error" That seems to be the case.
    Quote Quote  
  15. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @jack_666

    I am running a batch file

    I copied the code - pasted into notepad++ - saved as .bat file
    Quote Quote  
  16. And?
    Quote Quote  
  17. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @jack_666

    As I mentioned in post #11
    Quote Quote  
  18. You can speed up checking (although detecting fewer errors) by processing only an audio track, no video:

    Code:
    -map 0:a:0
    Quote Quote  
  19. @wiseant

    you are telling me that you ran the code


    for /R %%f in (*.mp4) do ffmpeg.exe -v error -i "%%~ff" -f null - > "%%~nff.error.txt" 2>&1

    echo.

    echo press any key to exit ... & pause>nul & exit


    in a folder with several mp4 files and it only processes the first mp4 and then you see


    echo press any key to exit ... & pause>nul & exit


    This does not make any sense.
    Quote Quote  
  20. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @jack_666

    Success

    My mistake was a lack of patience - I was using my slower computer and the first mp4 file was rather large - I didn't see any results so I ended the batch

    When I used my faster computer [ i5-12400 CPU] and noticed that the cpu usage was 99% - I let it do its thing:

    125 files with a total size of 221.70 GB with a total playing time of 94 hours took 142 min = 1.56 GB per minute

    8 mp4 files have significant errors

    Thanks jack_666
    Quote Quote  
  21. you are most welcome.

    The person that should get the credit is jagabo, after all it was his code that was used
    Last edited by jack_666; 10th Feb 2023 at 23:42.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!