VideoHelp Forum

+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Hi, and i'm a cat

    and even though.

    ---

    I try to do a batch file that concatenate using ffmpeg all the .mp4 in a directory, but first have to analize all the files parsed to verify is all the files have:

    the same resolution
    the same framerate
    the same codec
    the rotation flag

    At the moment I have build this code that simply concatenate all the .mp4 except for the final concatenated one (using fart.exe to delete the output file from the list of files to be concatenated)

    Code:
    @Echo Off
    
    color 6
    
    if exist concatList.txt del concatList.txt
    
    setlocal
    
    for %%f in (*.mp4) do echo file '%cd%\%mypath%%%f' >> "concatList.txt"
    
    fart.exe concatList.txt "file '%cd%\conCAT.MP4'" --remove
    
    endlocal
    
    ffmpeg64bit_2019.exe -y -threads 12 -y -f concat -safe 0 -i concatList.txt -map 0:? -ignore_unknown -vcodec copy -acodec copy -aspect 16:9 conCAT.MP4
    
    if exist concatList.txt del concatList.txt
    
    exit
    supposing in a folder are present 120.mp4 121.mp4 122.mp4 123.mp4, the batch have to concatenate all in one unique conCAT.MP4.
    In this case, for example, concatlist.txt become

    Code:
    file 'C:\Users\Administrator\Desktop\Loris\120.mp4' 
    file 'C:\Users\Administrator\Desktop\Loris\121.mp4' 
    file 'C:\Users\Administrator\Desktop\Loris\122.mp4' 
    file 'C:\Users\Administrator\Desktop\Loris\123.MP4'
    But only if they have the same resolution the same framerate the same codec the rotation flag... if they are identical. How can I do thanks
    ?
    Quote Quote  
  2. Blu-Disc Studio developer CDK's Avatar
    Join Date
    Oct 2013
    Location
    Poland
    Search PM
    You can use MediaInfo to get this info:
    Code:
    MediaInfo.exe file.mp4 > file.txt
    And now you need to find and compare several lines in text files. I don't know how to do it in a command line, but I think it should be possible...

    PS: this can help https://stackoverflow.com/questions/41231998/mediainfo-cli-command-line-interface-synt...e-once-for-all
    Last edited by CDK; 31st Jul 2022 at 09:31.
    Quote Quote  
  3. an idea to start would be

    :

    Code:
    @Echo Off
    
    color 6
    
    if exist concatList.txt del concatList.txt
    if exist %cd%\conCAT.MP4 del %cd%\conCAT.MP4
    
    setlocal
    
    for %%f in (*.mp4) do echo file '%cd%\%mypath%%%f' >> "concatList.txt"
    fart.exe concatList.txt "file '%cd%\conCAT.MP4'" --remove
    for /f "delims=" %%F in ('dir *.MP4 /b /o-n') do set FirstFile="%cd%\%%F"
    echo 1st file is %FirstFile%
    pause
    
    mediainfo.exe %FirstFile% dumpinfo:unicodefile.txt
    TYPE unicodefile.txt>mediainfo.txt
    
    rem *********
    
    IF exist unicodefile.txt DEL unicodefile.txt
    IF exist mediainfo.txt DEL mediainfo.txt
    
    endlocal
    
    
    ffmpeg64bit_2019.exe -y -threads 12 -y -f concat -safe 0 -i concatList.txt -map 0:? -ignore_unknown -vcodec copy -acodec copy -aspect 16:9 conCAT.MP4
    if exist concatList.txt del concatList.txt
    
    exit
    where if in a folder there is (for example) 120.mp4 121.mp4 122.mp4 123.mp4

    %FirstFile% assume 120.mp4 as first file.
    Mediainfo should parse %FirstFile% and store resolution, framerate, rotation and codec info and compare the info with all other .mp4 to verify if all the .mp4 files are concatenable

    If the files do not have the same characteristics, the batch returns an error and exits. If they are similar it continues in the concatenation process.

    Really it would be perhaps interesting that if the batch finds a rotated file (for example by 90 ) it is first remuxed as straight and then concatenated, but this is already another question)
    I
    Quote Quote  
  4. #24 input and further there are some subroutines that you can use:
    https://forum.videohelp.com/threads/377677-Video-batch-files

    but for all kids out there, if deciding to make some codes to automatize processes, do not do this using microsoft batch code, use python instead
    Quote Quote  
  5. interesting batch, even if at the moment I don't seem to find something that exactly compares the metadata of several files one with the others. In practice it would be a question of comparing if the resolution-framerate-idcodec-rotation of all the files present in a folder are exatly the same. If anyone wants to help the cat
    Quote Quote  
  6. you have a subroutine that gives you w, h, fps (add codec and rotation) of the first file, save them to different variables

    then run that subroutine for each file and if file does not have the same values as those in first file, do not add them in the list
    Quote Quote  
  7. thanks but a litte complicated for a cat-brain

    however I would like to do another thing, if someone helps me: we still consider the original batch. When I run the batch inside a folder that contains some .mp4 files it generate a final file called concat.txt which contains the names of the individual .mp4 files. But now I need to generate also a concat.txt of the only file drag and dropped to the batch. In this case how should I modify the batch?
    Quote Quote  
  8. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Hi marcorocchini, you can use ffmpegs ffprobe to get these items
    resolution
    framerate
    codec

    Not at PC now so not sure about rotation.
    Quote Quote  



Similar Threads