VideoHelp Forum




+ Reply to Thread
Results 1 to 7 of 7
  1. Member Ygramul's Avatar
    Join Date
    Jan 2007
    Location
    Poland
    Search Comp PM
    I have a folder with 80 .mp4 files (AVC + AAC). They're all about 2-8 minutes long. I want to trim the first minute from all of them without re-encoding while keeping the filenames.

    I read somewhere that in order to accomplish this I need to use a "loop". I tried this just to test:

    Code:
    for i in *.mp4; do 
        ffmpeg -i "$i" -c copy \
        -f segment -segment_time 600 \
        -reset_timestamps 1 \
        "${i/%.mp4/_part%02d.mp4}"; 
    done
    Unfortunately, I'm getting "i was unexpected at this time".
    Quote Quote  
  2. windows batch file:

    Code:
    for %%i IN (*.mp4) do (
    ffmpeg -ss 60 -i "%%i" -c copy  "%%~ni.cut.mp4
    )
    Note that the first frame will be at the i-frame closest to the desired cut point. That could be several seconds away.
    Quote Quote  
  3. Member Ygramul's Avatar
    Join Date
    Jan 2007
    Location
    Poland
    Search Comp PM
    Originally Posted by jagabo View Post
    windows batch file:

    Code:
    for %%i IN (*.mp4) do (
    ffmpeg -ss 60 -i "%%i" -c copy  "%%~ni.cut.mp4
    )
    Note that the first frame will be at the i-frame closest to the desired cut point. That could be several seconds away.
    Hey, thanks. Although in the meantime I found another script that works.

    Just one more question: is putting the whole path to ffmpeg.exe in the script a thing of the past? Is it enough to just have the file in the same folder as the input files?
    Quote Quote  
  4. is putting the whole path to ffmpeg.exe in the script a thing of the past? Is it enough to just have the file in the same folder as the input files?


    If the operating system (os) does not know the location of the executable, then the os will not be able to run the executable. The os, by default, will search the pwd (present working directory) for the executable.


    You have to inform the os the location of the executable via (a) the path environment variable or (b) place the executable within the pwd or (c) write the whole path explicitly within the command call.


    Having the executable within the pwd runs the risk of having multiple copies of the file present on your system
    Quote Quote  
  5. Originally Posted by Ygramul View Post

    Hey, thanks. Although in the meantime I found another script that works.
    Would be nice to put in thread script that works for you.

    Originally Posted by Ygramul View Post
    Just one more question: is putting the whole path to ffmpeg.exe in the script a thing of the past? Is it enough to just have the file in the same folder as the input files?

    Depends on usage context but it is always better to properly initialize your environment as at some point you may have various ffmpeg versions and they may or not support for example filters you are trying to use. Then you are forced to investigate why something worked previously suddenly not works.

    I use such script so i can easily point to desired ffmpeg folder

    Code:
    @setlocal
    
    @REM Where to Find ffmpeg
    @rem set FFMPG=C:\FF
    @set FFMPG=%CD%
    @set PATH=%FFMPG%;%PATH%
    
    
    ---your script here---
    
    
    @endlocal
    @pause
    Quote Quote  
  6. Member Ygramul's Avatar
    Join Date
    Jan 2007
    Location
    Poland
    Search Comp PM
    Originally Posted by pandy View Post
    Originally Posted by Ygramul View Post

    Hey, thanks. Although in the meantime I found another script that works.
    Would be nice to put in thread script that works for you.

    There you go:

    Code:
    for %%a in ("*.mp4") do "D:\Clips\ffmpeg.exe" -i "%%a" -ss 00:03:00 -c:v copy -c:a copy "trimmed\%%a"
    exit
    Note: you need to create a subfolder named "trimmed". This script trims the first 3 minutes.
    Quote Quote  
  7. Originally Posted by Ygramul View Post
    There you go:

    Code:
    for %%a in ("*.mp4") do "D:\Clips\ffmpeg.exe" -i "%%a" -ss 00:03:00 -c:v copy -c:a copy "trimmed\%%a"
    exit
    Note: you need to create a subfolder named "trimmed". This script trims the first 3 minutes.
    Hi, thx, something working for you may work for someone else in future.

    And you can add to script automatic folder generation, just add this before your main line:

    Code:
    @REM Where to place output file, No terminating Backslash. "." would be same as .bat file
    @set OUTDIR="trimmed"
    
    @if not exist %cd%\%OUTDIR% (mkdir %OUTDIR%)
    Quote Quote  



Similar Threads

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