lossless-cut icon indicating copy to clipboard operation
lossless-cut copied to clipboard

Native support for codecs/formats (TS,H265,mpeg2++)

Open mifi opened this issue 6 years ago • 57 comments

Due to losslesscut using chromium's html5 video tag which only supports certain container formats and codecs, we currently need to "convert to supported format" when trying to open exotic formats or codecs. This could be improved with the help of ffmpeg.

Workarounds

Compile custom electron

  • https://github.com/electron/build-tools

Convert to supported format

Currently it's possible to cut those files by first using the File -> Convert to supported format (slow) function, however this is a re-encoding (although fast) of the whole file, just to be able to view it in the HTML5 video player (note that the original and cut versions will not be re-encoded and are still lossless.)

Improve current proxy/dummy code

Currently a <canvas> element is used, and ffmpeg will stream low-resolution jpeg images to that canvas.

Drawbacks:

  • Slow, laggy, low resolution, low fps
  • No audio

This could be improved:

  • MediaSource API & https://www.electronjs.org/docs/latest/tutorial/message-ports
  • Web Audio API: https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
  • https://github.com/strukturag/libde265.js
  • https://stackoverflow.com/questions/55376781/seeking-with-ffmpeg-at-the-end-of-an-rtsp-stream
  • https://stackoverflow.com/questions/61672575/rtsp-to-webrtc-live-video-streaming
  • https://stackoverflow.com/questions/41965793/rtsp-h-264-in-google-chrome-browser
  • https://github.com/Streampunk/beamcoder
  • https://github.com/GleasonK/WebRTC-YouTubeTogether

Related

  • https://github.com/webtorrent/webtorrent-desktop/issues/561
  • https://github.com/webtorrent/webtorrent-desktop/issues/1389

~~Electron (Chromium) might never support h265~~

It seems like Chrome and most other browsers are not going to be supporting H265 as it stands now, and since we are using Chromium (Electron), this will be a problem. It might be possible to enable a flag to enable H265 decoding, but it requires some modding of electron.

  • https://stackoverflow.com/questions/36382568/h-265-hevc-web-browser-support
  • https://github.com/electron/libchromiumcontent/issues/198

Update: Chromium now supports h265 (hardware decoding only)

mifi avatar Sep 09 '18 20:09 mifi

heres the solution from the chrnoium developers https://github.com/henrypp/chromium/blob/master/hevc_support.md https://github.com/henrypp/chromium/blob/master/hevc_support_new.md

killaz47 avatar May 05 '19 07:05 killaz47

Now that more and more cameras (including DJI Mavic 2) are starting to support H265, it would be nice to have support for this here as well. Currently it's possible to cut those files by first using the File -> Convert to friendly format (slow) function, however this is a re-encoding (although fast) of the whole file, just to be able to view it in the HTML5 video player (note that the original and cut versions will not be re-encoded and are still lossless.)

It seems like Chrome and other browsers are not going to be supporting H265 as it stands now, and since we are using Chromium (Electron), this will be a problem. It might be possible to enable a flag to enable H265 decoding, but it requires some modding of electron.

If anyone has some bright ideas, shout out!

heres the solution from the chrnoium developers https://github.com/henrypp/chromium/blob/master/hevc_support.md https://github.com/henrypp/chromium/blob/master/hevc_support_new.md

killaz47 avatar May 05 '19 07:05 killaz47

I'm not sure how to do this with electron. (LosslessCut uses Electron which uses Chromium.) Feel free to open an issue at electron to see if this can be integrated. I think it is not a trivial task, so I don't have time to look at this now.

mifi avatar May 06 '19 15:05 mifi

Lately I swap my gear and see, that recording in HEVC format gives me better quality over H264 even with lower bitrate. I would love to switch to HEVC for all my projects although only Lossless Cut stops me from doing that - https://i.imgur.com/avu5AQE.png (after converting to friendly format).

Is there a chance this will work at some point or should I still sit on old format? Thanks.

TechManiacHD avatar May 30 '19 05:05 TechManiacHD

I'm seeing that too with GoPro 7 HEVC videos and fast convert. The slow one works.

esamattis avatar May 30 '19 07:05 esamattis

You're right! It works with slow one (That quality xD). Enough for cutting no worries :) Thanks, that will do for time being.

TechManiacHD avatar May 31 '19 00:05 TechManiacHD

Great! the reason for the low quality is to make it as fast as remotely possible, and only to be used as a preview.

mifi avatar Aug 12 '19 21:08 mifi

As LossLess-cut is build in electron do you ever considered to use mpv as player component? I've just found that a project to do that it's already there... https://github.com/Kagami/mpv.js/ with also some samples implementation

antonioriva avatar Aug 31 '19 13:08 antonioriva

Thanks for the tip! I didn't know about mpv.js, but if it's easy to integrate then that's definitely an option. https://github.com/Kagami/mpv.js/issues/27

