0

I needed a single ffmpeg command that will trim a video by 8 frames from beginning and 8 frames from the end of the video. Is there a way to do this. I'm on windows 10

If there is a single command to get this done it will really speed up my work, current option is to take it to premiere and trim and then export.

1 Answers1

0

If you know the frame rate (to calculate the frame duration) you should be able to use following code, assuming 8 frames = 0.333s (the 24FPS video)

#!/usr/bin/env powershell

$inputFile="input.mp4"
$outputFile="output.mp4"
$trimSeconds=0.333 # frames / FPS

$videoDuration=ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ${inputFile}
Write-Host videoDuration=${videoDuration}

$endPosition=(($videoDuration -as [double]) - ($trimSeconds -as [double])) -as [string]

ffmpeg -ss ${trimSeconds}s -to ${endPosition} -i "${inputFile}" -c:v copy -c:a copy ${outputFile}

https://shotstack.io/learn/use-ffmpeg-to-trim-video/

How to get video duration in seconds?

pstovik
  • 1
  • 2
  • hi thanks so much for your reply, I calculated the fps 24 fps and ran below command, but i'm getting the below mentioned error --- ffmpeg -i newvideo.mp4 -ss 0.333s -sseof -0.333s -c:v copy -c:a copy output1.mp4 Option sseof (set the start time offset relative to EOF) cannot be applied to output url output1.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to. Error parsing options for output file output1.mp4. Error opening output files: Invalid argument – Abraham Thomas Jan 06 '23 at 05:12
  • updated, need to get duration to calculate "-to" possition – pstovik Jan 09 '23 at 09:09
  • (so seems there is not single ffmpeg command, but combination with `ffprobe` and math calculation in e.g. `powershell`) – pstovik Jan 09 '23 at 09:16
  • Thanks so much for replying, sure i'll try this out, thank you – Abraham Thomas Jan 10 '23 at 10:26