【问题标题】:unable to stream rtmp to web page无法将 rtmp 流式传输到网页
【发布时间】:2019-05-03 06:34:37
【问题描述】:

我正在尝试使用 RTMP 将本地驱动器中的视频流式传输到浏览器。 我正在关注这个tutorial

这是cpp代码的一部分:

std::string video_fname;
video_fname = std::string(argv[1]);
cv::VideoCapture video_capture;
bool from_camera = false;
if(video_fname == "0") {
    video_capture = cv::VideoCapture(0);
    from_camera = true;
} else {
    video_capture=  cv::VideoCapture(video_fname);
}

if(!video_capture.isOpened()) {
    fprintf(stderr, "could not open video %s\n", video_fname.c_str());
    video_capture.release();
    return 1;
}

int cap_frame_width = video_capture.get(CV_CAP_PROP_FRAME_WIDTH);
int cap_frame_height = video_capture.get(CV_CAP_PROP_FRAME_HEIGHT);

int cap_fps = video_capture.get(CV_CAP_PROP_FPS);
printf("video info w = %d, h = %d, fps = %d\n", cap_frame_width, cap_frame_height, cap_fps);

int stream_fps = cap_fps;

int bitrate = 500000;
Streamer streamer;
StreamerConfig streamer_config(cap_frame_width, cap_frame_height,
                               1920, 1080,
                               stream_fps, bitrate, "high444", "rtmp://127.0.0.1/live/mystream");

streamer.enable_av_debug_log();
streamer.init(streamer_config);

size_t streamed_frames = 0;

所以你可以看到RTMP链接是rtmp://127.0.0.1/live/mystream,在启动我的Nginx后,我可以简单地将这个链接插入到我浏览器的URL字段中并播放它没有任何问题。 但是,现在我需要在 HTML 网页上流式传输它,但我不能这样做。

html代码:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>videojs-contrib-hls embed</title>

  <!--

  Uses the latest versions of video.js and videojs-http-streaming.

  To use specific versions, please change the URLs to the form:

  <link href="https://unpkg.com/video.js@6.7.1/dist/video-js.css" rel="stylesheet">
  <script src="https://unpkg.com/video.js@6.7.1/dist/video.js"></script>
  <script src="https://unpkg.com/@videojs/http-streaming@0.9.0/dist/videojs-http-streaming.js"></script>

  -->

  <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
</head>
<body>
  <h1>Video.js Example Embed</h1>

  <video-js id="my_video_1" class="vjs-default-skin" controls preload="auto" width="640" height="268">
    <source src="rtmp://127.0.0.1/live/mystream" type="rtmp/flv">
  </video-js>

  <script src="https://unpkg.com/video.js/dist/video.js"></script>
  <script src="https://unpkg.com/@videojs/http-streaming/dist/videojs-http-streaming.js"></script>

  <script>
    var player = videojs('my_video_1');
  </script>

</body>
</html>

我不断收到一条错误消息,提示视频格式不受支持。请展示如何做到这一点。我已经浏览了所有在线指南(实际上它们都是一样的),但它们都不起作用。谢谢

【问题讨论】:

    标签: javascript html video.js rtmp


    【解决方案1】:

    我不断收到错误消息,提示不支持视频格式

    这是因为不支持 rtmp。没有浏览器支持rtmp。您必须将服务器端转换为受支持的东西,例如 HLS 或 DASH。

    【讨论】:

    • 您好,感谢您的回答。对我知道那个。所以问题是怎么做?我在网上看到了很多关于如何使用 videoJS 来实现这一点的教程,但没有一个对我有用。对于在线教程,它们都有以“m3u8”结尾的视频源,我不知道如何获得类似的源,因为我的不一样。 **我选择 videoJS 因为它是免费的。我需要一些免费的东西谢谢
    • 我们只能通过回答您提出的问题来提供帮助。您问为什么不能在浏览器中播放 rtmp 流。如果您想知道如何将 rtmp 转换为 hls,请提出该问题(但首先要搜索,因为这里至少回答了十几次)。请不要让那些试图帮助你跳槽的人。它浪费了每个人(包括你)的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    相关资源
    最近更新 更多