Closed Shanmugamsundarrajan closed 7 years ago
First of all try with my app with example surface mode or textureview mode. If it work the most possible reason is that you need wait your view inflate. That is the reason I do start onclick a button. Other possibility if you want start all in onCreate method you can use the callback of textureview or surfaceview to know when the view is ready.
Surfaceview callback (you can get the SurfaceHolder with surfaceview.getHolder()): https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html
Remember too that any Android devices has bugs with Camera2 on API 21 and 22 normally so I recomend you use camera1. Finally if you tried with my advices, post you activity code example that crash and then I can help you more.
In the example also I was getting the onConfigureFailed.
Actually I want to use camera2, because the image capture is working better in camera2 and the quality of image and video are better in camera2 than the camera1.
Please let me know how to implement the Surfaceview callback (in which class, either in the Camera2APImanager or in the MainActivity.
Our main requirement is to stream the video through the Service (not with the Activity). is it doable . If yes, please let me know how to achieve, it will of great help
I am also trying the same in BuilderSurfaceModeBase with out the Surfaceview , there I am getting an error RtspClient onConnectionFailedRtsp.
09-12 11:17:59.886 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: connectToWifi is called 09-12 11:17:59.972 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifi is enabled 09-12 11:17:59.975 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: WifiInfo is SSID: spider, BSSID: 70:8b:cd:ac:d1:70, MAC: 34:87:3d:2d:ed:fd, Supplicant state: COMPLETED, RSSI: -51, Link speed: 72Mbps, Frequency: 2462MHz, Net ID: 0, Metered hint: false, score: 60 09-12 11:17:59.975 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: connection is wireless 09-12 11:17:59.975 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifiId is 52 09-12 11:17:59.976 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifi's ipAddressStr 192.168.5.204 09-12 11:17:59.979 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: Connected to WiFi 09-12 11:18:00.020 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient constructor called 09-12 11:18:00.157 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: videoEncoder OMX.qcom.video.encoder.avc type supported: video/avc 09-12 11:18:00.158 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2141391876 09-12 11:18:00.160 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2130708361 09-12 11:18:00.160 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2135033992 09-12 11:18:00.160 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 21 09-12 11:18:00.310 23014-23014/com.sixthenergy.video_rtsp_rtmp D/sixth.VideoEncoder: inputSurface is set : Surface(name=null)/@0x262d3cd2 09-12 11:18:00.389 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: build version is greater than 21 09-12 11:18:00.424 23014-23014/com.sixthenergy.video_rtsp_rtmp E/sixth.Camera2ApiManager: openCameraBack 0 09-12 11:18:01.085 23014-23138/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera startPreview surfaceview is : null , surface : Surface(name=null)/@0x262d3cd2 09-12 11:18:01.094 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: url : 09-12 11:18:01.097 23014-23014/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient onConnectionFailedRtsp called 09-12 11:18:01.175 23014-23138/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera opened 09-12 11:37:21.452 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: connectToWifi is called 09-12 11:37:21.545 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifi is enabled 09-12 11:37:21.547 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: WifiInfo is SSID: spider, BSSID: 70:8b:cd:ac:d1:70, MAC: 34:87:3d:2d:ed:fd, Supplicant state: COMPLETED, RSSI: -51, Link speed: 72Mbps, Frequency: 2462MHz, Net ID: 0, Metered hint: false, score: 60 09-12 11:37:21.548 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: connection is wireless 09-12 11:37:21.548 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifiId is 53 09-12 11:37:21.549 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: wifi's ipAddressStr 192.168.5.204 09-12 11:37:21.552 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.Main: Connected to WiFi 09-12 11:37:21.592 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient constructor called 09-12 11:37:21.715 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: videoEncoder OMX.qcom.video.encoder.avc type supported: video/avc 09-12 11:37:21.717 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2141391876 09-12 11:37:21.719 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2130708361 09-12 11:37:21.719 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2135033992 09-12 11:37:21.719 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 21 09-12 11:37:21.879 26919-26919/com.sixthenergy.video_rtsp_rtmp D/sixth.VideoEncoder: inputSurface is set : Surface(name=null)/@0x262d3cd2 09-12 11:37:21.959 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: build version is greater than 21 09-12 11:37:21.991 26919-26919/com.sixthenergy.video_rtsp_rtmp E/sixth.Camera2ApiManager: openCameraBack 0 09-12 11:37:22.633 26919-26984/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera startPreview surfaceview is : null , surface : Surface(name=null)/@0x262d3cd2 09-12 11:37:22.638 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: url : 09-12 11:37:22.639 26919-26919/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient onConnectionFailedRtsp called 09-12 11:37:22.719 26919-26984/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera opened
If you want stream in background mode you can use constructor that require context, protocol and ConnectCheckerRtsp. No view requirement to do it, no preview too. Use this constructor: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/rtsp/RtspCamera2.java#L45 To implement surfaceview callback you can use code example:
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
//you can start stream here, your surfaceview is now inflated
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
});
Ok Thanks for your quick response, I will get back to you
As suggested by you, now I am trying with RtspBuilderSurfaceMode new RtspBuilderSurfaceMode(context, Protocol.TCP, this);
I am getting camera configured. Need to work on the streaming to our RTSP server set up.
Once this is done, I will work on the feedback you have given to use surfaceChanged ....
Thanks for your great support.
Fine.
Remember RTSP is tested on wowza server I can't promise you it will work with other media server. If you experiment some problems let me know server that you use, error and If you can a tutorial to install the server to test for debug the error.
Also use ffmpeg to confirm your server is working, streaming with a mp4 file. Command:
ffmpeg -i pathtomp4file -f rtsp rtsp:/ip:port/appname/streamname
I am able to stream successfully,
I am able to stream (176 , 144 , 30) boolean result = videoEncoder.prepareVideoEncoder(176, 144, 30, 1200 * 1024, 90, false, FormatVideoEncoder.SURFACE); Its not working with (640 , 480 30)
Can u please help me on how to make it work with higher resolution (the camera actually supports upto HD
It started working after changing the rotation from 90 to 180. Now the streaming is working at higher resolution
Hi pedro,
Can we do the streaming as well as recording at the same time. Also the same recording should be stored in the SD card. If so, can u please suggest on how can we achieve this.
Our requirement is to stream and record the same for a fixed time (say 30 secs)
You have a method called startRecord. It should be called after start a stream
ok thanks
I have given the path as String videoRecPath = System.getenv("SECONDARY_STORAGE") + "/" + getUTCTime() + ".mp4";
is it OK? because the recording is not found in the SD card
You can get sdcard path with the method posted in here: https://stackoverflow.com/questions/36766016/how-to-get-sd-card-path-in-android6-0-programmatically
Anyway I think you can't write in a sdcard. When you catch the error you can see the reason doing a log of the error. If you get permission denied, you can't write in sdcard, if you see file not found your path is bad.
I have corrected the permission issue. Using the sample App I am able to write to file in the SD card. After that i loaded the streaming app, Still the recording was not happening, the code was breaking immediately after the start record was called. I have introduced Thread.sleep(2000) after the start of the streaming. It is working, but need to check the consistency of the working. Will the code handle both streaming and recording at the same time ??
You can use the callback that tell you stream start (onConnectionSuccess)
I have implemented the call back and it is working fine. After 60 sec I am stopping the record. once the recording is stopped the mobile is rebooting. Please help me on why it is rebooting ?
I am running this in the service, after every 60 secs the mobile is rebooting.
Working fine for me. Did you try with other device? https://stackoverflow.com/questions/10783128/foreground-service-causes-phone-reboot-why
I tried this two to three devices, it is rebooting Will the code running in the service, on stopping the recording will restart the module. I am just guessing.
May be the same will be working fine in the GUI based.
Can you send me a sample code, on how to implement the streaming and recording at the same time in the service
package com.pedro.rtmpstreamer;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.Log;
import com.pedro.rtplibrary.rtmp.RtmpCamera2;
import net.ossrs.rtmp.ConnectCheckerRtmp;
/**
* Created by pedro on 18/09/17.
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class ServiceTest extends Service implements ConnectCheckerRtmp{
private RtmpCamera2 rtmpCamera2;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//TODO do something useful
rtmpCamera2 = new RtmpCamera2(getApplicationContext(), this);
if (rtmpCamera2.prepareVideo() && rtmpCamera2.prepareAudio()) {
rtmpCamera2.startStream("rtmp://192.168.2.134/app/pedro");
} else {
Log.e("Pedro", "error?");
}
return Service.START_NOT_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
rtmpCamera2.stopStream();
}
@Override
public void onConnectionSuccessRtmp() {
}
@Override
public void onConnectionFailedRtmp() {
}
@Override
public void onDisconnectRtmp() {
}
@Override
public void onAuthErrorRtmp() {
}
@Override
public void onAuthSuccessRtmp() {
}
}
Working for me, I tested with a stream of 5min with devices Nexus 5x and Samsung S7. An App can't do your device reboot. If your device reboot then you have a bug in the firmware that could cause kernel panic rebooting the device.
Ok thanks,
I have the recording done in the sdcard with .mp4 extension. for 60 sec recording the file size is coming as 9 MB. But I could not play the same in the VLC player. What may be the problem.
The problem, the VLC player is playing the recording for 60 sec with blank/black screen. Nothing is visible in the recording.
What may be the problem?
Thanks for your continuous support.
Did you use stopRecord method? Remember you can't reproduce video before close it.
Yes I have used the stopRecord Method.
Logcat capture:
09-18 20:00:53.911 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:01:53.929 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:02:53.905 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:03:53.903 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:04:53.906 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:05:53.904 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:06:53.904 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:07:53.903 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:08:54.100 5071-5071/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:09:30.838 13851-13851/com.sixthenergy.video_rtsp_rtmp I/sixth.Main: Main activity started 09-18 20:09:30.843 13851-13851/com.sixthenergy.video_rtsp_rtmp I/sixth.Main: video services created 09-18 20:09:31.350 13851-13851/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: camera service called 09-18 20:09:31.350 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: connectToWifi is called 09-18 20:09:31.461 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: wifi is enabled 09-18 20:09:31.464 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: WifiInfo is SSID: spider, BSSID: 70:8b:cd:ac:d1:70, MAC: 34:87:3d:2d:ed:e6, Supplicant state: COMPLETED, RSSI: -57, Link speed: 72Mbps, Frequency: 2462MHz, Net ID: 0, Metered hint: false, score: 60 09-18 20:09:31.464 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: connection is wireless 09-18 20:09:31.464 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: wifiId is 8 09-18 20:09:31.467 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: wifi's ipAddressStr 192.168.5.180 09-18 20:09:31.475 13851-13851/com.sixthenergy.video_rtsp_rtmp D/sixth.Video2Service: Connected to WiFi 09-18 20:09:31.564 13851-13851/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient constructor called 09-18 20:09:32.000 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: videoEncoder OMX.qcom.video.encoder.avc type supported: video/avc 09-18 20:09:32.002 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2141391876 09-18 20:09:32.004 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2130708361 09-18 20:09:32.004 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 2135033992 09-18 20:09:32.004 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: Color supported: 21 09-18 20:09:32.261 13851-14008/com.sixthenergy.video_rtsp_rtmp D/sixth.VideoEncoder: inputSurface is set : Surface(name=null)/@0x3dd26ec1 09-18 20:09:34.400 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.VideoEncoder: build version is greater than 21 09-18 20:09:35.314 13851-14008/com.sixthenergy.video_rtsp_rtmp E/sixth.Camera2ApiManager: openCameraBack 0 09-18 20:09:36.955 13851-14154/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera startPreview surfaceview is : null , surface : Surface(name=null)/@0x3dd26ec1 09-18 20:09:36.967 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: url : rtsp://223.30.185.189:5554/sc20 09-18 20:09:36.968 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: url : rtsp://223.30.185.189:5554/sc20 09-18 20:09:36.968 13851-14008/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RtspClient host : 223.30.185.189 , port : 5554 , path : /sc20 09-18 20:09:37.135 13851-14154/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera opened 09-18 20:09:37.140 13851-14154/com.sixthenergy.video_rtsp_rtmp I/sixth.Camera2ApiManager: camera configured 09-18 20:09:37.612 13851-14109/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP Connect called 09-18 20:09:37.656 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP Connect socketAddress set 09-18 20:09:37.677 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP Connect connection success 09-18 20:09:37.679 13851-14255/com.sixthenergy.video_rtsp_rtmp E/sixth.RtspClient: Send announce called 09-18 20:09:37.679 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: options : OPTIONS rtsp://223.30.185.189:5554/sc20 RTSP/1.0 CSeq: 1 User-Agent: Android_SC_20 Session: null 09-18 20:09:38.186 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: getResponse sessionId : 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:38.186 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP/1.0 200 OK CSeq: 1 Date: Mon, 18 Sep 2017, 14:39:38 GMT Public: SETUP, TEARDOWN, PLAY, PAUSE, DESCRIBE, GET_PARAMETER, ANNOUNCE, RECORD Session: 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:38.190 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: announce request : ANNOUNCE rtsp://223.30.185.189:5554/sc20 RTSP/1.0 CSeq: 2 User-Agent: Android_SC_20 Session: 768b8b0097721e804f2aeaad1a45b372_sc20 Content-Length: 476 Content-Type: application/sdp
v=0
o=- 0 0 IN IP4 192.168.5.180
s=No Name
i=N/A
c=IN IP4 223.30.185.189
thread=0 0
a=recvonly
m=audio 0 RTP/AVP 97
a=rtpmap:97 mpeg4-generic/16000
a=fmtp:97 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1410; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
a=control:trackID=0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=42c029;sprop-parameter-sets=Z0KAH+kAoAt0A2hQmoA=,aM4G4g==;
a=control:trackID=1
09-18 20:09:39.071 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: getResponse sessionId : 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.071 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP/1.0 200 OK CSeq: 2 Date: Mon, 18 Sep 2017, 14:39:38 GMT Session: 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.071 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: setup : SETUP rtsp://223.30.185.189:5554/sc20/trackID=1 RTSP/1.0 Transport: RTP/AVP/TCP;interleaved=2-3 CSeq: 3 User-Agent: Android_SC_20 Session: 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.470 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: getResponse sessionId : 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.470 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP/1.0 200 OK CSeq: 3 Cache-Control: no-cache Date: Mon, 18 Sep 2017, 14:39:39 GMT Expires: Mon, 18 Sep 2017, 14:39:39 GMT Session: 768b8b0097721e804f2aeaad1a45b372_sc20 Transport: RTP/AVP/TCP;interleaved=2-3 09-18 20:09:39.470 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: record : RECORD rtsp://223.30.185.189:5554/sc20 RTSP/1.0 Range: npt=0.000- CSeq: 4 User-Agent: Android_SC_20 Session: 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.994 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: getResponse sessionId : 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.994 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.RtspClient: RTSP/1.0 200 OK CSeq: 4 Date: Mon, 18 Sep 2017, 14:39:39 GMT Session: 768b8b0097721e804f2aeaad1a45b372_sc20 09-18 20:09:39.995 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Connection success 09-18 20:09:39.995 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Start Stream success 09-18 20:09:39.995 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: video 2 service started and recording at : /storage/sdcard1/rtmp-rtsp-stream-client-java/1505745579.mp4 09-18 20:09:39.995 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.BuildSMB: startRecord : path /storage/sdcard1/rtmp-rtsp-stream-client-java/1505745579.mp4 09-18 20:09:40.275 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.BuildSMB: startRecord : started 09-18 20:09:40.275 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Recording started 09-18 20:09:40.275 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 1
[ 09-18 20:09:40.281 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:09:40.281 307:14230 E/ ]
hi843_8909_register_gain4444=74
[ 09-18 20:09:40.281 307:14230 E/ ]
hi843_8909_gain1111=74
[ 09-18 20:09:40.281 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:09:41.275 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 2 09-18 20:09:42.276 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 3 09-18 20:09:43.276 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 4 09-18 20:09:44.276 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 5 09-18 20:09:45.277 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 6 09-18 20:09:46.281 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 7 09-18 20:09:47.281 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 8 09-18 20:09:48.281 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 9 09-18 20:09:49.282 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 10 09-18 20:09:50.282 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 11 09-18 20:09:51.283 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 12 09-18 20:09:52.283 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 13 09-18 20:09:53.285 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 14 09-18 20:09:53.904 13851-13851/com.sixthenergy.video_rtsp_rtmp E/sixthenergy.cccbr: onReceive: 09-18 20:09:54.285 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 15 09-18 20:09:55.285 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 16
[ 09-18 20:09:55.285 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:09:55.285 307:14230 E/ ]
hi843_8909_register_gain4444=86
[ 09-18 20:09:55.285 307:14230 E/ ]
hi843_8909_gain1111=86
[ 09-18 20:09:55.286 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:09:56.286 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 17 09-18 20:09:57.286 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 18 09-18 20:09:58.286 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 19 09-18 20:09:59.287 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 20 09-18 20:10:00.287 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 21 09-18 20:10:01.287 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 22 09-18 20:10:02.287 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 23 09-18 20:10:03.288 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 24 09-18 20:10:04.288 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 25 09-18 20:10:05.288 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 26 09-18 20:10:06.289 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 27 09-18 20:10:07.289 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 28 09-18 20:10:08.289 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 29 09-18 20:10:09.289 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 30
[ 09-18 20:10:09.335 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:09.335 307:14230 E/ ]
hi843_8909_register_gain4444=120
[ 09-18 20:10:09.335 307:14230 E/ ]
hi843_8909_gain1111=120
[ 09-18 20:10:09.335 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:10.290 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 31 09-18 20:10:11.290 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 32 09-18 20:10:12.290 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 33
[ 09-18 20:10:12.336 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:12.336 307:14230 E/ ]
hi843_8909_register_gain4444=124
[ 09-18 20:10:12.336 307:14230 E/ ]
hi843_8909_gain1111=124
[ 09-18 20:10:12.336 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:13.291 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 34 09-18 20:10:14.292 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 35
[ 09-18 20:10:14.333 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:14.333 307:14230 E/ ]
hi843_8909_register_gain4444=151
[ 09-18 20:10:14.333 307:14230 E/ ]
hi843_8909_gain1111=151
[ 09-18 20:10:14.333 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:15.292 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 36 09-18 20:10:16.292 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 37 09-18 20:10:17.293 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 38
[ 09-18 20:10:17.323 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:17.323 307:14230 E/ ]
hi843_8909_register_gain4444=76
[ 09-18 20:10:17.323 307:14230 E/ ]
hi843_8909_gain1111=76
[ 09-18 20:10:17.323 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:18.293 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 39
[ 09-18 20:10:18.299 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:18.299 307:14230 E/ ]
hi843_8909_register_gain4444=83
[ 09-18 20:10:18.299 307:14230 E/ ]
hi843_8909_gain1111=83
[ 09-18 20:10:18.299 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:19.293 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 40 09-18 20:10:20.294 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 41 09-18 20:10:21.294 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 42
[ 09-18 20:10:21.310 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:21.310 307:14230 E/ ]
hi843_8909_register_gain4444=78
[ 09-18 20:10:21.310 307:14230 E/ ]
hi843_8909_gain1111=78
[ 09-18 20:10:21.310 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:22.294 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 43 09-18 20:10:23.295 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 44
[ 09-18 20:10:23.315 307:14230 E/ ]
hi843_8909_gain3333=-1242925383
[ 09-18 20:10:23.315 307:14230 E/ ]
hi843_8909_register_gain4444=75
[ 09-18 20:10:23.315 307:14230 E/ ]
hi843_8909_gain1111=75
[ 09-18 20:10:23.315 307:14230 E/ ]
hi843_8909_gain2222=479879401
09-18 20:10:24.295 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 45 09-18 20:10:25.295 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 46 09-18 20:10:26.295 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 47 09-18 20:10:27.296 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 48 09-18 20:10:28.296 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 49 09-18 20:10:29.297 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 50 09-18 20:10:30.297 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 51 09-18 20:10:31.298 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 52 09-18 20:10:32.298 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 53 09-18 20:10:33.299 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 54 09-18 20:10:34.301 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 55 09-18 20:10:35.301 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 56 09-18 20:10:36.302 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 57 09-18 20:10:37.302 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 58 09-18 20:10:38.302 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 59 09-18 20:10:39.303 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Secs of recording 60 09-18 20:10:40.303 13851-14255/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Streaming and recording stopped 09-18 20:10:40.644 13851-15177/com.sixthenergy.video_rtsp_rtmp I/sixth.Video2Service: Disconnected
Post service code please.
used stopRecord first and then stopStream, is it OK?
That is indifferent.
package com.sixthenergy.video_rtsp_rtmp; import android.; import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.DhcpInfo; import android.net.NetworkInfo; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.PowerManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.widget.Toast; import com.sixthenergy.video_rtsp_rtmp.builder.rtsp.RtspBuilderSurfaceMode; import com.sixthenergy.video_rtsp_rtmp.rtsp.rtsp.Protocol; import com.sixthenergy.video_rtsp_rtmp.rtsp.utils.ConnectCheckerRtsp; import java.io.File; import java.io.IOException; import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteOrder; import java.util.concurrent.Semaphore; public class Video2Service extends Service implements ConnectCheckerRtsp { private WifiManager localWifiManager; private Handler mHandler; /private File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
"/rtmp-rtsp-stream-client-java");*/ private File folder = new File(System.getenv("SECONDARY_STORAGE") + "/rtmp-rtsp-stream-client-java"); public final static String TAG = "sixth.Video2Service"; private RtspBuilderSurfaceMode rtspBuilderSurfaceMode; public Video2Service() { } @Override public void onCreate() { super.onCreate(); Context context = getApplicationContext();
Log.i(TAG, "camera service called");
final Semaphore signal = new Semaphore(0);
new HandlerThread("com.sixthenergy.videostreamingrtsp"){
@Override
protected void onLooperPrepared() {
mHandler = new Handler();
signal.release();
}
}.start();
signal.acquireUninterruptibly();
init();
} public void init(){ // TODO Auto-generated method stub //super.onStart(intent, startId); //String videoRecPath = System.getenv("SECONDARY_STORAGE") + "/" + getUTCTime() + ".mp4"; Context context = getApplicationContext(); if (!folder.exists()) { folder.mkdir(); } rtspBuilderSurfaceMode = new RtspBuilderSurfaceMode(context, Protocol.TCP, this); mHandler.post(new Runnable () { @Override public void run() { //rtspBuilderSurfaceMode = new RtspBuilderSurfaceMode(context, Protocol.TCP, this); if (!rtspBuilderSurfaceMode.isStreaming()) { if (rtspBuilderSurfaceMode.prepareAudio() && rtspBuilderSurfaceMode.prepareVideo()) { rtspBuilderSurfaceMode.startStream("rtsp://223.30.185.189:5554/sc20"); } else { /Toast.makeText(this, "Error preparing stream, This device cant do it", Toast.LENGTH_SHORT) .show();/ } } else { rtspBuilderSurfaceMode.stopRecord(); rtspBuilderSurfaceMode.stopStream(); } } }); } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } @Override public void onConnectionSuccessRtsp() { Log.i(TAG, "Connection success");
} @Override public void onConnectionFailedRtsp() { Log.i(TAG, "Connection failed");
} @Override public void onDisconnectRtsp() { Log.i(TAG, "Disconnected");
} @Override public void onAuthErrorRtsp() { Log.i(TAG, "Auth error");
} @Override public void onAuthSuccessRtsp() { Log.i(TAG, "Auth success");
} public void onStartStream() { Log.i(TAG, "Start Stream success"); if(rtspBuilderSurfaceMode.isStreaming()) { String videoRecPath = ""; videoRecPath = folder.getAbsolutePath() + "/" + getUTCTime() + ".mp4"; Log.i(TAG, "video 2 service started and recording at : " + videoRecPath); try { //Thread.sleep(2000); rtspBuilderSurfaceMode.startRecord(videoRecPath);rtspBuilderSurfaceMode.stopRecord(); Log.i(TAG, "Recording started "); } catch (IOException ioex) { } try { int videoStartTime = getUTCTime(); //int lastRecordtime = getUTCTime(); int i = 1; while (true) { //if((getUTCTime() - lastRecordtime) > 1 ){ //if(i > ){ Log.i(TAG, "Secs of recording " + i); try { Thread.sleep(1000); } catch (InterruptedException iex) { } //lastRecordtime = getUTCTime(); i++; //} if (i > 60) { //30 secs Log.i(TAG, "Streaming and recording stopped "); rtspBuilderSurfaceMode.stopStream(); //rebootModule(); break; } } } catch (Exception ex) { } }
}
}
onStartStream() is called in RtspClient.java after the onConnectionSuccessRtsp()
You never do a stopRecord... You are doing a startRecord and then stop inmediatally. onStartStream should be like this:
public void onStartStream() {
Log.i(TAG, "Start Stream success");
if (rtspBuilderSurfaceMode.isStreaming()) {
String videoRecPath = "";
videoRecPath = folder.getAbsolutePath() + "/" + getUTCTime() + ".mp4";
Log.i(TAG, "video 2 service started and recording at : " + videoRecPath);
try {
//Thread.sleep(2000);
rtspBuilderSurfaceMode.startRecord(videoRecPath);
Log.i(TAG, "Recording started ");
} catch (IOException ioex) {
}
try {
int videoStartTime = getUTCTime();
//int lastRecordtime = getUTCTime();
int i = 1;
while (true) {
//if((getUTCTime() - lastRecordtime) > 1 ){
//if(i > ){
Log.i(TAG, "Secs of recording " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException iex) {
}
//lastRecordtime = getUTCTime();
i++;
//}
if (i > 60) { //30 secs
Log.i(TAG, "Streaming and recording stopped ");
rtspBuilderSurfaceMode.stopStream();
rtspBuilderSurfaceMode.stopRecord();
//rebootModule();
break;
}
}
} catch (Exception ex) {
}
}
}
Thanks a lot, I made a mistake in calling the stopRecord function
After this correction the file size of the recording is coming around 5 MB. But the same is not playable in the VLC player.
I checked the recording in the ffmpeg and found the start record was missing sps and pps, later I moved the start record, befor the sps and pps is formed. Later only the first frame is visible and after that their is an error showing no frame. Can u guide on how to resolve this ?
Yes, this is my error. But if you record with rtmp is working fine, I don't understand it :(
ohh !!!, our requirement is to do with the RTSP only. Please help on how to resolve this.
Fixed. Clone last version and work.
Ok thanks, I will check the latest version and work
Now its working, the recording is able to play in the ffmpeg player, Thanks a lot.
But the same not being played in the VLC player. Any thought on it, why its not working with the VLC player.
It work for me in the official VLC app. Try with others players on android.
I am trying in the PC/Laptop to run this recording (.mp4). But its not opening with VLC player in the laptop.
I have one query with you , that is, whether the recording is dependent on the streaming. Because if there is no network connectivity, we still need to have a recording in the SD card. is it possible to do?
That is possible, I will add it to backlog but for now I want develop others things more interesting for me like stream with watermark. Please clone the project and use my app to record in custom rtsp activity. Firsts start stream, start record, stop it and now you can stop stream.
ok, I will clone the project and test it using your app
I tried to do the testing from you app, I am always getting an error saying, "Error preparing stream, This device cant do it" on click of start stream in the Rtsp activity.
I think you have used RtspCamera1, which uses old camera API, there is a problem in working with old camera api
No camera api problem, 2 possibilities:
If you are using a rooted device I can't help you because this could have firmware bugs. If not I can discard second option because camera2 is working for you. Please try create a demo activity with buttons for start/stop stream and start/stop record and follow steps that I tell you before.
The VLC player issue is resolved after taking the complete clone of the project. The Audio in the live stream is not working but the same is working in the recording. Any idea, on why this could happen?
I need more information about it. What media server are you using?
If you open stream with VLC and show codec information, do you see audio channel?. In that window statistics do you lose audio packets?
Your media server tell you that audio packets are received?
If you use UDP protocol, can you see 2 ports in the log? like:
09-20 15:52:42.927 14171-17462/com.pedro.rtmpstreamer I/RtpSocket: send packet, 1064 Size, 6976 Port
09-20 15:52:42.927 14171-17461/com.pedro.rtmpstreamer I/RtpSocket: send packet, 1272 Size, 6978 Port
I found the problem, it was my mistake, I had not setup the audio track. I will add the same and test it tomorrow. Thanks for your support. I am working on the TCP transport now. I have to start the UPD transport also
We are using the MIST server for the RTSP /RTP streaming,
through UDP, the client setup is 5001-5002 but the actual udp packets are sent through a different port. Because of which we are not able to stream.
When you connect to server with UDP the app do a request to know ports where stream can be send and server respond with 2 ports for video and 2 ports for audio so you cant stream UDP with only 2 ports video and audio. I think this is a server problem. Try stream RTSP UDP with ffmpeg, if it work and I can install that server for free I will debug the UDP problem.
Trying to stream RTSP To Rtsp server set at our office:
I am trying since 1 month, but i am facing the issue of cameraDevice.createCaptureSession is leading to onConfigureFailed.
Need your help to resolve the same
I am using the android build as below (android version in the device is 5.1.1) { compileSdkVersion 25 buildToolsVersion "25.0.2"
defaultConfig { applicationId "com.pedro.rtmpstreamer" minSdkVersion 21 targetSdkVersion 25 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
dependencies { compile project(':rtplibrary') compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' }
Logcat print as below:
startPreview: called 09-12 08:47:22.852 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: addPreviewSurface: addPreviewSurface in surface view 09-12 08:47:22.852 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: addPreviewSurface: addPreviewSurface in sufaceview.width : 0 , sufaceview.height : 0 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: addPreviewSurface 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: before add surface 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: after add surface 09-12 08:47:22.861 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: camera opened 09-12 08:47:22.862 8557-8670/com.pedro.rtmpstreamer E/sixth.Camera2ApiManager: configuration failed