mifi avatar Sep 01 '19 22:09 mifi

In 1.5.0 I have implemented a hack that lets us cut H265 videos, but scrubbing and playing only works at a very low fps and currently without audio.

mifi avatar Nov 04 '19 12:11 mifi

grafik Getting this error when trying to merge 2 H.265 videos together. Is there something I can do about this?

ThexXTURBOXx avatar Dec 04 '19 22:12 ThexXTURBOXx

Is it possible to add support for grabbing a frame at 4k/hevc to jpg even though the preview is not native?

peterhighgrove avatar Mar 26 '20 17:03 peterhighgrove

Is it possible to add support for grabbing a frame at 4k/hevc to jpg even though the preview is not native?

I have implemented this now

mifi avatar Mar 28 '20 14:03 mifi

Nice, thanks! Can't wait to test it in the next release!

peterhighgrove avatar Mar 28 '20 16:03 peterhighgrove

Check out newest version now

mifi avatar Mar 29 '20 11:03 mifi

Thanks, tested 3.17.9. It's working great:)

peterhighgrove avatar Mar 29 '20 15:03 peterhighgrove

@mifi Is there any news on supporting H265 natively?

ThexXTURBOXx avatar Mar 29 '20 15:03 ThexXTURBOXx

No. I think it needs a lot of work because have to compile a custom electron with a custom chromium that uses a custom ffmpeg. Not something i will prioritize unless this work gets funded somehow, or if we can find the work of someone else who did this already.

mifi avatar Mar 30 '20 10:03 mifi

This is still a problem in the current build and I was wondering if progress is being made on it as video standards move forward

desertpogona avatar Dec 11 '20 21:12 desertpogona

AFAIK chromium/electron still doesn't support H265 and they refuse to support it due to expensive licensing: https://bugs.chromium.org/p/chromium/issues/detail?id=684382 So we still need to build a custom electron with a custom chromium to get this native support

mifi avatar Dec 11 '20 21:12 mifi

I came across this guide "it’s not as difficult as it might sound" Electron with custom Chromium build

and then the instructions for HEVC support in chromium

Also noticed this gem from the chromium forums that is currently being implemented Issue 1286132: Implement HEVC for video playback and video conferencing on Windows

gmcmicken avatar Feb 17 '22 07:02 gmcmicken

Any updates on native HEVC implementation? The solution of making a dummy proxy is pretty brilliant, but it would be nice to see my videos in full res.

Linnshet avatar Feb 17 '22 16:02 Linnshet

@gmcmicken nice finds. I've not taken on the task of building a custom chromium. However I do have an idea with the https://developer.mozilla.org/en-US/docs/Web/API/MediaSource to hopefully allow for more smooth streaming from ffmpeg to the player. It may also allow playing audio. Note that it still needs to encode the video while playing but I think h264 encoding can be done very fast these days. Could also set the duration which would remove the need for the html5ified dummy file.

mifi avatar Feb 17 '22 16:02 mifi

There seems to be some good news: Sida Zhu has implemented support for hw decoding for HEVC in chromium v104.0.5084.0, disabled by default and enabled with the PlatformHEVCDecoderSupport feature. (https://github.com/StaZhu/enable-chromium-hevc-hardware-decoding) . chromium 104 needs electron nighty build 21 (https://github.com/electron/releases) . Mikael, could you build losslesscut updated to this electron version and with feature enabled? Thanks a lot!

romadd64 avatar Jul 22 '22 11:07 romadd64

that's fantastic! Then I think once electron 20 becomes stable we can upgrade to that. Note that upgrading losslesscut to newest electron is quite a big job. But I plan on doing it soon, now that electron>v8 slowness on macos has been fixed #714

mifi avatar Jul 22 '22 11:07 mifi

You are right, also latest electron 20 beta has chromium 104, with the 8-weeks release cycle we should hopefully have a stable 20 soon. I understand that going from electon 8 to 20 could be a big jump, I'll donate for your effort. Thanks.

romadd64 avatar Jul 23 '22 10:07 romadd64

Hi Mikael, do you have some progress on this improvement?

romadd64 avatar Sep 25 '22 10:09 romadd64

Hi. Unfortunately not, as ive been very busy with other projects. But, assuming electron now supports natively, it will be solved once Llc upgrades electron, which is one of the first next big tasks

mifi avatar Sep 25 '22 18:09 mifi

Hi. Unfortunately not, as ive been very busy with other projects. But, assuming electron now supports natively, it will be solved once Llc upgrades electron, which is one of the first next big tasks

I will definitely buy the app store version to subsidise a couple of cups of coffee for your effort ;)

dellhem avatar Sep 27 '22 20:09 dellhem

I'm testing with Electron v21 now and with app.commandLine.appendSwitch('enable-features','PlatformHEVCDecoderSupport') h265 seems to be working! so expect an alpha release of losslesscut soon

mifi avatar Nov 22 '22 15:11 mifi