'How to precisely trim a video
Using code below I tried to trim a video clip:
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(ffmpegPath)
const video_path = `${root}/views/app/files/sources/videos/`;
ffmpeg(video_path + 'Frozen 2013.mp4')
.setStartTime('5:20.994')
.setDuration('0:19.352')
.output(video_path + 'video_out_high.mp4')
.on('end', function(err) {
if(!err) { console.log('conversion Done..') }
})
.on('error', function(err){
console.log('error: ', err)
}).run()
But there is this issues :
the output video seems to be jerky at start, like there are some frames lost at the very beginning. or there is a frame at start and suddenly some frames removed then normal frames playing
Solution 1:[1]
Both of the issues likely stem from just copying the frames. The initial jerkiness comes from the first requested frame is not a keyframe, and an mp4 video may require to end with a keyframe (not 100%). So, you have a choice of (1) reencode or (2) pick start and end times according to the keyframes of the input video.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kesh |
