-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Native crash in FFmpegFrameRecorder.recordSamples() when using RTMPS connection #399
Comments
I tried it with those, and the same thing happens. One strange thing I noticed is that while this function normally runs around 24 times before crashing (producing the 2-3 second sound on the server), if I put a breakpoint to the function's beginning and make the program wait at least a few seconds there, it actually crashes the first time it would return from it. So it's like it's something external/asynchronous that's causing this - but I don't know what can it be as I don't call ffmpeg related functions elsewhere... Might be something about the network connection? (it would make sense as it works fine just by changing rtmps to rtmp) I really don't know... |
Does the same thing happen in another OS? |
That's a good question, I didn't test that yet. It's used in an Android app currently. |
It looks like it's working through the normal desktop java console app on windows (x86_64), I managed to stream a 10 second audio without problems. |
I think the Windows binaries were built with GnuTLS instead of OpenSSL though. |
That's interesting, I might try to build a version that uses GnuTLS.. Meanwhile an interesting observation: I made the aforementioned minimalist app work on Android (to exclude all other sources of errors) and this time, there's no error, in runs through, but a 10 second sample takes around 3 minutes to process. I did some logging, and the first ~3 second go normally, then it gets blocked in recordSamples() for around a whole minute (!) (around 56 seconds to be precise) then it continues as if nothing happened when after a further ~3 seconds, the same 1 minute long blocking happens, etc. So apparently it looks like it
It must be something network/protocol related... Like the connection or something gets reset every minute or something - which makes it continue that gets otherwise blocked after a few seconds. |
I see the script in javacpp-presets that builds ffmpeg (cppbuild.sh) is only made to build with OpenSSL and for Windows it uses Zeranoe's builds which has GnuTLS already integrated so that's of little help. Any tip about how to build it with GnuTLS? I'm really noob in this, and I'm unsure about how to get started. What I'm unsure about is if I somehow manage to separately compile GnuTLS for Android (using RTMPDump or similar) - or even better FFMPEG with GnuTLS for Android - can I just put it in this lib (in the place of the corresponding .so file that currently has openssl - I'm not even sure which one is it) and make it work with minimal additional work? Or it's not so simple and I'm better off building "from scratch" and modifying this script to compile gnutls insted of openssl (if I figure out howto do that)? |
Sure, if you get a build with GnuTLS, the rest is easy. The hard part is getting the build working... |
Yeah, thanks, I'll try to do that - though I assume it really won't be easy and I'm not even sure where to start... |
Some very interesting new findings: (I compiled javacpp-presets + javacv with newer ffmpeg (3.0.2) and openssl (1.0.2h) and it was still broken that's why I starting digging into older versions and since I got various compile errors I got tired with I just tried the archived releases - I'm really unsure where the problem might be) |
Nothing special happened at the release of version 1.0. If you figure out how to fix that, please let me know! Thanks |
I checked and between 0.11 and 1.0 at the first glance I see: I'll try to check with the changes reverted in javacv but if it's in the other 2 repos, I'm not sure I can check them because of the compile times. |
Great, thanks for testing that! BTW, it's possible to limit the presets to build only ffmpeg with a command like |
Yeah, I tried that once already, thanks, so I guess building only ffmpeg from the libs should be ok as long as I don't need anything else from javacv. Do I see it correctly that since javacv depends on javacpp-presets and javacpp-presets depends on javacpp: if i change something in javacpp, I would have to recompile the other 2 repos as well, right? |
If something doesn't work, yes trying to rebuild everything is the first thing to try, but it's not always required just to test things out. It's possible to make a Windows build with OpenSSL as well you know. Check inside the cppbuild.sh file for details. Of course I can't expect you to spend a lot of time on this, but do let me know if you figure out a fix! Thanks |
JavaCV 1.3 has just been released and depends on newer versions of FFmpeg and OpenSSL. Could you give it a try and see if it works now? Thanks for your time on this! |
Hello! Thanks for the update. I grabbed version 1.3 and tried quickly but it looks like I still get the same exceptions as before. A handful of these exceptions (when continuously trying to write audio), then at the end a memory violation and crash: 12-09 10:53:57.061 12264-12964/com.google.android.alarm W/System.err: org.bytedeco.javacv.FrameRecorder$Exception: av_write_frame() error -5 while writing audio packet. |
Thanks for testing! The Windows build also uses OpenSSL these days. Does it do the same thing? |
I tried it on Windows but I get this exception when trying to instantiate FFmpegFrameRecorder: Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil (the same thing works when I use libs from an older JavaCV, maybe it was 1.1 when it worked) |
Did you make sure to use the new javacv-platform artifact?
|
I think so, I downloaded it from here: |
Right, so did you add all the JAR files to your class path?
|
@scorpeeon Did you find a solution? |
@pascalbaljet I didn't yet, unfortunately I didn't have time for it to investigate since then... Still using the old version (0.11) I found to be working. |
@scorpeeon Thanks for letting me know! |
The solution is building FFMpeg with the librtmp library and then everything works as expected. Here are some useful instructions: https://github.com/OnlyInAmerica/FFmpeg-Android Succesfully tested with FFMpeg 3.2.4 and rtmpdump 2.4 |
@pascalbaljet Great! Could you send a pull request for that? |
Yes sure! It needs some cleanup and it is only tested on the Android platform. |
@pascalbaljet Can you please send me working Solution on I tried also and FFmpegRecorder sends only some packets and then wait so long and then sends again some packets. With RTMP works fine but i have only problem with RTMPS. Here is my Gradle config compile 'com.android.support:appcompat-v7:22.0.0' Thanks |
Does the same thing happen with FFmpeg 3.3.2?
|
@saudet Can you please tell me how can i upgrade it in Gradle ? |
@saudet |
@webdeutschland I'll submit a pull request next week |
@pascalbaljet @saudet when will you guys submit the pull ? I am really waiting to test it with new FFmpeg. Thanks :-) |
@saudet @webdeutschland I've commit my changes to a fork: pascalbaljet/javacpp-presets@4952499 I did this instead of pull request because I had to revert OpenSSL back to the 1.0.2 LTS branch, the 1.1.0 branch seems incompatible with librtmp. Another flaw in my commit is this hardcoded path: https://github.com/pascalbaljet/javacpp-presets/blob/4952499f9c03d1b6537b0562ca26ab8571b7d57b/ffmpeg/ffmpeg-librtmp.patch#L10 With these changes I've just successfully compiled FFmpeg for android-arm (javacpp and javacpp-presets v1.3.3 on MacOS 10.12.6). I hope someone finds a solution for the OpenSSL incompatibility and could do some more cleanup of the build script. |
@pascalbaljet what if you upload your SO (binary files like libavcodec.so etc) Files and we replace these files in JNI Folder. In this way no one needs to compile again and again. I hope for Android it will work :-) you may upload file in a Google Drive and share link with us. |
It's a common issue, there is a page about it: You'll also find issues opened in this repository and in the ReLinker.loadLibrary(context, "rtmp"); |
@saudet @pascalbaljet can you provide me your .so files |
@pascalbaljet thank you. :-) 👍 It was my mistake. I was not loading all libs at the start. NOw i did it and i can run use RTMPS Feature. |
My compile works only on armeabi-v7a. The problem is other devices does not load rtmp library, although i used ReLinker to load the libraries. My idea is can you provide me your .so files and i will try to run my app with your .so files. |
@pascalbaljet @webdeutschland |
I'm using this lib to decode sound from microphone to aac and stream it through RTMP(S) to a server. For this I'm using FFmpegFrameRecorder.recordSamples() function and it is working fine when I'm connecting through a normal RTMP connection. But when I'm using RTMPS, it also works fine for the initial 2-3 seconds (and I can playback this little part on the server) but after that the native part just crashes with a not very verbose message:
E/audit: type=1701 msg=audit(1461335772.791:1017): auid=4294967295 uid=10325 gid=10325 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=23492 comm="pool-4-thread-1" reason="memory violation" sig=11
When debugging I found that this happens a few seconds after initiating the connection precisely when returning from the recordSamples() function. (initially I thought that the last line was crashing but I modified it and it still crashed when it returned from this function).
Since the crash message is not very verbose and the said function is over a 100 lines with quite a few native calls, I don't really know how to debug this issue. Any ideas?
The text was updated successfully, but these errors were encountered: