Android平台GB28181设备接入端如何实现本地录像?

102 篇文章 20 订阅
102 篇文章 1 订阅

实现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平台接入,一路高分辨率帧率,用于本地录制,具体根据使用场景定制即可。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值