网站设计的重要性,app软件开发合同范本,网站关键词怎样做优化,网站建设需求确认书实现Android平台GB28181设备接入的时候#xff0c;有个功能点不可避免#xff0c;那就是本地录像#xff0c;实际上#xff0c;在实现GB28181设备接入模块之前#xff0c;我们前些年做RTMP推送和轻量级RTSP服务的时候#xff0c;早已经实现了本地录像功能。 本地录像功能…实现Android平台GB28181设备接入的时候有个功能点不可避免那就是本地录像实际上在实现GB28181设备接入模块之前我们前些年做RTMP推送和轻量级RTSP服务的时候早已经实现了本地录像功能。 本地录像功能我们实现的主要控制接口如下
音视频录制开关为了更细粒度的控制录像如只需要录纯音频还是纯视频或者音视频可以通过下述两个接口实现
/*** 音频录制开关, 目的是为了更细粒度的去控制录像, 一般不需要调用这个接口, 这个接口使用场景比如同时推送音视频但只想录制视频可以调用这个接口关闭音频录制** param is_recoder: 0: do not recorder; 1: recorder; sdk默认是1** return {0} if successful*/public native int SmartPublisherSetRecorderAudio(long handle, int is_recoder);/*** 视频录制开关, 目的是为了更细粒度的去控制录像, 一般不需要调用这个接口, 这个接口使用场景比如同时推送音视频但只想录制音频可以调用这个接口关闭视频录制** param is_recoder: 0: do not recorder; 1: recorder; sdk默认是1** return {0} if successful*/public native int SmartPublisherSetRecorderVideo(long handle, int is_recoder);
创建并设置录像目录
/*** Create file directory(创建录像存放目录)* * param path, E.g: /sdcard/daniulive/rec* * pre The interface is only used for recording the stream data to local side. /pre * * return {0} if successful*/public native int SmartPublisherCreateFileDirectory(String path);/*** Set recorder directory(设置录像存放目录)* * param path: the directory of recorder file.* * pre NOTE: make sure the path should be existed, or else the setting failed. /pre* * return {0} if successful*/public native int SmartPublisherSetRecorderDirectory(long handle, String path);
设置单个文件录制的大小 /*** Set the size of every recorded file(设置单个录像文件大小如超过最大文件大小自动切换到下个文件录制)* * param size: (MB), (5M~500M), if not in this range, set default size with 200MB.* * return {0} if successful*/public native int SmartPublisherSetRecorderFileMaxSize(long handle, int size);
启动录像、暂停录像、停止录像说到这里好多开发者可能对暂停/恢复录像比较感兴趣实际上我们在具体使用场景下并不是所有的数据都想录制下来比如智慧教室下课时间我们无需录制这时候只要调用PauseRecorder来暂停录像等上课后恢复录像即可。
/*** Start recorder(开始录像)** return {0} if successful*/public native int SmartPublisherStartRecorder(long handle);/*** Pause recorder(暂停/恢复录像)** is_pause: 1表示暂停, 0表示恢复录像, 输入其他值将调用失败** return {0} if successful*/public native int SmartPublisherPauseRecorder(long handle, int is_pause);/*** Stop recorder(停止录像)** return {0} if successful*/public native int SmartPublisherStopRecorder(long handle);
具体调用如下
class ButtonStartRecorderListener implements View.OnClickListener {public void onClick(View v) {if (isRecording) {stopRecorder();if (!isPushingRtmp !isRTSPPublisherRunning !isGB28181StreamRunning) {ConfigControlEnable(true);}btnStartRecorder.setText(实时录像);isRecording false;btnPauseRecorder.setText(暂停录像);btnPauseRecorder.setEnabled(false);isPauseRecording true;return;}Log.i(TAG, onClick start recorder..);if (libPublisher null)return;if (!isPushingRtmp !isRTSPPublisherRunning !isGB28181StreamRunning) {InitAndSetConfig();}ConfigRecorderParam();int startRet libPublisher.SmartPublisherStartRecorder(publisherHandle);if (startRet ! 0) {isRecording false;Log.e(TAG, Failed to start recorder.);return;}if (!isPushingRtmp !isRTSPPublisherRunning !isGB28181StreamRunning) {CheckInitAudioRecorder();ConfigControlEnable(false);}startLayerPostThread();btnStartRecorder.setText(停止录像);isRecording true;btnPauseRecorder.setEnabled(true);isPauseRecording true;}}
实际上本地录像和GB28181上去的数据是同一路编码数据当然如果做的更智能一些也可以分两个实例来实现一路编码用于GB28181平台接入一路高分辨率帧率用于本地录制具体根据使用场景定制即可。