Skip to content
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

Build FFmpeg with libfreetype (new FFmpegFrameFilter("drawtext=...")) #254

Closed
Iqra786 opened this issue Oct 18, 2015 · 43 comments
Closed

Build FFmpeg with libfreetype (new FFmpegFrameFilter("drawtext=...")) #254

Iqra786 opened this issue Oct 18, 2015 · 43 comments

Comments

@Iqra786
Copy link

Iqra786 commented Oct 18, 2015

new FFmpegFrameFilter("drawtext=\"text='hello world'\"", imageWidth, imageHeight);

But when i call FFmpegFrameFilter.start(), it fails.

Logcat showsFrameFilter$Exception: avfilter_graph_parse_ptr().

I had discuss with saudet about this problem in issue #164. He said we would need to build FFmpeg with libfreetype.

--enable-libfreetype     enable libfreetype, needed for drawtext filter [no]

Thanks

@saudet saudet changed the title new FFmpegFrameFilter() - drawtext=\"text='hello world'\""; Build FFmpeg with libfreetype (new FFmpegFrameFilter("drawtext=...")) Oct 19, 2015
@yrandriamamory
Copy link

Hi there,

Sorry for my question but have you got any workaround for this stuff?

the problem: drawtext filter could not treated by FFmpegFrameFilter.

How can i rebuild ffmpeg with --enable-libfreetype ?

Thanks in advance

@saudet
Copy link
Member

saudet commented Feb 27, 2016

@pisokelyrya No workaround, but a contribution would be very welcome. :) Add the --enable-libfreetype flag to the cppbuild.sh file and simply follow these instructions to rebuild:
https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments

@yrandriamamory
Copy link

