Live data from Hacker News

Lazycut: A simple terminal video trimmer using FFmpeg

github.com

51–60 of 69 posts

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#51
post #47

I don't find trimming videos with ffmpeg particularly difficult, is just-ss xx -to xx -c copy basically. Sure, you need to get those time stamps using a media player, but you probably already have one so that isn't really an issue. What I've found to be trickier is dividing a video into multiple clips, where one clip can start at the end of another, but not necessarily.

There's nothing easy about it. Here's a taste. # make a 6 second long video that alternates from green to red every second. ffmpeg -f lavfi -i "color=red[a];color=green[b];[a][b]overlay='mod(floor(t)\,2)*w'" -t 6 master.mp4; # creates 150 frames @ 25fps. # try make a 1 second clip starting at 0sec. it should be all green. ffmpeg -ss 0 -i "master.mp4" -t 1 -c copy "clip1.mp4"; # exports 27 frames. you see some red. ff…

I've never tried doing frame perfect clips like that, that does sound annoying. But from a cursory read of the source, I don't think this program will solve that issue either? Because the time stamps in your examples are all correct, and the TUI is using ffmpeg with -ss and -t as well.

  func BuildFFmpegCommand(opts ExportOptions) string {
   output := opts.Output
   if output == "" {
    output = generateOutputName(opts.Input)
   }
   duration := opts.OutPoint - opts.InPoint
  
   args := []string{"ffmpeg", "-y",
    "-ss", fmt.Sprintf("%.3f", opts.InPoint.Seconds()),
    "-i", filepath.Base(opts.Input),
    "-t", fmt.Sprintf("%.3f", duration.Seconds()),
   }
I think the best way of getting frame accurate clips like that is putting the starting time after the input (or rather before the output), which decodes the video up to that time, and reencode it instead of copying. Both of these commands gives the expected output:

  ffmpeg -i master.mp4 -ss 0 -t 1 -c:v libx264 green.mp4
  ffmpeg -i master.mp4 -ss 1 -t 1 -c:v libx264 red.mp4

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#52

I guess I can find another implementation to combine trimmed parts after taking out certain scenes?

Write a text file with all the parts like this: file 'file1.mp4' file 'file2.mp4' file 'file3.mp4' Then call ffmpeg like this: ffmpeg -f concat -i files.txt -c copy output.mp4 And I guess you could make an LLM write a {G,T}UI for this if you really want.

Thanks! I don't want to just stitch them. Hoping to have a smooth transition and an easy blend. No jerking between scenes.

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#53

I've been using ffmpeg with claude as video editor for long time.

You mean you let create claude command or it itself runs ffmpeg on your local machine and returns you finished cut?

I just let claude use ffmpeg to edit videos.

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#54
post #47

I don't find trimming videos with ffmpeg particularly difficult, is just-ss xx -to xx -c copy basically. Sure, you need to get those time stamps using a media player, but you probably already have one so that isn't really an issue. What I've found to be trickier is dividing a video into multiple clips, where one clip can start at the end of another, but not necessarily.

There's nothing easy about it. Here's a taste. # make a 6 second long video that alternates from green to red every second. ffmpeg -f lavfi -i "color=red[a];color=green[b];[a][b]overlay='mod(floor(t)\,2)*w'" -t 6 master.mp4; # creates 150 frames @ 25fps. # try make a 1 second clip starting at 0sec. it should be all green. ffmpeg -ss 0 -i "master.mp4" -t 1 -c copy "clip1.mp4"; # exports 27 frames. you see some red. ff…

Can't make frame perfect cuts without re-encoding, unless your cut points just so happen to be keyframe aligned.

There are incantations that can dump for you metadata about the individual packets a given video stream is made up of, ordered by timecode. That way you can sanity check things.

This is terribly frustrating. The paths of least resistance either lead to improper cuts or wasteful re-encoding. Re-encoding just until the nearest keyframe I'm sure is also possible, but yeah, this does suck, and the tool above doesn't seem to make this any more accessible either according to the sibling comment.

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#56

I don't find trimming videos with ffmpeg particularly difficult, is just-ss xx -to xx -c copy basically. Sure, you need to get those time stamps using a media player, but you probably already have one so that isn't really an issue. What I've found to be trickier is dividing a video into multiple clips, where one clip can start at the end of another, but not necessarily.

I used a plugin in mpv to do it but I can't find it anymore. You just pressed a key to mark the start and end. And with . and , you could do it at keyframe resolution not just seconds.

There's mpv-webm, which is great, but has no way to make a lossless clip AFAIK.

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#57

If you dont like leaving your main video player, IINA on mac is scriptable, so I just use shortcut keys to send start/end indicators to a script which runs ffmpeg on the timestamps. Im sure other video players like VLC support this, but I found VLC's apis very lacking.

mpv has plugins for this like https://github.com/serenae-fansubs/mpv-webm

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#58

It's interesting how terminal apps are increasing in popularity after decades of desktop and web apps. I wonder if it's the talk to the chat AI that's making people more used to asking a prompt screen or if it's the simplicity and lack of bloat.

being true cross-platform is a bigger draw for me. once something works on one platform it will usually work on any other platform that has a terminal.

im in the process of switching to neovim as my main editor just so i can have the same setup everywhere. IDEs like vscode are 'cross platform' but only work on desktop, and there are IDE-like editors for android but none of them work on desktop. oddly enough neovim on android/termux is actually easier to use than any of the IDE editor apps mainly due to everything being keyboard based

when it comes to writing my own mini programs/scripts, is basically the promise of things like flutter where you can write something once and run it everywhere, only it takes hours instead of days to throw something together and its not as overkill because im just using python or bash and then fzf or textual for any interactive parts

Re: Lazycut: A simple terminal video trimmer using FFmpeg

#59
post #47

I don't find trimming videos with ffmpeg particularly difficult, is just-ss xx -to xx -c copy basically. Sure, you need to get those time stamps using a media player, but you probably already have one so that isn't really an issue. What I've found to be trickier is dividing a video into multiple clips, where one clip can start at the end of another, but not necessarily.

There's nothing easy about it. Here's a taste. # make a 6 second long video that alternates from green to red every second. ffmpeg -f lavfi -i "color=red[a];color=green[b];[a][b]overlay='mod(floor(t)\,2)*w'" -t 6 master.mp4; # creates 150 frames @ 25fps. # try make a 1 second clip starting at 0sec. it should be all green. ffmpeg -ss 0 -i "master.mp4" -t 1 -c copy "clip1.mp4"; # exports 27 frames. you see some red. ff…

For frame perfect cuts you need to re-encode. You can use lossless H264 encoding for intermediary cuts before the final one so that you don't unnecessarily degrade quality.

I wonder if there is a solution which would just copy the pieces in between the starting and ending points while only re-encoding the first and last piece as required.

Post reply on HN