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

FFmpegFrameRecorder setFormat H265/HEVC #41

Closed
pgfsim opened this issue Oct 18, 2014 · 33 comments
Closed

FFmpegFrameRecorder setFormat H265/HEVC #41

pgfsim opened this issue Oct 18, 2014 · 33 comments

Comments

@pgfsim
Copy link

pgfsim commented Oct 18, 2014

I'd like to change the video codec to H265 (AV_CODEC_ID_H265) instead of (AV_CODEC_ID_MPEG4) for large resolution videos. The following gives me avcodec_find_encoder() error, Video codec not found. How can I add this video codec?

recorder.setVideoCodec(org.bytedeco.javacpp.avcodec.AV_CODEC_ID_H265);
recorder.setFormat("mp4");
recorder.setPixelFormat(org.bytedeco.javacpp.avutil.AV_PIX_FMT_YUV420P);
recorder.setFrameRate(24);
recorder.setVideoQuality(0);

@saudet
Copy link
Member

saudet commented Oct 18, 2014

We would have to compile x265 and link it to FFmpeg. Would you be interested in working on this? It would require modifying the cppbuild.sh script as appropriate.

@pgfsim
Copy link
Author

pgfsim commented Oct 18, 2014

I'm interested in working on this but I'm afraid I have moderate experience in this. I remember when you compiled x264 and ffmpeg :). I'll try and see what I can do

@saudet
Copy link
Member

saudet commented Oct 19, 2014

Great! Let me know if you run into any problems

@pgfsim
Copy link
Author

pgfsim commented Oct 27, 2014

I've put the x265 files in the correct Android NDK arch-arm folders. I'm currently trying to compile ffmpeg to make the .so files. I'm using ffmpeg 2.2.9. It takes around 15 mins to compile but I don't think it's working correctly as it says the folders/commands aren't found :/.

This is my build script

#!/bin/bash

