VideoHelp Forum
+ Reply to Thread
Results 1 to 7 of 7
Thread
  1. Hello,

    I convert .mp4 files to .ts format using this ffmpeg cmd:

    ffmpeg -i video1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts video1.ts

    But obviously, it is to convert a single file. I would to adapt this command to batch convert all the mp4 of my entire folder. Can you tell me what would be the command to do so?

    I already prepared a txt file ready with the list of the mp4 files, since I assume I would need it. I named it "list_mp4_to_ts.txt", and this is its content:

    file 'video1.mp4'
    file 'video2.mp4'
    file 'video3.mp4'

    Thank you!
    Quote Quote  
  2. You don't even need a list.
    Copy the code and save it to your desktop as yourname.cmd.
    Select your .mp4 files and drag and drop them onto that icon on your desktop.

    Code:
    @echo off
    :next
    if "%~1"=="" goto done
    
    ffmpeg -y -i "%~1" -c copy -bsf:v h264_mp4toannexb -f mpegts "%~1.ts"
    
    shift
    goto next
    :done
    Quote Quote  
  3. Great, thank you! I wasn't familiar with cmd files. And if I wanted to use a list, can you tell me what would be the command?
    Quote Quote  
  4. Code:
    @echo off
    
    for /f "delims=" %%x in (filelist.txt) do call :encode "%%x"
    echo done
    ENDLOCAL&echo press any key to exit&pause>nul&exit
    
    :encode <video file>
    ffmpeg -y -i "%~1" -c copy -bsf:v h264_mp4toannexb -f mpegts "%~1.ts"
    goto :eof
    do not forget quotes around "%%x" otherwise it would read paths with spaces wrong
    Quote Quote  
  5. did not notice you have "file " proceeding each line in your text file and removing apostrophe from both ends:
    Code:
    @echo off
    
    for /f "delims=" %%x in (filelist.txt) do call :process "%%x"
    echo done
    ENDLOCAL&echo press any key to exit&pause>nul&exit
    
    :process <line>
    rem remove string: "file " from line and then removing first and last character (that apostrophe mark: ')
    set "path=%~1"
    set "path=%path:file =%"
    set path=%path:~1,-1%
    call :encode "%path%"
    goto :eof
    
    :encode <video file>
    ffmpeg -y -i "%~1" -c copy -bsf:v h264_mp4toannexb -f mpegts "%~1.ts"
    goto :eof
    Last edited by _Al_; 12th Feb 2024 at 11:35.
    Quote Quote  
  6. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    No need to prepare any txt file. All *.mp4 in dir will be converted.

    Code:
    @echo off
    dir/b *.mp4 >mp4list.txt
    for /F "delims=;" %%F in (mp4list.txt) do ffmpeg -i "%%F" -c copy -bsf:v h264_mp4toannexb -f mpegts "%%~dF%%~pF%%~nF.ts"
    del mp4list.txt
    pause
    Last edited by rgr; 16th Feb 2024 at 12:21.
    Quote Quote  
  7. Great, thank you for your answers.
    Quote Quote  



Similar Threads

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