Comments (23)
I got it now , i was using encoder wrongly thats why video is not getting ,my encoder is not encoding to h264 correctly ,I will fix it later but for now i am interested in using your LiveVideoBroadcaster ,so i am working on it.
from librtmp-client-for-android.
OK, it expects NAL units.
from librtmp-client-for-android.
OK, finally solved it. See thread #103
from librtmp-client-for-android.
make sure that video and audio packets are synched correctly and monotically increasing.
If you are sure that is synched correctly, we should go deeper to find out what the problem is.
Sorry for tha late reply
from librtmp-client-for-android.
I forgot about my little project and recently came across it again using this library. I have tried and still failed to get it to work. This time I tried to stream to Twitch using the following function (to test):
private void startStream() {
Log.e("mux", "STARTING");
new Thread(new Runnable() {
@Override
public void run() {
rtmpMuxer = new RTMPMuxer();
int result = rtmpMuxer.open(String.format("rtmp://live.twitch.tv/app/%s?no_archive", STREAM_KEY), 720, 480);
Log.e("mux", "result: " + result);
byte[] data = new byte[1024];
if(rtmpMuxer.isConnected() == 1) {
for (int i = 0; i < 100; i++) {
Log.e("video", "" + rtmpMuxer.writeVideo(data, 0, 1024, i));
Log.e("audio", "" +rtmpMuxer.writeAudio(data, 0, 1024, i));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
Log.e("rip", "" + rtmpMuxer.isConnected());
}
rtmpMuxer.close();
}
}).start();
}
This prints in the log:
03-23 22:16:07.095 5980-5980/com.lfdversluis.androidrtmpteststream E/mux: STARTING
03-23 22:16:12.256 5980-6033/com.lfdversluis.androidrtmpteststream E/mux: result: 134
03-23 22:16:12.257 5980-6033/com.lfdversluis.androidrtmpteststream E/video: -1
03-23 22:16:12.257 5980-6033/com.lfdversluis.androidrtmpteststream E/audio: 0
03-23 22:16:13.257 5980-6033/com.lfdversluis.androidrtmpteststream E/video: -1
03-23 22:16:13.258 5980-6033/com.lfdversluis.androidrtmpteststream E/audio: 0
03-23 22:16:14.258 5980-6033/com.lfdversluis.androidrtmpteststream E/video: -1
03-23 22:16:14.259 5980-6033/com.lfdversluis.androidrtmpteststream E/audio: 0
etc.
Any idea how to debug this? It looks like audio does work as it returns 0?
from librtmp-client-for-android.
Hello, I am getting the same error, even I am doing it correctly before I was using FFmpeg to encode video for YouTube live but that was too slow.I thought of using your library but its giving same error as above -1 .
from librtmp-client-for-android.
You are sending it to youtube and you get this error. Could you please provide some sample code so that I can try to find out what the problem is?
from librtmp-client-for-android.
Hi.
I am experiencing the same same issue as @lfdversluis. The audio data is certainly reaching the server, but the video is not. I send test data just as @lfdversluis .
Any ideas on how to deal with it would be great! I am trying to solve the problem and I will update If I come up with any solution.
Br :)
from librtmp-client-for-android.
return -1 means server does not accept the connection or drop the connection.
How do you use ffmpeg? @karanatwal
@lfdversluis how do you encode data, do you use LiveVideoBroadcaster or something else?
If you do not use, I can offer you the tool - LiveVideoBroadcaster we have developed. Recently, I have fixed a bug in this library. I am just waiting the client to test and approve the fix. If you use this tool, I will become more eligible to help.
You may also want to take a look at this blog post: How to develop live streaming mobile app in 3 steps.
from librtmp-client-for-android.
I use ffmpeg as given in Youtube sample app also i was able to stream by this code on Facebopok ,but it was too slow , then i tried your code for both youtube and facebook , it was giving me -1 exactly same as @lfdversluis. after that i ends up in using this https://github.com/begeekmyfriend/yasea .Now i can stream smoothly on youtube and fb.
from librtmp-client-for-android.
@karanatwal, I see, what did you use to encode data? LiveVideoBroadcaster?
from librtmp-client-for-android.
@mekya I used these steps simply -
#####To publish streams, you can call below functions of RtmpMuxer from Java#####
public native int open(String url, int width, int height); : First, call this function with the url you plan to publish. Width and height are the width and height of the video. These two parameters are not mandatory. They are optional. They put width and height values into the metadata tag.
public native int writeVideo(byte[] data, int offset, int length, int timestamp);: Write h264 nal units with this function
public native int writeAudio(byte[] data, int offset, int length, int timestamp);: Write aac frames with this function
public native int close();: Call this function to close the publishing.
public native int isConnected();: Call this function to query the connection status. Returns 1 if connected, returns 0 if not connected
these were given in readme section of this repo
from librtmp-client-for-android.
I just mean how you encode raw data to h264 nal unit. You must have used something like ffmpeg or hardware encoder with this LibRtmp Client for Android library. I just wondered, it is not a critical point.
from librtmp-client-for-android.
Closing this issue now, please feel free to reopen or comment ;)
from librtmp-client-for-android.
Hi,
Could you please look at this fragment of code?
this is a onActivityResult
method of my activity:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1 && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
InputStream inputStream = getInputStreamFromUri(videoUri, getContentResolver());
rtmpMuxer.open("rtmp://192.168.1.108/live/Gg", 320, 240);
byte[] chunk = new byte[4096];
int counter = 0;
try {
while (inputStream.read(chunk, 0, 4096) > 0) {
counter++;
System.out.println("video succeeded " + rtmpMuxer.writeVideo(chunk, 0, 4096, counter));
}
} catch (IOException e) {
e.printStackTrace();
}
}
So, the server I am broadcasting to works fine, I have tested it, and the file that is represented as inputStream
and then divided into chunk
s is a .h264 file. I got it by using ffmpeg on an .mp4 file.
So my goal here is to read the file from android external storage, and then broadcast it
chunk by chunk.
However the writeVideo
fails to send most of the chunks. This is what console looks like
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded 0
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded 0
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded -1
08-21 21:03:29.080 26684-26684/projekt.filip.raspberry I/System.out: video succeeded 0
Am I missing something here? Do you have any idea how to solve it? Any advice will be higly appriciated.
I tried LiveVideoBroadcaster and it works great, but it doesn't fit what I need because my goal is to send files from android storage.
from librtmp-client-for-android.
No success with NAL units from a DJI drone. Open fine, connect fine (at least for a while), first chunk is sent then it falls back to disconnected
Does the lib expect NAL units or a NAL unit stream?
from librtmp-client-for-android.
Thank you @neilyoung
from librtmp-client-for-android.
@mekya You're welcome. However, until now I couldn't make it work. With neither RTMP server.. :(
See also #103
Maybe you have an idea what to check. Meanwhile I managed to include this project at source level into mine, so I hope I will be able to find the issue by debugging.
from librtmp-client-for-android.
Hi @neilyoung ,
I see.
Have you tried the Ant Media Server? You can use the community version. Because generally we're testing this lib with Ant Media Server.
Secondly, I've experienced some kind of parameters issue in one of the rtmp servers. As far as I remember, in the problem has been resolved by providing "flashver" to the librtmp . Take a look at the connection parameters -> https://linux.die.net/man/3/librtmp
You may need to set these parameters programmatically in the C code.
Please let me know if it helps.
from librtmp-client-for-android.
Hi Ahmet,
Thanks for the follow up. I will try the Ant Media Server (if there is a free Mac version).
Right now I have managed to create a simpler test application, which includes your project from source. I'm not using a real H.264 source for it, but a file, which I took from here https://github.com/usunyu/librtmp-publish-h264-sequence/tree/master/librtmp-publish-h264-sequence/h264 (the first).
This starts with an SPS (0x27), followed by PPS (0x28) and an ID Frame (0x25) plus some packets. The node-media-server
reacts like before: Complaining about "packet parse error".
But what baffles me a bit: I was following the way of the first 0x27 packet, which also has a length of 27 bytes down the way to the native write_video
.
I'm no wondering about the fact, that the code obviously expects to see more than just one NAL unit in the buffer, because it returns with -1 for the first packet
03-30 13:44:04.227 19013 19096 D Test : Send NAL buffer, len 27, type 0x67, first bytes: 00 00 00 01 67 64 00 1f ac 2b -> -1
This seems to be by intention, if I trust this line (and in fact the "No NAL after SPS" appears
If this code requires to always have at least 2 NAL Units in the buffer, then this is a little game changer. Can you confirm that?
from librtmp-client-for-android.
OK, I the flashver
doesn't seem to make a difference. Currently not installed AntMedia yet, but I have annotated the rtmp_sender_write_video_frame
routine a bit after each RTMP_Write
in order to check the results there. The len provided to RTMP_Write
seems always 20 byte larger than the original NAL unit. I think that's ok.
However, the far end considers this as "malformed packet", as well as Wireshark does. Somewhere after the first few packets (mostly after the first) the remote closes the connection and traces complains.
If I don't target AntMedia, I suppose, this lib is not working for me. Too bad :(
from librtmp-client-for-android.
I'm also a bit confused about the install instructions for AntMedia Server: This source https://antmedia.io/what-is-rtmp-server-how-to-set-up-a-free-rtmp-server/#:~:text=comparison%20table%20here.-,How,-to%20set%20up
states:
Community Edition can be downloaded from here.
If I clone the repo there is a missing link. No zip to install :(
PS: Was able to compile it, but don't know how to create a JAR yet
PPS: I will continue in the other thread #103
from librtmp-client-for-android.
Hi @neilyoung ,
The community edition's zip file is available on Releases
https://github.com/ant-media/Ant-Media-Server/releases
FYI
from librtmp-client-for-android.
Related Issues (20)
- Sample Example for RTMP URL HOT 1
- always crash with SIGSEGV after 6~8 hours rtmp steam play in android HOT 2
- Upload RTMP to YT - closing after a couple of buffers (NAL units) HOT 7
- RtmpMuxer推流使用exoplay无法播放,但是电脑直接用ffmepg推流exoplay可以正常播放? HOT 2
- Unable to stream video after updating to the new release 3.2.0 HOT 1
- 请问RTMPMuxer.writeVideo返回-20是什么错误? HOT 1
- Unable to publish to RTMP Server HOT 1
- Issues enabling debug mode
- Can not stream with RtmpStreamer? HOT 2
- SEI message support (Display Orientation)
- how to work with this lib in Azure media service android? HOT 1
- 断网close后,第二次不能推流到服务端
- 推流无法使用VLC播放 HOT 2
- The method of writevideo is not hard to push. When writeaudio is added to push, the video cannot be played HOT 1
- Does this library support audio only publishing? HOT 2
- how to switch rtmp stream HOT 2
- JCenter shutdown - do you plan to move the latest version to another repository? HOT 20
- Send Metadata HOT 1
- RTMP publish/write confusion HOT 1
- Failed to analyze sps from h264 data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from librtmp-client-for-android.