Sunday 28 January 2018

linux - How to cut video files by frame


Does anyone know of a software that could be installed/compiled for linux that is able to cut video by the frame? Thanks.



Answer



ffmpeg can do it. If the video codec is inter-coded and you want precise frame accuracy, you'll have to re-encode the video. If you need to not re-encode the video, then ffmpeg will cut from the nearest GOP boundary before the specified cut point.


Cut and stream-copy:


ffmpeg -i input -ss T -t D -c copy -fflags +genpts output

-ss T specifies the starting point expressed as timecode in the format of S+[.m...] e.g. 24 or 65.22 or [HH:]MM:SS[.m...] e.g. 02:34:11.644


-t D specifies the duration in the same format.


This won't be frame accurate if the start point isn't at a GOP boundary.


Cut and re-encode:


ffmpeg -i input -ss T -t D -fflags +genpts output

Same as above, but this will be frame-accurate.


If you need to specify in and out points by frame numbers:


ffmpeg -i input -vf trim=start_frame=n:end_frame=m -af atrim=start=s:end=t -fflags +genpts output

n and m are the frame numbers of the video in and out points. s and t are the timecodes for the corresponding audio.


The codecs chosen for the re-encoded videos will be according to whichever defaults ffmpeg has set for the output container e.g. H.264 and AAC for MP4.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...