我想制作Android应用程序,可以使用他们的API直接将实时视频流式传输到Facebook和YouTube。我已经完成了直播视频,但都是单独的(一次一个)。但我希望从手机摄像头同时将实时视频流式传输到两者(Facebook-YouTube)。 我使用此库作为RTMP发布者 - https://github.com/pedroSG94/rtmp-rtsp-stream-client-java。 我尝试过使用多个对象,但它没有使用它。
答案 0 :(得分:0)
我是rtmp-rtsp-stream-client-java developer。
如果要将重复流发送到不同的服务器,则只需要重复的srsFlvMuxer或rtspClient依赖于您的流类型。 例如,如果您使用的是rtmpCamera1,则需要修改此类,如下所示:
public class RtmpCamera1 extends Camera1Base {
private SrsFlvMuxer srsFlvMuxer;
private SrsFlvMuxer srsFlvMuxer2;
public RtmpCamera1(SurfaceView surfaceView, ConnectCheckerRtmp connectChecker) {
super(surfaceView);
srsFlvMuxer = new SrsFlvMuxer(connectChecker);
srsFlvMuxer2 = new SrsFlvMuxer(connectChecker);
}
public RtmpCamera1(TextureView textureView, ConnectCheckerRtmp connectChecker) {
super(textureView);
srsFlvMuxer = new SrsFlvMuxer(connectChecker);
srsFlvMuxer2 = new SrsFlvMuxer(connectChecker);
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public RtmpCamera1(OpenGlView openGlView, ConnectCheckerRtmp connectChecker) {
super(openGlView);
srsFlvMuxer = new SrsFlvMuxer(connectChecker);
srsFlvMuxer2 = new SrsFlvMuxer(connectChecker);
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public RtmpCamera1(LightOpenGlView lightOpenGlView, ConnectCheckerRtmp connectChecker) {
super(lightOpenGlView);
srsFlvMuxer = new SrsFlvMuxer(connectChecker);
srsFlvMuxer2 = new SrsFlvMuxer(connectChecker);
}
/**
* H264 profile.
*
* @param profileIop Could be ProfileIop.BASELINE or ProfileIop.CONSTRAINED
*/
public void setProfileIop(byte profileIop) {
srsFlvMuxer.setProfileIop(profileIop);
srsFlvMuxer2.setProfileIop(profileIop);
}
@Override
public void setAuthorization(String user, String password) {
srsFlvMuxer.setAuthorization(user, password);
srsFlvMuxer2.setAuthorization(user, password);
}
@Override
protected void prepareAudioRtp(boolean isStereo, int sampleRate) {
srsFlvMuxer.setIsStereo(isStereo);
srsFlvMuxer.setSampleRate(sampleRate);
srsFlvMuxer2.setIsStereo(isStereo);
srsFlvMuxer2.setSampleRate(sampleRate);
}
@Override
protected void startStreamRtp(String url) {
if (videoEncoder.getRotation() == 90 || videoEncoder.getRotation() == 270) {
srsFlvMuxer.setVideoResolution(videoEncoder.getHeight(), videoEncoder.getWidth());
srsFlvMuxer2.setVideoResolution(videoEncoder.getHeight(), videoEncoder.getWidth());
} else {
srsFlvMuxer.setVideoResolution(videoEncoder.getWidth(), videoEncoder.getHeight());
srsFlvMuxer2.setVideoResolution(videoEncoder.getWidth(), videoEncoder.getHeight());
}
srsFlvMuxer.start(url);
//second url stream. For now hardcoded, modify this method to set in startStream library method.
srsFlvMuxer2.start("rtmp://x.rtmp.youtube.com/xxxxxxxxx");
}
@Override
protected void stopStreamRtp() {
srsFlvMuxer.stop();
srsFlvMuxer2.stop();
}
@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
srsFlvMuxer.sendAudio(aacBuffer.duplicate(), info); //duplicate because you will reuse it on the second srsFlvMuxer.
srsFlvMuxer2.sendAudio(aacBuffer, info);
}
@Override
protected void onSPSandPPSRtp(ByteBuffer sps, ByteBuffer pps) {
srsFlvMuxer.setSpsPPs(sps.duplicate(), pps.duplicate());//duplicate because you will reuse it on the second srsFlvMuxer.
srsFlvMuxer2.setSpsPPs(sps, pps);
}
@Override
protected void getH264DataRtp(ByteBuffer h264Buffer, MediaCodec.BufferInfo info) {
srsFlvMuxer.sendVideo(h264Buffer.duplicate(), info);//duplicate because you will reuse it on the second srsFlvMuxer.
srsFlvMuxer2.sendVideo(h264Buffer, info);
}
}