webtorrent-desktop icon indicating copy to clipboard operation
webtorrent-desktop copied to clipboard

Support more audio and video codecs

Open MathieuDebit opened this issue 6 years ago • 14 comments

What version of WebTorrent Desktop? (See the 'About WebTorrent' menu) Version 0.20.0 (0.99.3)

What operating system and version? Windows, MacOS and Linux

Support more codecs

I'd like to discuss about ways to support more audio and video codecs in Webtorrent Desktop. Considering the choosen technology (Electron/Javascript), there are different solutions available (FFMPEG.js, WebAssembly, plugins, etc), but I suppose the more relevant comes from Butter Project.

Butter Desktop currently supports native decoding for a lot of audio and video codecs (see supporting codecs). I tried to dive into the code, I'm not sure about it but they seem to use video.js with a set of addons and custom implementations. In the end, Butter Desktop is an app built upon similar web technologies, but supports all the audio and video codecs needed.

What do you think about it? Do you think we could be helped by the current Butter Desktop codebase to support more codecs in Webtorrent Desktop?

Thanks a lot 🙏

MathieuDebit avatar May 11 '18 09:05 MathieuDebit

@MathieuDebit Any ideas how they support the AC3 audio codec? Are they running ffmpeg manually? Or did they bundle the codec into the chromium content module?

feross avatar May 15 '18 11:05 feross

@feross I'm not really sure as the codebase goes beyond my skills, but Butter is still using NW.js, and it seems that there is a way to enable prioritary codecs by compiling sources with FFMPEG:

  • nwBuilder withFFmpeg: true: https://github.com/butterproject/butter-desktop/blob/caed8c45e90f471587225d5e3744bc006e1537e3/gulpfile.js#L115-L125
  • "Nearly impossible to understand how to compile ffmpeg": https://github.com/nwjs/nw.js/issues/4595
  • "enabling for ac3 and hevc codecs support": https://github.com/nwjs/nw.js/issues/5653
  • "Enable Proprietary Codecs" on NW.js: http://docs.nwjs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/

MathieuDebit avatar May 15 '18 11:05 MathieuDebit

@feross as you said here https://github.com/webtorrent/webtorrent-desktop/issues/350#issuecomment-240903825, I guess the best solution would be to build Electron with a custom FFmpeg, did you already explore this approach?

  • Here is an idea of how to implement it: https://github.com/electron/libchromiumcontent/issues/198#issuecomment-211352345
  • It seems that there is no problems with seeking: https://github.com/electron/libchromiumcontent/issues/198#issuecomment-367489559
  • We should also think about legal issues by adding proprietary codecs: https://github.com/electron/electron/issues/9534#issuecomment-303098715

Sources:

  • https://discuss.atom.io/t/information-about-bundled-ffmpeg/28456
  • https://github.com/electron/libchromiumcontent/issues/198
  • http://pietropassarelli.com/ffmpeg-electron.html
  • https://github.com/electron/electron/issues/9534

MathieuDebit avatar May 15 '18 12:05 MathieuDebit

did you already explore this approach?

Yep, we did at one point in time but abandoned it because it complicated the build process too much and the legal situation was unclear. I think things have gotten better on both fronts, so happy to explore this in future versions of WD.

If anyone else has the interest/skill to tackle this before then, go for it!

feross avatar May 15 '18 13:05 feross

So the idea is to replace the ffmpeg library in Electron with our own one.

Thankfully projects like ffbinaries or ffmpeg-static allow us to get the latest binaries for all platforms.

But I don't know how to tell Electron to use these binaries instead... 🚶

Also it could change the build process, will we need a CI or something like electron-builder?

MathieuDebit avatar May 15 '18 14:05 MathieuDebit

Sorry if all of this seems obvious for some of you, but as I'm still learning in that field, I prefer write everything down to be sure the most noob of us will be able to follow 😛

So here is two approaches I've found to support more codecs in Electron with FFmpeg:

  • build libchromiumcontent with a custom libffmpeg: this solution seems to be the best, but is a power-user feature and means that the WD build process will be way more complicated (here, simply use FFmpeg binaries in Node via ffbinaries or ffmpeg-static (example) is not enough, since we don't only want to access FFmpeg methods, but use it in the <video> tag).

  • Convert on-the-fly videos through a local http server like in this app called StreamStudio: this solution doesn't change the build process, and is apparently not that CPU consuming, but will surely complicate the codebase.

I'm digging into the first solution, which is the cleanest, but surely the hardest path 🚣‍♀️

MathieuDebit avatar May 15 '18 20:05 MathieuDebit

@MathieuDebit Thanks for sharing your progress. At one point, I believe the Electron team was producing builds of libchromiumcontent which included a much larger list of ffmpeg codecs enabled. You might want to see if there's something already compiled that you can use.

feross avatar May 16 '18 14:05 feross

Any update here? Without (E-)AC3 support webtorrent is useless. :/

paxter avatar Aug 25 '18 14:08 paxter

Hi @paxter, unfortunately I wasn't able to build Electron with a custom FFmpeg version, because custom builds of Electron and libchromiumcontent are not easy (at least for me 🤷‍♂️) and Electron team does not share their build process...

MathieuDebit avatar Aug 28 '18 15:08 MathieuDebit

Missing codec support can be a bit annoying because using an external player is a little shaky if the file is still downloading.

Right now the error message looks like:

image
  1. As a user, it would be helpful if the error showed the name of the unsupported codec, so I have more information if it's the same type I'm running across often, or more of a long-tail problem.

  2. Would it be helpful to start tracking unsuccessful play attempts across different codecs in telemetry logs, to prioritize formats? Looks like https://webtorrent.io/desktop/telemetry is behind a password, though.

dsernst avatar Apr 22 '20 00:04 dsernst

Shouldn't the player use external codecs installed on the OS? I get this error all the time. Also, shouldn't Webtorrent try to play the video with the default video player from that OS instead of always suggesting to use VLC? Many people don't use VLC and are then faced with installing a new video player.

Would be simpler to have the video directly open in the default video player if a codec error is encountered.

tio-trom avatar Apr 27 '21 13:04 tio-trom

I have the same problem here: image

https://gist.github.com/wellington1993/fbc4af44951da0aeb499a02cac8a9f14

Audio #1 ID : 2 Format : AC-3 Format/Info : Audio Coding 3 Commercial name : Dolby Digital Codec ID : A_AC3

wellington1993 avatar Apr 03 '22 20:04 wellington1993

I fount that project: https://github.com/DanielHuisman/ac3.js/ "JavaScript AC-3 (ATSC A/52) decoder"

The same info found in "Totem" player: AC-3 (ATSC A/52) image

maybe it will help, since we are talking about two projects with the same technology.

wellington1993 avatar Apr 04 '22 23:04 wellington1993

Hello! Do we have any updates on this? Can we check this out https://github.com/Muril-o/electron-chromium-codecs This one bascially patches the ffmpeg bundled with electron and electron as well.

I tried this but faced some issues while building it while also referring to the official build guide.

Kindly share if anyone has updates on this? Also if HEVC has some legal concerns can't we just add AC3 since its patent is expired?

WINOFFRG avatar Sep 04 '22 09:09 WINOFFRG

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

github-actions[bot] avatar Nov 03 '22 12:11 github-actions[bot]

FYI Electron now supports HEVC playback when hardware decoder is available. see discussion https://github.com/mifi/lossless-cut/issues/88

mifi avatar Dec 23 '22 10:12 mifi

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

github-actions[bot] avatar Feb 21 '23 12:02 github-actions[bot]