Gstreamer rtmpsink到Azure媒体服务直播活动

问题描述 投票:0回答:1

我正在尝试使用本地gstreamer编码器管道将实时视频广播到Azure Media Services。

使用videotestsrc测试管道似乎可以正常使用以下字符串:

gst-launch-1.0 -e videotestsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency byte-stream=true threads=4 ! flvmux streamable=true ! rtmpsink location='rtmp://xxxx.media.azure.net:1935/live/xxxx/mystream live=true flashver=FMLE/3.0(compatible;FMSc/1.0)'

我可以在Azure AMS仪表板中观看流的预览。

现在,如果我尝试使用OpenCV(使用gstreamer支持编译)从我的python脚本中使用appsrc管道,则预览窗口中不会显示任何内容。但是,正在为流创建资产,并且我能够通过AMS服务查看此资产流。

以下python3脚本使用自定义版本的OpenCV版本4.0.0与gstreamer和cuda编译。

import sys
import time
import urllib
import cv2
import numpy as np
from datetime import datetime


TEST_CARD = 'https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png'
HEADLINE = 'AZURE LIVE STREAM'

RTMP_SERVER = 'rtmp://xxxx.media.azure.net:1935/live/xxxx/mystream'
GST_PIPE = "appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency byte-stream=true threads=4 ! flvmux streamable=true ! rtmpsink location='{0} live=true flashver=FMLE/3.0(compatible;FMSc/1.0)' ".format(RTMP_SERVER)

if __name__ == '__main__':
    print ('Azure Mediastream tester')
    print(sys.version)
    print (cv2.getBuildInformation())

    imgRequest = urllib.request.urlopen(TEST_CARD)
    imgArray = np.asarray(bytearray(imgRequest.read()), dtype=np.uint8)
    imgO = cv2.imdecode(imgArray, -1)

    h,w,c = imgO.shape
    font = cv2.FONT_HERSHEY_PLAIN
    line = cv2.LINE_AA
    cv2.putText(imgO,HEADLINE,(302,85),font,1,(255,255,255),2,line)

    print(HEADLINE)
    print ('Showing: {0} at [h:{1},w:{2},c:{3}]'.format(TEST_CARD,h,w,c))
    print ('Opening GSTREAM {0}'.format(GST_PIPE))

    try:
        fcc = cv2.VideoWriter.fourcc ('X','2','6','4')
        stream = cv2.VideoWriter(GST_PIPE,fcc,25.0,(w,h))
        while True:
            currentTime = datetime.now()
            img = imgO.copy()
            cv2.putText(img,str(currentTime),(283,460),font,1,(255,255,255),1,line)

            stream.write(img)
            cv2.imshow(HEADLINE,img)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
    finally:
        stream.release()
        cv2.destroyAllWindows()
        print ('DONE')

我在这里错过了什么?

python opencv gstreamer rtmp azure-media-services
1个回答
0
投票

因此,在与Microsoft的Azure媒体服务团队进行广泛对话之后,事实证明Azure Media Player需要一个声音轨道才能播放。

将GST_PIPE更改为:

GST_PIPE = "appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency byte-stream=true threads=4 ! flvmux name=mux ! rtmpsink location='{0} live=true flashver=FMLE/3.0(compatibble;FMSc/1.0)' audiotestsrc is-live=true ! audioconvert ! audioresample ! audio/x-raw,rate=48000 ! voaacenc bitrate=96000 ! audio/mpeg ! aacparse ! audio/mpeg, mpegversion=4 ! mux.".format(RTMP_SERVER)

在我的Python代码中,使一切按预期工作(Azure门户中的通道预览面板除外(仍然不知道那里发生了什么))。

© www.soinside.com 2019 - 2024. All rights reserved.