[FFmpeg-user] Trying to cut 5 sec of beginning and ending of mp4 files

tsh at tshilton.com tsh at tshilton.com
Wed Jan 20 02:48:33 CET 2016


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-bounces at 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 at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user



More information about the ffmpeg-user mailing list