Hi @saudet
Ok thanks for response. Sorry had no time to deal with it till now but i'm gonna take a look at this.
Have another question about javaCV: I have used FFMegrecoder to record frames providing by camera (record a bitmap list to mp4 file. the record succeded and generate the mp4 file. Could even read it on android devide or VLC player but cannot read it in Web browser (chrome/firefox..) Maybe you have a idea about this?

recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
recorder.setFormat("mp4");
recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
recorder.setFrameRate(n);
recorder.setVideoBitrate(800000);
recorder.setSampleRate(44100);

@saudet
Copy link
Member

saudet commented Mar 7, 2016

Try the AV_CODEC_ID_H264 codec instead.

@yrandriamamory
Copy link

it says codec not found!
Thanks for reactive response

@saudet
Copy link
Member

saudet commented Mar 7, 2016

Use a build that contains that codec (x264). It is included in the binaries of version 1.1.

@moster67
Copy link

moster67 commented Apr 19, 2016

As suggested, I am trying to build but I get an error. I have followed the instructions and added --enable-libfreetype in the cppbuild.sh file located in the "/xx/Android/javacv/javacpp-presets/ffmpeg" directory. However, at a certain point I get an error "ERROR: freetype2 not found.

**id-arm/include/vpx/vpx_encoder.h
[INSTALL] /home/osboxes/Android/javacv/javacpp-presets/ffmpeg/cppbuild/android-arm/lib/libvpx.a
[INSTALL] /home/osboxes/Android/javacv/javacpp-presets/ffmpeg/cppbuild/android-arm/lib/pkgconfig/vpx.pc
make[1]: Nothing to be done for 'install'.
patching file configure
patching file library.mak
ERROR: freetype2 not found

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solve the problem.**

I am compiling on Ubuntu 15.10 (64bit) and I am using latest Android NDK (11).

I found this post
[http://stackoverflow.com/questions/36137590/ffmpeg-compile-for-android]
when searching for the error which might suggest that I need to link to freetype2 for ARM since the script may be using freetype2 of my ubuntu-platform.
Any idea what I need to change in the script? I'd like to get this done since as you said, this is a common request.

@saudet
Copy link
Member

saudet commented Apr 19, 2016

You'll need to build libfreetype first

@moster67
Copy link

In the meantime, I tried to compile also for x86 but still get the same error so I am unsure if it really related ARM.
Hmm, I found these instructions
[https://software.intel.com/en-us/articles/building-freetype-libraries-for-x86-devices-using-the-android-ndk]
which permits me to create so-files for x86 (I could probably use the same instructions for ARM). Is this what you mean?
Or do you mean I need to build freetype for my ubuntu (although according to the Ubuntu Software Centre it is already installed)?
Sorry for asking but this stuff is quite new for me although I am willing to learn!

@saudet
Copy link
Member

saudet commented Apr 19, 2016

Check inside the cppbuild.sh script. You're going to see lines for other libraries. Now we need to do something similar for libfreetype, that's all.

@moster67
Copy link

moster67 commented Apr 19, 2016

I am bit lost here...you mean I should add a download link for freetype and then in the platform-section of the script add a make-script part for libfreetype (like in the "ffmpeg-$FFMPEG_VERSION" section)?

@saudet
Copy link
Member

saudet commented Apr 19, 2016

Yes, you got that right

@moster67
Copy link

OK, I'm on it...

@moster67
Copy link

Here it's getting tricky...(I have not arrived to the point of running the script yet): OK for creating a libfree-variable, adding the download-link and probably the extraction of the archive.
As I said, now it's getting more difficult:I need to write the commands for building it. This is new for me - could you just check this link:
[https://how-to-build-for-arm.wikispaces.com/freetype]
Is this the stuff what I am looking for?

If yes, then I will do that as a separate exercise and when I am successful and understood what I am doing, I will try to adapt it and paste it into the script.

@saudet
Copy link
Member

saudet commented Apr 19, 2016

Yes, that's a good start, but we need it for Android as well, so base your commands on the configure and make lines used for other libraries.

@moster67
Copy link

moster67 commented Apr 19, 2016

I am wondering if something like this would work (I am afraid to test - lol)

FREELIB_VERSION=2.6

download http://download.savannah.gnu.org/releases/freetype/freetype-$FREELIB_VERSION.tar.gz freetype-$FREELIB_VERSION.tar.gz 

tar -xzvf ../freetype-$FREELIB_VERSION.tar.gz

cd ../freetype-$FREELIB_VERSION
        LDFLAGS= ./configure --host=arm-linux-androideabi --prefix=/freetype --without-zlib --with-png=no --with-harfbuzz=no
        make -j $MAKEJ
        make install

but I think I am missing some variables...

@moster67
Copy link

Edited previous post..

@moster67
Copy link

moster67 commented Apr 19, 2016

No luck: no more error Freetype2 not found but something that I am too tired to analyze now:

/home/osboxes/Android/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
config.mk:55: recipe for target '/home/osboxes/Android/javacv/javacpp-presets/ffmpeg/cppbuild/android-arm/freetype-2.6/objs/libfreetype.la' failed
make: *** [/home/osboxes/Android/javacv/javacpp-presets/ffmpeg/cppbuild/android-arm/freetype-2.6/objs/libfreetype.la] Error 1
osboxes@osboxes:~/Android/javacv/javacpp-presets$ 

The reason is probably my configure ....

Will try again tomorrow.

@moster67
Copy link

BTW: if someone else would like to join to try to get this done, please let me know and I will paste my test-script on PasteBin....

@moster67
Copy link

Still trying but no luck although I am not sure what I am doing. This is more like "trial and error"....

Tried this:

cd ../freetype-$FREELIB_VERSION
    ./configure --prefix=$INSTALL_PATH --disable-shared --with-pic --host=arm-linux 
make -j $MAKEJ
        make install

but now the original error error Freetype2 not found returned.....

@moster67
Copy link

moster67 commented Apr 19, 2016

Did the last try for now..but still no luck:


cd ../freetype-$FREELIB_VERSION
    LDFLAGS= ./configure --prefix=$INSTALL_PATH --disable-shared --with-pic --host=arm-linux --without-zlib --with-png=no --with-harfbuzz=no    
make -j $MAKEJ
        make install

and once again the original error error Freetype2 not found returned.....

It seems like the first attempt was the best one.

@saudet
I could use some help here....

@saudet
Copy link
Member

saudet commented Apr 20, 2016

Well, it's not finding something like it wants it. Check the config.log file for details

@moster67
Copy link

Found this page: [https://mortoray.com/2012/08/21/android-ndk-cross-compile-setup-libpng-and-freetype/]
It says:

The only catch with freetype is that the header files are put in the “freetype2” subdirectory. I suppose this is a historical oddity when it had to coexist with the previous freetype. This means you’ll need to tell the compiler where to find the freetype headers (you will also have to do this for any Linux project using FreeType2).

Anyway in the config.log of freetype, I found errors about not finding input-files so I guess I am not using the right syntax in the configure-line or I am omitting some global enviroment variables from the script.

I am pretty stuck. I will have a look at it again later on....

@saudet
Copy link
Member

saudet commented Apr 20, 2016

Sure! No problem. Thank for looking into this!

@moster67
Copy link

Anyway, this was the last configure I tried:

cd ../freetype-$FREELIB_VERSION
    # LDFLAGS= ./configure --host=arm-linux-androideabi --prefix=/freetype --without-zlib --with-png=no --with-harfbuzz=no
    LDFLAGS= ./configure --prefix=/freetype --disable-shared --with-pic --host=arm-linux-androideabi --without-zlib --with-png=no --with-harfbuzz=no    
        make -j $MAKEJ
        make install

and this is the configure.log
[http://pastebin.com/VbyL3Mzv]

Maybe you see something obvious, considering your experience....

@moster67
Copy link

moster67 commented Apr 20, 2016

BTW: it struck me that I had never built the project in its original form (i.e. without adding the freelib option) so I tried it and got this end:

mxnet-master/tools/kill-mxnet.py
mxnet-master/tools/launch.py
mxnet-master/tools/make_list.py
mxnet-master/tools/parse_log.py
../cppbuild.sh: line 52: BLAS: unbound variable
osboxes@osboxes:~/Android/javacv/javacpp-presets$ 

I doubt very much it is related to my problems with compiling freetype but still it seems like I cannot compile the same. This error seems to be this line:
make -j $MAKEJ CC="$CC" CXX="$CXX" USE_BLAS="$BLAS"
in cppbuild.sh found in mxnet-master.

Any idea?

PS: by the way, when everything works, in which folder are the so-files generated?

@saudet
Copy link
Member

saudet commented Apr 20, 2016

According to the log file, it looks like it wants bzip2. Is this a requirement for libfreetype? This is the kind of investigation that we need to do!

mxnet isn't supposed to build for Android, at least not right now, so you don't need to worry about that, that's correct.

There's 2 sets of .so files, one generated by the cppbuild.sh scripts, and usually under cppbuild/platform/lib, but that depends, and the other set generated by JavaCPP is in the usual target/classes subdirectory.

@moster67
Copy link

moster67 commented Apr 20, 2016

I am going to have a look at the following script I found and see if I can modify it for Android to start with:
[https://github.com/rtgoodwin/ffmpeg-build-script-plus-frei0r-freetype/blob/master/build-ffmpeg]
The only thing is that it requires pkg-config (a helper tool) but I've seen it used for Android as well so maybe it can work.

Other various sources mention that you need to create a symlink:

When installing ffmpeg on OS X 10.9, ffmpeg configuration fails and the port isn't installed, as the freetype2 header "freetype/freetype.h" isn't found. The fundamental issue may be with the freetype2 installation.
A successful workaround is to add a symlink after freetype2 installation so that ffmpeg's configure script can find it. Then install ffmpeg.
ln -s /opt/local/include/freetype2 /opt/local/include/freetype

will check this when I have some time.

@moster67
Copy link

moster67 commented Apr 20, 2016

just a doubt but when a build fails, can I just modify my cppbuild.sh script in the ffmpeg-folder and then re-run or do I need to do everything from the beginning (importing from git, mvn clean install etc)?

@saudet
Copy link
Member

saudet commented Apr 21, 2016

Some libraries don't need cleaning, while some others do when we change the configuration... Each case is different, in many respects. It takes time to check all these details for each library. I don't have enough time on my own to do everything, so thank you for your help!

@moster67
Copy link

Mine was just a general question since I don't know. I did't ask you to do it for me...

@moster67
Copy link

I am sorry but this is well over my head. To learn this, I have read about configure, make, done numerous attempts etc but I cannot get it right. I can compile freetype using other examples I have seen but I am unable to get it working with the cppbuild.sh script here

Sorry @saudet - I tried to do my best but it was in vain. Maybe someone else can get it working? If there was a wishlist for new features, I wish to add this one.

@saudet
Copy link
Member

saudet commented Apr 23, 2016

Yeah, it takes a while to wrap one's head around all that stuff :( That's why I would love to have this project lift off at some point so that more non-C++ developers can easily access all those native libraries without fuss.

In any case, could you post your latest modifications, in a fork maybe? And the error that you get and such? It might be something obvious, and I could help out right away, who knows.

If it's just about the link, we can use ln -s ... whatever inside cppbuild.sh as well. That's another reason why there is a script: to automate those kinds of hacks :)

@tonymcodes
Copy link

@moster67 @saudet I am able to successfully rebuild ffmpeg for android with libfreetype enabled. What i found is that the pkg-config setting is missing in the build script for ffmpeg when the platform is android-arm . This setting is done in ffmpeg/cppbuild.sh for few other platforms, but not for android-arm. After copying pkg-config settings and following these instructions https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments, I am able to finally generate the required target folder with *jar and *.so files. Now can you kindly guide , how to incorporate these updated files into an existing android app based on javacv , javacpp and javacpp-presets.

@saudet
Copy link
Member

saudet commented Jan 15, 2017

@tonymcodes Awesome! Please send a pull request: https://github.com/bytedeco/javacpp-presets/pulls

@pavel-corsaghin
Copy link

@tonymcodes Hi, I am currently trying to build ffmpeg .so files with libfreetype enabled. I am searched 2 days but no result, can you share with me how to do this. I would appreciate it very much.

@mifritscher
Copy link
Contributor

mifritscher commented Jul 17, 2017

Ok, so the main problem seems to be the build under android? I hope I can get the time to take the way @tonymcodes took. I already did this under cygwin (with "raw" ffmpeg and the provided freetype libs), so it should be doable.
Mac OS x seems to be working as well @moster67 ?
So, if the android issue is solved the freetype enabled build can be enabled globally?

@saudet
Copy link
Member

saudet commented Jul 17, 2017

Just send a pull request and it will get built by Travis CI. No need to build anything by yourself!

@saudet
Copy link
Member

saudet commented Jul 17, 2017

If it's not possible to get it working with Android, let's start with the other platforms, that's fine.

@mifritscher
Copy link
Contributor

mifritscher commented Aug 25, 2017

See bytedeco/javacpp-presets#452 (or https://github.com/mifritscher/javacpp-presets/tree/freetype, which is the branch for this) for my first shot. Feel free to improve it :-)

@mifritscher
Copy link
Contributor

mifritscher commented Aug 26, 2017

Builds on all plattforms on travis and on my crude Windows build environment. Feel free to test :-)
@pavel-corsaghin: Just take my branch and compile it "the normal way". If you want I can give you the binaries as well.
@tonymcodes: Can you please compare my solution with yours?

@saudet
Copy link
Member

saudet commented Aug 28, 2017

Thanks a lot to @mifritscher we now have SNAPSHOT builds with FreeType, so please let me know if you have any problems with them. Thanks!

@saudet
Copy link
Member

saudet commented Jan 18, 2018

JavaCV 1.4 now comes with a version of FFmpeg built with libfreetype.
Thanks again to @mifritscher for the contribution!

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

No branches or pull requests

7 participants