New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearly impossible to understand how to compile ffmpeg #4595

Closed
Yonezpt opened this Issue Mar 18, 2016 · 48 comments

Comments

Projects
None yet
10 participants
@Yonezpt

Yonezpt commented Mar 18, 2016

I have been trying for almost 4 days to compile ffmpeg, find a working version compatible with nwjs, following the tutorial but I am not capable of understanding how, what and where it has to be done.

The available documentation is very confusing; there's mentions of ffmpegsumo even though Chrome stopped using the external DLL making useless any related instructions, in "Build it yourself" I cannot understand where I have to open the indicated partial location, I cannot find it in the current repository and the external possible locations contain code that is different than the one that should be changed (perhaps this is a case of outdated details), the suggested "short directions" make no sense, and then it mentions patching the ffmepg repo which makes me think that I also need to do something in it, again making no sense.

In the end I am completely clueless on how I can get a simple ffmpeg.dll that is capable of playing MP4 format.

I appreciate in advance if anyone tries to share an already compiled ffmpeg.dll with MP4 playback capabilities, but the problem will return when nwjs needs to be updated so ideally the best solution would be to learn how to do it on my own.

Would it be possible to create an updated, clear and easy tutorial containing all the necessary steps to achieve the desired result? Or maybe provide a routine/script/batch which makes this task simpler, a guide, etc.? Anything to improve the current state of this problem that is preventing the continuation of development under NWJS.

@rogerwang

This comment has been minimized.

Member

rogerwang commented Mar 18, 2016

The proper documentation is here: http://docs.nwjs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/

Wiki is for 0.12 and some content may not apply.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 18, 2016

I've also read that linked documentation before and the problem remains the same, I cannot understand what needs to be done, how it has to be done and where it is done. third_party/ffmpeg/ffmpeg.gyp is where, from which place, in which website/repo? Applying the patch; is it done manually, through console/terminal, connected to some place? Regenerating gyp files, I have no understanding here as well, and the rest goes along the same way.

The required knowledge level to understand that documentation is either too high for me or is too incomplete making me incapable of compiling a working mp4 capable ffmpeg by myself.

(side note, I am working with nwj13 rc3 under win7x64)

@rogerwang

This comment has been minimized.

Member

rogerwang commented Mar 18, 2016

To under stand the build process, you should read this first: http://docs.nwjs.io/en/latest/For%20Developers/Building%20NW.js/ though you don't need to build the entire NW.js.

I agree with you that messing with the build system of a large C++ project with millions of code is hard to JS programmers sometimes, we'll see what we can do. In the meantime you could wait for someone else in the community to do this, or pay someone to do it for you.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 18, 2016

I am hoping for something like what you mentioned here: #4492 (comment)

Which I assume it means we won't need to compile the entire NWJS, just the dll. However, I did not find that documentation during my searches, will take a good read at it to see if I am capable of understanding what it requires. But this line right here is already a bit scary:

This usually downloads 20G+ from GitHub and Google’s Git repos. Make sure you have a good network provider and be patient

Seems like it can take some time.

And with parts of ffmpeg now under LGPL, not just GPL

FFmpeg is licensed under the GNU Lesser General Public License (LGPL) version 2.1 or later. However, FFmpeg incorporates several optional parts and optimizations that are covered by the GNU General Public License (GPL) version 2 or later. If those parts get used the GPL applies to all of FFmpeg.

https://www.ffmpeg.org/legal.html

won't these make the restrictions smaller regarding the ability to share, provide one-click compilers for the purpose discussed here or even pack it by default in NWJS? I do not understand these licenses perfectly, but that's the idea I have regarding LGPL, unless the parts being/intended to be used are under GPL in which case nevermind the above.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 18, 2016

I've read the documentation, it is beyond my capabilities both in hardware requirements and time availability. To take upon such a humongeous task to just change one simple line is insane, I cannot do it, but still thanks for the help.

I will wait for a simpler process to be made available, the current one is very discouraging and counter-productive.

@iteufel

This comment has been minimized.

Contributor

iteufel commented Mar 18, 2016

@Yonezpt write me and i will send you the binaries.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 18, 2016

