顯示具有 youtube 標籤的文章。 顯示所有文章
顯示具有 youtube 標籤的文章。 顯示所有文章

2021/05/14

之前的直播都是直接上youtube

今天有個需求 希望能夠不要使用youtube

而且user要能直接用browser看 不需要 vlc

因為之前上看校的直播使用的是 rtmp

查了一下資料

如果要在browser用rtmp

使用的播放程式都必需轉成flash

問題是現在沒有browser支援flash了

所以想到另一個方式

先把串流轉成hls (m3u8)的格式

在srs.conf 裡進行如下的修改

vhost __defaultVhost__ {

   hls {

        enabled         on;

        hls_path        /usr/local/srs/objs/nginx/html/; (此行依現況調整)

        hls_fragment    10;

        hls_window      60;

    }

}

改完重啟 並進行串流後

會在html生成live目錄及相關的m3u8文件


在client端目前看來只有 safari 能直接在html5 使用 <video> 播放

其他browser都需要再呼叫播放器

參考以下範例


<html>

<head>

    <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">

</head>

 

<body>

    <video id='my-video' class='video-js' controls preload='auto' width='800' height='600' poster='avatar-poster.jpg'

        data-setup='{ "html5" : { "nativeTextTracks" : true } }'>

        <source src='http://1.2.3.4:8080/live/livestream.m3u8' type="application/x-mpegURL">

        <p class='vjs-no-js'>

            To view this video please enable JavaScript, and consider upgrading to a web browser that

            <a href='https://videojs.com/html5-video-support/' target='_blank'>supports HTML5 video</a>

        </p>

    </video>

 

    <script src='https://vjs.zencdn.net/7.4.1/video.js'></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"></script>

 

    <script>

        var player = videojs('my-video');

        player.play();

    </script>

 

</body>

</html>


如果不使用直播而是想播放檔案

就要先把 mp4 轉成 hls

指令如下


ffmpeg -i video.mp4 -codec: copy -start_number 0 -hls_time 15 -hls_list_size 0 -f hls video.m3u8


接下來再依照上述的html範例進行修改 


https://caniuse.com/http-live-streaming


https://blog.csdn.net/weixin_40592935/article/details/109361642


https://videojs.com/


https://videojs.com/getting-started

2012/05/27

今天想到一個需求
要將youtube的影片自動並重複播放


新版iframe內嵌程式碼
新版因為採用新的技術來播放影片,而YouTube也尚未釋出新的自動播放參數,所以只需修改一下新版iframe內嵌程式碼 就可以達成我們自動播放YouTube嵌入影片的目的!
原理是把新版iframe內嵌程式碼的影片網址改成舊版embed內嵌程式碼的影片網址就可以重新使用舊版的YouTube嵌入影片的自動播放參數。

首先必須把藍色的embed

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/pY5jko0w8PQ" frameborder="0" allowfullscreen></iframe>

改成v
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/v/pY5jko0w8PQ" frameborder="0" allowfullscreen></iframe>

然後同樣地把自動播放參數
&autoplay=1

重複播放參數為
&loop=1

加在綠色的影片ID後面
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/v/pY5jko0w8PQ&autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>

http://happy-yblog.blogspot.com/2011/03/youtube_28.html

===================================================================
建立公開播放清單後也可以使用

<iframe width="853" height="480" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&amp;hl=zh_TW" frameborder="0" allowfullscreen></iframe>

改為

<iframe width="853" height="480" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>

用BlueGriffon編輯時以上的語法會顯示有錯誤

要改成如下


<iframe width="560"
          height="315" frameborder="0" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&amp;autoplay=1;loop=1;hl=zh_TW"
          allowfullscreen="1"></iframe>


還沒找到去除廣告的方法