NDK=~/Downloads/android-ndk-r10c
SYSROOT=$NDK/platforms/android-8/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
function build_one
{
./configure
--prefix=$PREFIX
--enable-shared
--disable-static
--disable-doc
--disable-ffmpeg
--disable-ffplay
--disable-ffprobe
--disable-ffserver
--disable-avdevice
--disable-doc
--disable-symver
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-
--target-os=linux
--arch=arm
--enable-cross-compile
--sysroot=$SYSROOT
--extra-cflags="-Os -fpic $ADDI_CFLAGS"
--extra-ldflags="$ADDI_LDFLAGS"
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one

@saudet
Copy link
Member

saudet commented Nov 1, 2014

Try to use the ffmpeg/cppbuild.sh script instead...

@pgfsim
Copy link
Author

pgfsim commented Nov 2, 2014

I've used the cppbuild.sh script and that created the native libraries within the cppbuild/android-arm folder. Now I'm trying to run mvn install --projects ffmpeg but that's saying Failed to execute JavaCPP Builder: could not parse "libavutil/avutil.h": file does not exist. I'm using Maven 2.2.1. The files do exist in various folder within cppbuild/android-arm/

@saudet
Copy link
Member

saudet commented Nov 2, 2014

Does it do the same with the source code from the develop branches?

@pgfsim
Copy link
Author

pgfsim commented Nov 11, 2014

Well develop branch gives the following:

[WARNING] The POM for org.bytedeco:javacpp:jar:0.9.1-SNAPSHOT is missing, no dependency information available
[ERROR] Plugin org.bytedeco:javacpp:0.9.1-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.bytedeco:javacpp:jar:0.9.1-SNAPSHOT: Could not find artifact org.bytedeco:javacpp:pom:0.9.1-SNAPSHOT -> [Help 1]

Changing the version in the pom file to simply '0.9' gives the same could not parse message

@saudet
Copy link
Member

saudet commented Nov 15, 2014

That means you also need to install the develop branch of javacpp:
https://github.com/bytedeco/javacpp/tree/develop

@pgfsim
Copy link
Author

pgfsim commented Nov 16, 2014

Ok, I get the same could not parse error.

@saudet
Copy link
Member

saudet commented Nov 17, 2014

Well, it works here. Can you let me know the exact sequence of git, cppbuild.sh and mvn that you are using, just to make sure that there isn't anything wrong there? Thanks!

@pgfsim
Copy link
Author

pgfsim commented Nov 17, 2014

Alright here's what I'm doing:

cd ~/Downloads
git clone https://github.com/bytedeco/javacpp
cd ~/Downloads/javacpp
git branch -a
git checkout develop
mvn install
cd ~/Downloads
git clone https://github.com/bytedeco/javacpp-presets
cd ~/Downloads/javacpp-presets
git branch -a
git checkout develop
ANDROID_NDK=~/Downloads/android-ndk-r10c/ bash cppbuild.sh -platform android-arm install clean ffmpeg
mvn install -Dplatform.name=android-arm --projects ffmpeg

I actually cppbuilded all projects, not just ffmpeg. Here is where the could not parse error is shown.
Failed to execute goal.bytedeco:javacpp:0.9.1-SNAPSHOT:build (generate source) on project ffmpeg: Failed to execute JavaCPP Builder: Could not parse "libavutil/avutil.h": File does not exist -> [Help 1]

If I try a maven install on opencv I get a similar error:
Failed to execute goal.bytedeco:javacpp:0.9.1-SNAPSHOT:build (generate source) on project opencv: Failed to execute JavaCPP Builder: Could not parse "opencv2/core/types_c.h": File does not exist -> [Help 1]

Thanks

@saudet
Copy link
Member

saudet commented Nov 18, 2014

Running cppbuild.sh with both install and clean isn't going to actually do anything... We should probably have the script output an error there.

And you'll need to specify the directory of the NDK for the mvn command as well. So something like this should work:

export ANDROID_NDK=~/Downloads/android-ndk-r10c/
bash cppbuild.sh -platform android-arm install ffmpeg
mvn install -Pandroid-arm -Dplatform.root=$ANDROID_NDK --projects ffmpeg

@pgfsim
Copy link
Author

pgfsim commented Nov 18, 2014

Thanks, that's fixed but now later on in the build process I'm getting this error but the file does exist.

[ERROR] Failed to execute goal org.bytedeco:javacpp:0.9.1-SNAPSHOT:build (process-classes) on project ffmpeg: Failed to execute JavaCPP Builder: Cannot run program "toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++": error=2, No such file or directory -> [Help 1]

@saudet
Copy link
Member

saudet commented Nov 19, 2014

What's the command you used for mvn? It sounds like the platform.root property isn't set.

@pgfsim
Copy link
Author

pgfsim commented Nov 19, 2014

I managed to get past that by setting -Dplatform.compiler=/path/to/arm-linux-androideabi-g++
Note it had to be the full path, i.e. '/home/pete/Downloads/...' and not '~/Downloads/...'

Next error... :(
/home/pete/Downloads/javacpp-presets/ffmpeg/target/classes/org/bytedeco/javacpp/jniavcodec.cpp:27:17: fatal error: jni.h: No such file or directory compilation terminated.

It seems to be looking at the cppbuild/android-arm/include/ folder for jni.h ? Well there's the java-jdk jni.h or the same file in android-ndk-r10c/platforms/android-8/arch-arm/usr/include. If I copy all the files and folders from the android include folder then it gets caught on #include <exception> and the presumably #include <new>

@saudet
Copy link
Member

saudet commented Nov 20, 2014

As explained above, we need to specify the platform.root property. In your case, something like this should also work:

mvn install -Pandroid-arm -Dplatform.root=/home/pete/Downloads/android-ndk-r10c/ --projects ffmpeg

@saudet
Copy link
Member

saudet commented Feb 21, 2015

FYI, work started for x265 support here: bytedeco/javacpp-presets@778d34b

@pgfsim
Copy link
Author

pgfsim commented Feb 21, 2015

Thanks Sam, I started work on this too but lost track. I'll try and have a look again.

@saudet
Copy link
Member

saudet commented Apr 11, 2015

x265 is now included in version 0.11. Thanks for your effort, it helped a lot!! Let me know if you see anything wrong with the current build.

@saudet saudet closed this as completed Apr 11, 2015
@pgfsim
Copy link
Author

pgfsim commented Apr 11, 2015

Hi Sam,

Just compiled latest version 0.11 and when calling recorder.setVideoCodec(org.bytedeco.javacpp.avcodec.AV_CODEC_ID_HEVC); I get the dreaded org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open video codec.

I'm having a look into it.

@saudet
Copy link
Member

saudet commented Apr 12, 2015

Ok, thanks! Let me know what you find out.

@godzillad
Copy link

Hi Peter, did you find the solution. I am facing the same issue. I am using version 0.11 on Nexus 5 with lollipop.

@saudet
Copy link
Member

saudet commented Jun 23, 2015

Could you guys try on Linux or Mac OS X and let me know if it works or not? It would help, thanks

@godzillad
Copy link

I dont have access to any Macs, I will try on Linux and let you know.

@pgfsim
Copy link
Author

pgfsim commented Jun 23, 2015

I didn't find a solution but the codecs (encoder & decoder) were definitely there. But it still would not load.

I'm away at the moment but didn't try on Linux. Only android.

@godzillad
Copy link

I tried on Linux (ubuntu 14.04 LTS). I converted a h264 video to HEVC using FFmpegFrameGrabber and FFmpegFrameRecorder and it works.

@saudet
Copy link
Member

saudet commented Jun 24, 2015 via email

@ShihabSoft
Copy link

A bit of strangeness is remaining.
As android considered as a flavor of UNIX.

Let me check it out on Mac.
On Jun 24, 2015 5:36 AM, "Samuel Audet" notifications@github.com wrote:

So it works on Linux, but not on Android? Strange...


Reply to this email directly or view it on GitHub
#41 (comment).

@saudet
Copy link
Member

saudet commented Jun 25, 2015

Does the same thing happen with FFmpeg 2.7 and x265 1.7 recently updated in the presets?

@pgfsim
Copy link
Author

pgfsim commented Aug 16, 2015

Latest git downloaded and built.

This does not work
recorder.setVideoCodec(avcodec.AV_CODEC_ID_HEVC);

But this appears to. Very odd.
recorder.setVideoCodecName("H265");

@saudet
Copy link
Member

saudet commented Aug 17, 2015 via email

@gordonpro
Copy link

Is HEVC encoder supported?

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

5 participants