LosslessCut: lossless video/audio editing
mifi.no
mifi.no
I think the most common criticism is that the app is large and uses a lot of memory (compared to Notepad?:P) due to it being Electron based. Somewhat unpopular opinion, but here goes: Developing an app using Electron gives such tremendous benefits that it far outweighs any downsides. It lets you easily build a cross-OS app on a super optimised, stable and secure platform that's being battle tested by billions of people around the world every day (Chromium). It gives you all the features of the web, and it "just works" on almost any popular OS. The web has all the big tech pushing new features and improvements all the time and it maintains really good backwards compatibility. I don't think I ever had the LosslessCut app actually crash on me. CI, automatic building and releasing to all different kinds of channels is a breeze due to tools like `electron-builder`.
I think if you compare it to most other lossy video editors, you'll find that the CPU usage is much lower (especially per minute of produced video!), and the memory footprint is probably lower than many other popular video editors. Storage is cheap, and what is 500mb when working with 4K video anyways, so optimising for size is mostly a waste of time and doesn't really benefit 99% of users. Counter arguments are welcome :)
-Mikael Author of LosslessCut
As someone who wrote performant Electron apps, I disagree. Electron has great documentation, but I found little else to praise.
> stable and secure platform
A major factor to me stopping to write Electron apps was the frequent updates needed due to some new flaw upstream. To make matters unbearable, every time there was an update something else had changed with the build tool or the Electron API, which I then had to relearn and painstakingly change everywhere.
I like apps to be done, I don’t want to be forced to babysit in perpetuity an otherwise working app.
> Storage is cheap
It is not. People buy computers and mostly stick to the internal disk which they can’t or don’t know how to change. No one is happy to have to buy and use an external hard drive because their apps—which are orders of magnitude larger than they could be—are eating up all available space.
You’re used to professional apps which do a lot. LosslessCut is a simple, limited app (I say this as a positive) which is perfectly usable by non-pros who don’t deal with that much data.
This type of thinking is pretty common in HN, where they live in a rich country. Then the same people apply their situation to whole world. It's not same in developing world. People still have to manage their savings for storage.
I get this perspective from the developer point of view, but I'm not a video editor. I'm a person who occasionally edits videos. Elsewhere in this thread I mentioned that I use vidcutter, a free and open source tool that does the same basic task. After installation it takes 14 MB on my Linux distribution (it's a 4 MB download).
The thing is, I have dozens or hundreds of tiny little utilities like this installed that make one-off tasks that I do once a month or so much easier. I can't afford for them to be Electron based on my 128 GB SSD. For people who edit videos every day it's obviously not an issue, but I wouldn't be surprised if the majority of people who use tools like this don't use them every day. Maybe not even every week. All this extra space adds up.
I think, in fairness, that a lot of the anti-Electron criticism comes from Linux users like myself. Windows users expect to have everything packaged as one gigantic binary with all the dependencies. (Vidcutter is a 175 MB download on Windows.) This strikes most of us as "poorly engineered", which for some is already enough of a reason not to use something. On Linux, the norm is that distribution maintainers put together a package with the dependencies separate, and these are shared between multiple packages. Electron applications are rarely distributed this way, and that's the biggest part of the problem and the source of a lot of the bloat from a Linux user's perspective.
I'd argue also for most end users' point of view as they will most likely get a more stable app when the average developer doesn't have to write C/C++.
> The thing is, I have dozens or hundreds of tiny little utilities like this installed that make one-off tasks that I do once a month or so much easier. I can't afford for them to be Electron based on my 128 GB SSD.
That's a fair point. I also feel the pain of installing large apps on my MacBook with 256GB SSD. But I think I would still take a large app with all the other benefits than an app that might SEGFAULT all the time, but is small because it's written in C/C++ (like what has been my experience with avidemux for example).
> On Linux, the norm is that distribution maintainers put together a package with the dependencies separate, and these are shared between multiple packages
I get this point, and I used to be an avid Gentoo user myself so I compiled everything from scratch and liked the small size and efficiency of a dynamically linked system. I think the biggest drawback with this approach is that sometimes sharing libraries with "compatible" versions will cause bugs because those versions actually have certain tiny differences that cause bugs to appear, whereas with a static build you lock down the whole dependency tree (except the OS level libs), so you know almost for sure that the app is going to work exactly the same regardless of the system you run it on.
Actually because the bundled JS itself is quite small for LosslessCut (32MB), it would be theoretically possible to bring-your-own electron (even from source), e.g. use a single system-installed electron that can be shared by many different electron apps, as well as use the system installed ffmpeg. Then you could run `electron Resources/app.asar`. It might be possible to setup such a minimal build.
vidcutter is written in Python, built on top of Qt, which is very stable.
In fact one of the reasons people dislike Electron is that it tends to result in a non-native UI appearance, which can make an application harder to learn and use.
honest question from a non-linux user - how much time do you spend in dependency hell? dynamic linking all the things sounds like a recipe for constant nightmare
Most of our machines have no SSD and 8GB RAM on a laptop is a luxury. You can buy brand new Celeron machines like it's 1998. Windows 10 runs like shit and Windows 11 is basically a slideshow. Electron apps are the bane of our existence.
I object to Electron apps when they use a lot of my CPU cycles AND they're for functions that I want to run all the time, like chat programs. Not a problem for a video editor.
can container repacking be avoided? currently hls ts container is being extracted which takes time. seeking "unsupported videos" is much slower than supported
>>Fast: Full quality remux (no audio) is audio really removed? can it be added with other editor?
>>MediaStream API on windows, what about microsoft media foundation, chromium has it in early stages
To answer a point that's been brought up elsewhere in the thread, one nice feature of vidcutter is that you can either cut fully losslessly (on keyframes) or cut frame-perfect while only encoding the frames before and after the first and last keyframes in the cut.
The Arch Linux package for vidcutter is only 4 MB. It has dependencies, of course, but I already have all of them installed for other things. (There's nothing uncommon.) All praise to dynamic linking.
Sadly a massive blocker[0]
Best tool for the job. I'll probably keep using ffmpeg to clip out a single segment, but it gets hairy when you have more complicated edits.
It's implemented in Javascript with Chromium and the HTML5 video player. Not the way I would have thought to do it but makes cross platform a lot easier. You can do the same with ffmpeg on the command line of course but having a GUI to pick the cut points makes all the difference.
The workflow to do a minor edit in a full editor like Final Cut Pro looks roughly like:
- open Final Cut Pro
- create a new proj... oh shoot no, a new library? Yeah that's right.
- click import and track down the videos on my hard drive
- now create a new project and drag the videos into the timeline
- use the blade tool to cut out a segment
- export the video which is... uh... oh yes under the share menu bar and then the format needs to be... hmmm... I think export for YouTube
- wait approximately `videoLength/5` for the video to export
- oh my goodness my hard drive somehow has `videoSize*4` less space
In LosslessCut that workflow looks like:
- open LosslessCut[2]
- drag and drop your videos in
- mark the start and end times of either the segments you want to keep or the ones you want to take out
- hit export and... wow, it's already done? How is that possible?! And it's just in the same format as my source video! Perfect. Oh man and it even saved a little xml file so if I happen to open the same file again I haven't lost my human work of marking the in and out points.
The cuts are usually slightly off from where I'd ideally like them to be, I think because LosslessCut can only cut on i-frames[3], but it's a totally fair tradeoff for my use case.
I liked the minimalist editor interface so much I copied the timeline part of it for a dedicated social media video clipper I'm working on[4].
If you'd like to try it out I strongly suggest installing it from GitHub and donating the amount you would've spent in the macOS app store. The macOS app store version has fewer disk permissions and adds an extra step asking for access to each folder you want to edit in.
1. makers.dev
2. frustratingly, right clicking a video and selecting "open in LosslessCut" doesn't work
3. i-frames in most video codecs are "key frames" that repaint the entire frame. Most frames are p-frames or "predicted frames" which just store a delta from the last frame.
4. thevideoclipper.com
There is an experimental "smart cut" mode where it re-encodes the video between your cut and the next keyframe. It will of course not be entirely lossless though
That is (probably) because the editor uses certain marks in the video (I don't remember how they are called) that "group" the frames together, and you can't use simple editors to re encode the video.
I had this issue some time I tried to cut videos from my gf. Then I moved to ShotCut, that cuts the videos exactly where you want, although the walkthrough is a little longer.
You almost had it! https://en.wikipedia.org/wiki/Group_of_pictures
"“lossless” in Shotcut export does not imply the image goes through the engine untouched. It simply means that the codec is lossless or in lossless mode. The engine does not support every pixel format and color space in existence – only a few. Often sources get converted going through the engine. In your case, the source is RGB, but the engine defaults to yuv422 unless it has an mlt_image_format specified in Export > Other. For your 6SrK4.mp4, you would need mlt_image_format=rgb24 Also, in order to avoid image changes, you must use a Video Mode that matches the source and must not use any effecs (multiple video tracks, transitions, filters). (A mismatching video mode can cause automatic deinterlace, colorspace conversion, scaling, and padding)." –source: https://forum.shotcut.org/t/lossless-annoyances/18344
I found this problem with all ffmpeg-based editors...does anybody know of an editor capable of cutting between inter-frames? The same happens with sound files, which is inconvenient.
This is how it's been done traditionally, since basically forever as far as I can remember. To be honest, I think modern tools could do better. If you happen to want a cut just 20 frames after a keyframe, those 20 frames could be computed (decoded) in order to create a new keyframe right in the spot you wanted. There are a myriad tools to do the typical lossless easy cut, but no idea of one that goes the extra mile to do this more advanced technique.
UPDATE: Navigating the GitHub issues I found out that this is indeed an in-progress experimental feature! That's amazing -- https://github.com/mifi/lossless-cut/issues/126
All the P-frames and B-frames in between two I-frames have to be recomputed. That’s by definition re-encoding and not lossless.
You could re-encode just that small segment though.
It is possible, it will just be a ridiculously large video.
> Mentally, I think of P frames as containing "changes" in the frame. The changes would be the same regardless of whether or not the previous frame was an I or P frame.
P-frames in modern codecs use multiple previously decoded frames, not just the previous frame. And I'm not getting into the complexity of frame ordering (decoded frames and presented frames can be ordered differently).
You can do that, but it’s container format-dependent (e.g. mov edit list) and player support is uneven. If the player doesn’t support it you get extended cut and A/V desync.
Ha true, I guess you could encode every P/B frame after the cut as an I-frame.
These algorithms had methods have existed for 20 years - nearly that long ago, I held in my hand a single DVD with thirty full-length movies on it - all compressed losslessly using such an codec on a laptop. I actually accepted a job with the company (they even sent tickets for the flight out to Seattle for my first day on Monday) before calling me on Friday afternoon to tell me that the company had been acquired by a government-related entity and my role (being public-facing) was not needed. (Pissing me off because I'd turned down another good offer to take theirs!) It's the only time I've ever even heard of getting laid off before you start. The company vanished from the face of the earth that week...
That's an extraordinary claim, I presume you can present the requisite extraordinary evidence?
>single DVD with thirty full-length movies on it - all compressed *losslessly* using such an codec on a laptop
But at what resolution, fps, color space ? Storing the same gray scale image over and over again, as in most old security camera footage, takes up very little space.
Besides that the only way to losslessly re-encode frames is to use lossless encoding, which would easily be a 50-100x size bloat.
You end up with a tiny bit of wasted data, but it's happy middle ground compared to having to give up the key selling point
You can also leave out the B-frames prior to the new start time.
Some containers such as Matroska are able to store an offset (and ffmpeg does that), so it starts playing from exact wanted position even though the actual stream contains data since the last keyframe. Some players ignore that though.
What happens is that every so often it sends a complete image - the intra frame - and then sends differences to show what changes from frame to frame. This is a complete and utter pain in the tits to edit with, so most people transcode to an intraframe codec like DNxHR or ProRes although there's absolutely nothing wrong with MJPEG or MPEG2 intra-only.
If you don't re-encode, you're limited to cutting at an intra frame because that's where it starts drawing from. If you don't you get all this weird "ghost trail" stuff happening.
Costs $18.99 on App Store!
brew install losslesscut
is free :-)Everything I've researched into this says that it cannot be done because there is final metadata that gets added at the end of the stream that is missing. This does not seem right - if you have already download frames of video there should be some way to recreate any metadata instead of being left with an unplayable broken mpg file.
The internet has many shady third party paid products that claim to do this but I don't trust them.
Or mp3splt for MP3 and Ogg Vorbis: https://mp3splt.sourceforge.net/mp3splt_page/home.php
I've found handy for splitting up the occasional concert regording off Youtube back into individual tracks, and things like that…
(unfortunately, the trimmed video won't get the same metadata, so I also needed to use exiftool -TagsFromFile oldvid.mp4 -all:all newvid.mp4 )
This downloads as an 84.9 MB zip file.
I sure hope this does something Virtualdub can't / anything better than Virtualdub, my current preferred lossless video / audio editing Swiss army knife.
Can anyone confirm whether that is the case?
BTW downloads that don't require approaching Lord Appstore cap in hand can be found here:
Lossless-cut: The swiss army knife of lossless video/audio editing - https://news.ycombinator.com/item?id=24883030 - Oct 2020 (10 comments)
LosslessCut – Save space by quickly and losslessly trimming video files - https://news.ycombinator.com/item?id=22026412 - Jan 2020 (1 comment)
Show HN: LosslessCut – Cross-platform GUI tool for fast, lossless video cutting - https://news.ycombinator.com/item?id=12885585 - Nov 2016 (33 comments)
FFmpeg also works of course (it's what LosslessCut uses internally), but in my experience I've occasionally run into files where FFMpeg doesn't properly cut on keyframes and I end up with a few seconds of no image at the start of the video. No such problems with mkvmerge, and the API is much simpler.
We also use keyframe based cutting for lossless cuts and a smart-cut mode that only re-encodes parts around keyframes (at least for h264 and vp8 codecs). I see that you also experiment with a similar smart-cut feature: https://github.com/mifi/lossless-cut/issues/126. That seems to work quite well if you re-encode with the same parameters as the original but I guess there are a lot of edge cases.
What I want is a 64-bit version of Quicktime 7 Pro. Q7P has interface issues (handles are too small, and it is clumsy to get to specific time index), but otherwise it is a Swiss Army Knife of clipping. Apple's 64-bit Quicktime X is absolutely worthless (I don't want to re-encode, and I don't want to share anything!).
ffmpeg -ss 3 -t 2 -i in.mkv -c copy out.mkv
[edited to put -ss and -t before -i]
As output options, ss waits till the first KF after the given value, it's not a seek. With a t of 2, that may very well result in an empty video stream.
From what I can tell, FFMPEG does support actions like that. Perhaps it's not "lossless enough" for the app author.
Some times the scene detection isn't perfect and I have to shave off a few milliseconds to get the clip just right. Also scene detection doesn't do well with fade transitions or with night time skate clips where there's a camera with a flash.
I also learned how to put clips back together with ffmpeg too. I've definitely been doing this the hard way, but it's been fun learning ffmpeg and its crazy incantations.
Here's my site: https://skateboardle.com
For casual video audio editing, I usually use Avidemux. Its Copy mode is similar in cutting out portions of the video without the lengthy re-encoding process. LosslessCut looks nice. I’ll give it a try.
But Avidemux in copy mode should handle it, I’ve been using it for a while in a similar lossless manner to this tool and it’s great.
I mostly use it for cutting up clips from an older GoPro so I don't run in to this often but I did borrow a Hero9 recently and it worked fine, it just was a bit less streamlined.
You answered "Why does this even exist?" yourself, it's a thin wrapper around ffmpeg. It provides a reasonably usable and friendly GUI to perform the kind of basic cuts a lot of people want to do with their video.
When I have two hours of GoPro footage I want to chop up in to a quick and dirty highlight reel, which one do you think I'm going to choose?
1. Fire up my favorite video player, scrub through every file noting the start and end times of every segment, turn each of those segment times in to a ffmpeg command line, and throw all those in a script.
2. Fire up LosslessCut, scrub through every video clicking "start segment" and "end segment" as appropriate, click "Export"
It ships a whole web browser because unfortunately that's the easiest way to make a cross platform GUI app these days, and they get video playback support "for free" (though this does result in some limitations with codecs other than H.264). Yes it's heavier than it could be, but I'm editing video here, I don't really care about megabytes of hard disk space or RAM.
There's nothing else like it as far as I'm aware. AviDemux only does one cut at a time, VirtualDub doesn't even run on non-Windows platforms.
There are plenty of parallel comments on this page that describe why people like LosslessCut. It exists because its authors saw a niche they wanted to fill, and the userbase suggests they aren’t alone. How strange to look at that and call it “absurd”.
Some.video.mkv
Subtitles/Some.video/English.0.srt
and my players of choice (mpv and MPC) are unable to automatically make the match.This setup eliminated 99% of the time I spent on all media management.
Some.video.mkv
Some.video.en.srt
Some.video.en.forced.srt
Some.video.en.cc.srt
https://support.plex.tv/articles/200471133-adding-local-subt...