Q: Video modifications using ffmpeg and windows batch command I have a series of 8 videos which have different number of frames, some of them lose a couple of them at the beginning. I was trying to concatenate at the beginning of the videos with less frame a copy of their first frame. Unfortunately my code either crash while comparing the length of the videos or fail to accomplish the task required. Here I add the code that I'm using.
@ECHO off
SETLOCAL EnableDelayedExpansion
MKDIR COMPRESSED\
MKDIR RAW\
SET  j=0
SET  jj=1
SET max=1
FOR %%a IN (*.avi) DO (
    SET /A j=j+1
    FOR /F "delims=" %%V IN ('ffprobe.exe -v error -count_frames -select_streams v:0 -show_entries stream^=nb_read_frames -of       default^=noprint_wrappers^=1:nokey^=1 ".\%%~nxa" 2^>^&1') DO SET elem[!j!]=%%V
SET elem[!j!]
)

FOR %%a IN (*.avi) DO (
    IF !elem[%jj%]! GTR !elem[%max%]!(
        SET max=!jj!
    )
SET /A jj=jj+1  
) 
SET max

SET /A x=1
FOR %%a IN (*.avi) DO ( 

    IF "!elem[!x!]!" LSS "!elem[!max!]!" (
            ffmpeg -i ".\%%~nxa" -vf "select=eq(n\,0)" -q:v 3 output_image.jpg
            ffmpeg -y -i ".\%%~nxa" -loop 1 -i output_image.jpg -t 0.01 -s 1936x1216 ".\%%~nxa"
            SET elem[!x!]=elem[!x!]+1
            SET elem[!x!]                   
    )
SET /A x=x+1    
) 


FOR %%a IN (*.avi) DO (
    ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames ".\%%~nxa"
    ffmpeg -i ".\%%~nxa" -c:v libxvid -vtag xvid -qscale:v 2 -force_key_frames 1 -s 968x400 -r 100 ".\COMPRESSED\%%a"
    SET mystr=%%~na
    SET mystr=!mystr:~-1!
    IF !mystr! == 3 (
        ffmpeg -i ".\%%~nxa" -c:v mpeg4 -b:v 4M -c:a libfdk_aac -b:a 192k ".\COMPRESSED\%%~na.mp4"
    )
    IF !mystr! == 5 (
        ffmpeg -i ".\%%~nxa" -c:v mpeg4 -b:v 4M -c:a libfdk_aac -b:a 192k ".\COMPRESSED\%%~na.mp4"
    )
)

