brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -sseof -30 cuts the last 30 seconds of a file

Ffmpeg
~/tips/tip-ffmpeg-sseof-last-seconds

ffmpeg -sseof -30 -i recording.mkv -c copy last30.mkv

Starts the cut a fixed time before the end of the file, whatever its length.

Sometimes the part I want is at the end of a recording, and I do not know how long the file is. -sseof solves that: it works like -ss, but counts from the end of the file instead of from the start.

The ffmpeg manual says -sseof is like -ss but relative to the end of file, where negative values are earlier in the file and 0 is the end itself. Like -ss it is an input option, so it goes before -i.

ffmpeg -sseof -30 -i recording.mkv -c copy last30.mkv

That keeps everything from 30 seconds before the end up to the end. No duration to look up, no arithmetic, and the same command works for every file whatever its length. The value uses the same time duration syntax as -ss, and I stick to plain seconds.

A second use is chopping off a tail you do not want, together with -t or -to. For a normal trim from the start I still reach for -ss, but when the question is “give me the end of this file”, -sseof is the shorter answer.

The caveat is the same as for -ss. With stream copy (-c copy) the manual says the segment between the seek point and the requested position is kept, so the clip can begin a bit earlier than 30 seconds before the end. If the exact start matters, leave out -c copy and let ffmpeg re-encode. That is slower and the file changes, but the cut lands where you asked.

Also check the result by playing the first seconds of last30.mkv before you delete the original recording. Cutting is quick to redo, a deleted source is not.

Further reading: ffmpeg documentation: main options (-sseof)

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link