I was able to run a bat file on all my mpeg files to cut the first 10 seconds. for %%a in ("*.mp4") do ffmpeg -ss 00:00:10 -i "%%a" -codec copy "newfiles\%%~na.mp4"
Then I found this web page http://superuser.com/questions/657492/cut-last-30-seconds-off-ends-of-videos-using-ffmpeg-in-a-batch-file-in-windows I then created two bat files. trim.bat: @echo off for %%i in (*.mp4) do ( call _trim2.bat "%%i") and _trim2.bat: @echo off for /f "tokens=*" %%a in ('_ffprobe -show_format -i %1 ^| find "duration"') do set _duration=%%a set _duration=%_duration:~9% for /f "delims=. tokens=1*" %%b in ('echo %_duration%') do set /a "_durS=%%b" for /f "delims=. tokens=2*" %%c in ('echo %_duration%') do set "_durMS=%%c" rem following line is seconds to cut set /a "_durS-=30" set "_newduration=%_durS%.%_durMS%" set "_output=%~n1" md _fixed _ffmpeg -ss 0 -i %1 -t %_newduration% -c copy "_fixed\%_output%.mp4" I made a couple of changes is that my FFmpeg and FFprobe does not have a _ in front of them. So in each directory I put all the mp4 files, along with FFmpeg.exe and FFprobe.exe plus The three bat files. I also created the newfiles folder. I ran the first bat file, and it put all the mp4 files with the first 10 seconds cut into newfiles. I then copied FFmpeg.exe and FFprobe.exe plus trim.bat and _trim2.bat into newfiles And made the directory _fixed. I ran the trim.bat and now in the _fixed directory I have The files with both ends cut off. Thanks for all the help. Hope this helps someone else. Tom -----Original Message----- From: ffmpeg-user [mailto:ffmpeg-user-boun...@ffmpeg.org] On Behalf Of t...@tshilton.com Sent: Tuesday, January 19, 2016 6:49 PM To: 'FFmpeg user questions' Subject: Re: [FFmpeg-user] Trying to cut 5 sec of beginning and ending of mp4 files I want to thank all that has submitted suggestions to me. I am guessing all of them are for Linux. I really only know Windows. I have loaded a laptop with Ubuntu. I think it will take me longer to learn that then to manually edit each end of each file using Avidemux. I really don’t even know what bash is. Sorry Guys, for being so stupid about Linux Best Tom -----Original Message----- From: ffmpeg-user [mailto:ffmpeg-user-boun...@ffmpeg.org] On Behalf Of Jim Shupert, Jr. Sent: Tuesday, January 19, 2016 10:38 AM To: FFmpeg user questions Subject: Re: [FFmpeg-user] Trying to cut 5 sec of beginning and ending of mp4 files > Hi > > I am been trying almost every combination of switches to be able to > cut 5 sec from the start and 5 sec from the ending of variable length mp4 > files. > > I have not been successful at doing either. I guess I really don't > understand the usage. I have more than 100 files to do. > > Can anyone suggest a command string that will work? > read https://www.ffmpeg.org/ffmpeg.html about -ss position and -t duration (input/output) When used as an input option (before -i), limit the duration of data read from the input file so what you really want is a sh script to loop 5 sec fro top is easy cause they all start at 0 so approx something like : and you ffmpeg -i < inFile> -ss 05.000 -vcodec $$ -acodec $$ <outfile> you now have outFile with the top 5 sec off and I think you HAVE to reEncode to trim , or is that just for video filters (-vf) ?????? or can one do -codec copy -acodec copy :: reckon I am not sure - try it so what you really want is a sh script to loop and you have to get the total duration in seconds subtract 5 sec from that start at the top and and your new duration is ( totalSec- 5 sec try some of this ## this is NOT a fuctioning sh script but a sketch a copy & paste from some things I *have done It may help you get started ( or be very wrong ) i think you strat 5 sec deep with a ss- 5 and then you want your duration [ -t ] to be 10 sec less that the running time of the org 5 sec from top and then short another 5 - so as not all the way to end .. #!/bin/bash Src=<yourPathhere> etn=mp4 ### for a file 2.mp4 I get seconds ##ffprobe -i 2.mp4 -show_entries format=duration -v quiet -of csv="p=0" ##yields ##865.365000 ## but maybe you want to take just the whole sec ## so use some awk cd $Src for f in *.$etn ; do durT=$(ffprobe -i $Src/$f -show_entries format=duration -v quiet -of csv="p=0") echo $durT ## get the whole sec NNN of NNN.mmm echo $durT | awk -F'.' '{print $1}' durT1=$(echo $durT | awk -F'.' '{print $1}') echo my sec = $durT1 ## yields a number like so 865 #### durT=$(ffprobe -i $Src/$f -show_entries format=duration -v quiet -of csv="p=0") echo $durT ## get the whole sec NNN of NNN.mmm echo $durT | awk -F'.' '{print $1}' durT1=$(echo $durT | awk -F'.' '{print $1}') echo my sec = $durT1 #####-----------/ do a subtract ..tot time in sec - 10 sec durTless10=$(($durT1 - 600)) echo $durTless10 ## i think is then your -t $durTless10 ffmpeg -ss 5 -i <inFile>${f%.*}.mp4 -t $durTless10 videocodec etc etc <outfileFinal>${f%.*}_short.mp4 done _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user