@iteufel I really appreciate the help, but I've followed Roger's suggestion for now and paid someone to do it for me. The next step is to check with a lawyer for license conditions and possible fees, but thankfully that won't be needed any time soon.

It is not an ideal scenario because this makes me dependent of someone else to do this whenever NWJS is updated (unless I am wrong), but for now it will do until a better alternative is made available.

With that said, you can remove your contact to prevent spam bot/crawlers from catching it.

@rogerwang

This comment has been minimized.

Member

rogerwang commented Mar 18, 2016

@ghostoy I believe there is way not to download the whole NW source tree to build ffmpeg. Please check it.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 19, 2016

I'm trying

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 21, 2016

There is no easy way to build ffmpeg without pulling NW source tree. Some dependencies of NW source tree must be kept in order to setup proper building variables for ffmpeg. You can download entire zip package of chromium.src from Github (~800M), which is much smaller than syncing entire NW source tree. Extract the ZIP to a local folder and follow the instructions below to download additional dependencies.

In my test, following folders are the minimal requirement:

  1. base/allocator/: Windows only
  2. build/*
    • build/linux/*-sysroot/*: Linux Only. Use build/linux/sysroot_scripts/install-sysroot.py --running-as-hook to fetch build dependencies for Linux
  3. tools/*
    • <tools>/gyp: see DEPS for commit and repo
  4. third_party/yasm
    • <yasm>/sources/patched-yasm: see DEPS for commit and repo
  5. third_party/ffmpeg: see DEPS for commit and repo
  6. third_party/llvm-build: Mac and Linux only. Use tools/clang/scripts/update.py --if-needed to download.

Patch ffmpeg:

  1. Apply patch in https://raw.githubusercontent.com/nwjs/nw.js/nw13/patch/patches/ffmpeg.patch
  2. Apply patch as in the doc http://docs.nwjs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/

With sources with patches above, you can now generate build targets with gyp:

export GYP_GENERATORS=ninja
export GYP_DEFINES="branding=Chrome"
export PYTHONPATH="$PWD/build"
./tools/gyp/gyp -I build/common.gypi --depth=. ./third_party/ffmpeg/ffmpeg.gyp

Build ffmpeg with ninja:

ninja -C out/Release ffmpeg

You will find build results in out/Release.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 21, 2016

On Windows, GYP_DEFINES should also include clang=0 to disable clang.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 23, 2016

If it would be possible, perhaps the best option would be to provide the fully built proprietary ffmpeg isolated from the main repo and linked in the wiki with the required disclaimers as well as any applicable licenses. This way the source is always available for anyone that wants it, the licenses are being respected, it is by all means independent of the main code since each one is free to use a different build and users do not have to go through an excessive and discouraging task to make such a simple change to one file.

That is, of course, if it is possible.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 23, 2016

As far as I see, there are two major issues: 1) License incompatibility from ffmpeg 2) Patents of codecs

Issue 1) may be solved by releasing with a different license as your suggestion.
Issue 2), codecs, like H264, are covered by several patents. I don't know if we have rights to redistribute NW with these codecs since we don't hold or in the patent pool of MPEG LA.

Technically we will try to simplify the procedures of building ffmpeg and doc it clearly.

@baconbrad

This comment has been minimized.

baconbrad commented Mar 23, 2016

The next step is to check with a lawyer for license conditions and possible fees

From their licensing page:

Note that FFmpeg is not available under any other licensing terms, especially not proprietary/commercial ones, not even in exchange for payment.

@Yonezpt

This comment has been minimized.

Yonezpt commented Mar 28, 2016

@baconface I did read that, but I was referring mostly to H264 use/conditions.

@fuwenchun

This comment has been minimized.

fuwenchun commented Mar 29, 2016

@iteufel Could you send you the ffmpeg.dll .I have been trying to compile ffmpeg, but i failed

@iteufel

This comment has been minimized.

Contributor

iteufel commented Mar 29, 2016

I have created a repo with prebuilt binaries and some guides how i build it.
https://github.com/iteufel/nwjs-ffmpeg-prebuilt

@fuwenchun

This comment has been minimized.

fuwenchun commented Mar 29, 2016

@iteufel I tried many times according to the guides,but i download source code failed,my network is very unstable.There are other way to download source code?or could you send me the binaries?

@iteufel

This comment has been minimized.

Contributor

iteufel commented Mar 29, 2016

You can download prebuilt binaries from https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases

@orgaralf

This comment has been minimized.

orgaralf commented Mar 29, 2016

Thanks @iteufel - very helpful of you 🍻 and 👍 ! For me it is now a question of license fees and distributing the libs with our tool. I have officially requested informations on prices via our US company and German company. I also informed them that we sell very very small amounts of the product... I will update you along the way!

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 29, 2016

I believe you have to pay for US-based and Japan-based (for example), but there are no applicable fees for EU-based companies, because EU doesn't allow these kind of patents. See https://register.epo.org/application?lng=en&number=EP10767601for the MPEG LA request, that has been rejected because of http://www.epo.org/law-practice/legal-texts/html/epc/1973/e/ar52.html and http://www.epo.org/law-practice/legal-texts/html/epc/2013/e/ar53.html

More information in french: http://www.lemonde.fr/europe/article/2005/07/06/le-parlement-europeen-a-enterre-la-directive-sur-le-brevet-des-logiciels_669825_3214.html

All of that, I believe (I'm not a lawyer), means that in EU you can redistribute binaries and libraries without worrying about fees, but the copyright still exists and belongs to the creator/editor.

@orgaralf

This comment has been minimized.

orgaralf commented Mar 29, 2016

I have mailed the MPEG LA and got back:

In that regard, there is no royalty for the manufacture and Sale of the first 100,000 AVC Product units in each Calendar Year. After the first 100,000 units in each Calendar Year, the royalty is $0.20 per unit up to 5M units in the year and $0.10 per unit for units above 5M units in the year.

That refers only to the H264 (MP4 files use that a lot, but note the difference between ENCODER and CONTAINER - you can have other formats in an MP4 container), yet H.264 is pretty much standard. That means you might need to have a second license for music (H264 is video mostly, music maybe)... so, if you really want to have you butt covered:

Finally, MPEG LA does not offer a license for MP3 or any other audio formats, so our only suggestion would be to contact parties such as Fraunhofer Institute (http://www.iis.fhg.de/audio), Thomson Multimedia (http://www.thomson-multimedia.com), Philips licensing (http://www.philips.com), SISVEL (http://www.sisvel.com) and Audio MPEG (http://www.audiompeg.com). We also understand that Dolby (or its licensing company Via Licensing (http://www.vialicensing.org/)) may provide licenses for various audio formats.

So, I will dig deeper and find out, what where and how...

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 30, 2016

@ghostoy I think you're forgetting a few things in your guide above (with zip for chromium.src)

I've got a few errors:

  • pymod_do_main from build/common.gypi doesn't work, I had to manually change what these scripts do (mainly hardcode the arch and write a bunch of True or False depending on whether a folder exists or not). There's probably some way to make it work without having to hardcode, but I don't know python at all.
  • the compilation with ninja doesn't work, I'm missing errno.h, assert.h, stdlib.h. Not sure where I will find those yet, they're present in /usr/include, /usr/include/asm and /usr/include/asm-generic
@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 30, 2016

@vankasteelj Thanks for pointing out. You can set PYTHONPATH=<path-to-chromium>/build environment before running gyp to prevent the error.

I'm using Ubuntu 14.04 64bit and not seeing missing files. I recommend you to install dependencies with build/install-build-deps.sh. And if you are using other distributions, it may not work.

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 30, 2016

I'm on 15.10 and had to fight with that script to make it work, but I don't see why it would bother me on <file.h> inclusion :o
I guess I'll try with a live session of 14.04 then.

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 30, 2016

Oh, and I'm reading in ffmpeg.gyp that they offer ffmpeg_component to build ffmpeg as a shared library. Shouldn't we then also use export GYP_DEFINES="component=true" or something?

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 30, 2016

@vankasteelj I forgot to mention to patch ffmpeg with https://raw.githubusercontent.com/nwjs/nw.js/nw13/patch/patches/ffmpeg.patch. Updated my steps above.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Mar 30, 2016

@vankasteelj I found the issue. Try running python build/linux/sysroot_scripts/install-sysroot.py --running-as-hook before ninja. This script will download those headers.

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 30, 2016

Nice, I can now compile! :) I also found out that you can do: export GYP_DEFINES="branding=Chrome component=shared_library" instead of applying your patch

Note that:
export GYP_DEFINES="branding=ChromeOS component=shared_library" allows for reading AVI files.

My goal is to include hevc, ac3,eac3 as well, but for that, I need to check out some .c and .h files here and there

@iteufel

This comment has been minimized.

Contributor

iteufel commented Mar 30, 2016

@vankasteelj use export GYP_DEFINES="ffmpeg_branding=Chrome ffmpeg_component=shared_library"

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 30, 2016

I went chatting on #chromium IRC, and am now trying to compile nwjs entirely, simply to have the flags proprietary_codecs=1 enable_hevc_demuxing=1 enable_ac3_eac3_audio_demuxing=1 used.

This, plus a modification of ffmpeg to include hevc, might just work.

If you have any idea on how to have hevc support, I'm all ears :)

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 31, 2016

Ok, so. Following the steps (butterproject/butter-desktop#339 (comment)) to build nwjs entirely, there's a good and a bad news:

  • The good news is that it compiles and reads HEVC \o/
  • The bad news is that nw went from 120MB to 3.1GB (also \o/, in a weird way, that must be some kind of achievement)
$ ls -la && ls -la lib/

total 281276
drwxrwxr-x 4 vankasteelj vankasteelj      4096 mar 31 12:29 .
drwxr-xr-x 3 vankasteelj vankasteelj      4096 mar 31 12:24 ..
-rwxrwxrwx 1 vankasteelj vankasteelj  10207936 mar 31 00:43 icudtl.dat
drwxrwxrwx 2 vankasteelj vankasteelj      4096 mar 31 12:43 lib
drwxrwxrwx 2 vankasteelj vankasteelj      4096 mar 31 01:18 locales
-rwxrwxrwx 1 vankasteelj vankasteelj    412344 mar 31 01:05 natives_blob.bin
-rwxrwxrwx 1 vankasteelj vankasteelj   6026776 mar 31 10:34 nw
-rwxrwxrwx 1 vankasteelj vankasteelj    853535 mar 31 01:18 nw_100_percent.pak
-rwxrwxrwx 1 vankasteelj vankasteelj 199338856 mar 31 01:19 nwjc
-rwxrwxrwx 1 vankasteelj vankasteelj  63515512 mar 31 02:16 payload
-rwxrwxrwx 1 vankasteelj vankasteelj   7015543 mar 31 01:20 resources.pak
-rwxrwxrwx 1 vankasteelj vankasteelj    618372 mar 31 01:20 snapshot_blob.bin
total 2700696
drwxrwxrwx 2 vankasteelj vankasteelj       4096 mar 31 12:43 .
drwxrwxr-x 4 vankasteelj vankasteelj       4096 mar 31 12:29 ..
-rwxrwxrwx 1 vankasteelj vankasteelj   22254288 mar 31 01:23 libEGL.so
-rwxrwxrwx 1 vankasteelj vankasteelj   16269816 mar 31 01:02 libffmpeg.so
-rwxrwxrwx 1 vankasteelj vankasteelj   25683056 mar 31 01:23 libGLESv2.so
-rwxrwxrwx 1 vankasteelj vankasteelj   32385272 mar 31 10:34 libnode.so
-rwxrwxrwx 1 vankasteelj vankasteelj 2668888856 mar 31 10:34 libnw.so

From what I tested by replacing files around, modified libffmpeg.so allows to read h264 and avi (it contains all the codecs), and modified libnw.so allows to read hevc (it was built using enable_hevc_demuxing).

Now, how to have a "regular" size... x) I only have to compile libnw and libffmpeg, as replacing those 2 in the official build is working.

@rogerwang

This comment has been minimized.

Member

rogerwang commented Mar 31, 2016

@vankasteelj you need to strip it. Please see our official buildbot for the configuration and build steps: http://buildbot-master.node-webkit.org:8010/waterfall

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 31, 2016

I don't see any configuration :/ There's a bunch of SetProperty but that doesn't indicate me what they do.
I also apprently missed ninja -C out/release dist

@rogerwang

This comment has been minimized.

Member

rogerwang commented Mar 31, 2016

See GYP_DEFINES and other environment variables in the 'gyp' step.

On Thu, Mar 31, 2016 at 7:16 PM Jean van Kasteel notifications@github.com
wrote:

I don't see any configuration :/ There's a bunch of SetProperty but that
doesn't indicate me what they do.
I also apprently missed ninja -C out/release dist


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#4595 (comment)

@vankasteelj

This comment has been minimized.

vankasteelj commented Mar 31, 2016

ok thanks, I have a working hevc build :)

The steps are described at butterproject/butter-desktop#339 (comment), thanks @ghostoy, @rogerwang and @iteufel

It's some sort of mix of the official nwjs doc, chromium docs and what ghost wrote above.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Apr 1, 2016

I'll update document to include the simplified steps for building only ffmpeg library.

@thecyberd3m0n

This comment has been minimized.

thecyberd3m0n commented Nov 27, 2016

could you make available whole build of nwjs with all of those codecs included? Or branch? It's not simple, any mistake will cause improper build and losing about 6 hours of compilation. It's not included, or even not recognized by Chromium - and build codecs without Chromium is not enough.

Please help, instructions on butter-project are also outdated

@ghostoy

This comment has been minimized.

Member

ghostoy commented Nov 28, 2016

@thecyberd3m0n There is a 3rd-party project nwjs-ffmpeg-prebuilt providing ffmpeg libraries for all NW.js releases since 0.13. It may save your time building entire NW.js binaries.

@thecyberd3m0n

This comment has been minimized.

thecyberd3m0n commented Nov 28, 2016

@ghostoy ok it gives me libffmpeg.so binary, just it. I tried to replace default binary with it. Still - ac3 sound not works (I didn't test other codecs but nice 5.1 sound is important to me).

@vankasteelj

This comment has been minimized.

vankasteelj commented Nov 28, 2016

yeah ac3 doesn't work without a custom build. We have compiled nwjs with all the codecs we could (issue atm is most divx/xvid video are black - but they play; some weird codecs stutter; AVC .ts files can't be read; but aac/ac3/vorbis/h264/hevc work fine)

http://builds.butterproject.org/nw/v0.18.6/

@thecyberd3m0n

This comment has been minimized.

thecyberd3m0n commented Nov 28, 2016

@vankasteelj thanks man, I owe you a beer!

@blaremc

This comment has been minimized.

blaremc commented Jan 20, 2017

Does anyone have new version of nwjs with all codecs like here http://builds.butterproject.org/nw/ ? Building custom nwjs is painfull :(
I tried to use this instruction butterproject/butter-desktop#339 (comment) but for nw19 it doesn't work.

@vankasteelj

This comment has been minimized.

vankasteelj commented Jan 20, 2017

We are planning to upgrade to 19 or 20 soon (fullscreen stutter/flash is annoying), so we'll have our guys compile it. You might wanna keep checking every now and then. And yes, the instructions are incomplete, because the compilation actually is a real pain and we had to find "a guy" to do it for us. We're still trying to have a worker do it automatically on each release of nwjs build, but so far I haven't heard back about that, so we're still depending on manual builds.

Official builds with codecs for the non-US user would be a great addition 👍

@ghostoy

This comment has been minimized.

@vankasteelj

This comment has been minimized.

vankasteelj commented Jan 21, 2017

the prebuilt ffmpeg lib is good, but it requires modifications to the core to also enable ac3 does it not?

@ghostoy

This comment has been minimized.

Member

ghostoy commented Jan 23, 2017

@vankasteelj Do you request supporting AC3 codecs in NW.js? If so, please create a new issue with a sample app.

@ghostoy

This comment has been minimized.

Member

ghostoy commented Jan 23, 2017

@vankasteelj I've created a new issue for the request. See #5653.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment