Link to home
Start Free TrialLog in
Avatar of Wasim Shaikh
Wasim ShaikhFlag for United Arab Emirates

asked on

FFmpeg : cut starting 10 sec and ending 10 sec

Guys,
I am not really good at this and need your help.
I have some video files, I need to cut out starting 10 seconds and ending 10 seconds from all .mp4 files.
video files length varies in every file.
Tried to use some software but cutting out end part is getting tricky as the length is not fixed.
came across FFmpeg and it seems we can batch the process.
of course without encoding and all :-)
If anyone have a working batch file that will be great!.
Avatar of Paul Sauvé
Paul Sauvé
Flag of Canada image

Hi,

Here is a detailed guide for using FFmpeg―A Guide To Video And Audio Conversion Using FFmpeg.
5. Cut Video File into a Smaller Clip
The -ss defines the starting time stamp (here starting time is the 45th second) and -t tells the total time duration for the clip. So, -t 40 means 40 second duration. The command should like this:

You may also find that this solution is helpful―I need to cut MP4 videos. A part at the beginning and a part at the end in a batch fashion
I solved it. I don't mind helping you, but I'm not going to provide the full solution. I will, however, give you hints with the trickiest parts. I'll leave it up to you to fill in the blanks.

ffmpeg will let you do what you want. The -ss switch specifies the start position. -t specifies duration. Unfortunately, there's no switch or program substitution variable that'll internally perform the needed math on the video length to trim-right. You'll have to compute that via scripting.
Avatar of Wasim Shaikh

ASKER

Hi Paul,
I did check those links before posting on EE.
The second link which contains batch file, I am not able to make it work, as I am not able to understand that script.
the changes that I did in script was the time marking, as below.
For /f "Tokens=1* Delims=." %%a In (
    'FFProbe %opts% %1') Do (Set/A "ws=%%a-10.0" & Set "ps=%%b")
rem If %ws% Lss 20 GoTo :EOF
Set/A hh=ws/(60*60), lo=ws%%(60*60), mm=lo/60, ss=lo%%60
If %hh% Lss 10 Set hh=0%hh%
If %mm% Lss 10 Set mm=0%mm%
If %ss% Lss 10 Set ss=0%ss%
C:\ffmpeg-x64\bin\FFMpeg -i %1 -ss 00:00:10.0000 -to %hh%:%mm%:%ss%.%ps:~,3% -c:v copy -c:a copy "Trimmed\%~1"

Open in new window

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Wasim Shaikh
Wasim Shaikh
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
glad to hear everything worked out OK.

I have used FFmpeg in the past with mixed results.
I was hoping if someone has already done this kind of stuff that would be helpful.
It took time for me to understand how the batch file was working.