如何在不停止流媒体的情况下保存 VoD 录音?

问题描述

如何在不停止流的情况下,在我的流源和网络摄像机中保存 Ant Media Server 中的点播?

解决方法

您可以使用 python 脚本来实现。假设你已经安装了 python3 和 pip。 以下脚本以用户定义的时间间隔停止并再次开始记录:

import sys
import sched,time
try:
    import requests
    print("requests library already installed!")
except ImportError:
    try:
        import pip
        print("requests library is being installed")
        pip.main(['install','--user','requests'])
        import requests
    except ImportError:
        print("pip is not installed,so it needs to be installed first to proceed further.\nYou can install pip with the following command:\nsudo apt install python3-pip")
slp=sched.scheduler(time.time,time.sleep)
def startStopRecording(s):
    print("Stopping the recording of "+sys.argv[2])
    response=requests.put(sys.argv[1]+"/rest/v2/broadcasts/"+sys.argv[2]+"/recording/false")
    if response.json()["success"]:
        print("recording of "+sys.argv[2]+" stopped successfully")
        print(response.content)
        print("starting the recording of "+sys.argv[2])
        response=requests.put(sys.argv[1]+"/rest/v2/broadcasts/"+sys.argv[2]+"/recording/true")
        print(response.content)
        if response.json()["success"]:
            print("recording of "+sys.argv[2]+" started successfully")
            s.enter(int(sys.argv[3]),1,startStopRecording,(s,))
        else:
            print("Couldn't start the recording of "+sys.argv[2])
            print("content of the response:\n"+response.content)
            sys.exit()

    else:
        print("Couldn't stop the recording of "+sys.argv[2])
        print("content of the response:")
        print(response.content)
        sys.exit()
    
slp.enter(int(sys.argv[3]),(slp,))
slp.run()

示例用法如下:python3 file.py https://domain/{Application} streamId interval

第一个参数是您要使用的域,例如:https://someexample.com:5443/WebRTCAppEE

第二个参数是您要使用的流 ID。前任。流123.

第三个参数是您要重新开始录制的间隔的持续时间。持续时间单位为秒。所以 60 等于 1 分钟。