当前位置:网站首页>Local broadcast MSE fragments mp4 service
Local broadcast MSE fragments mp4 service
2022-08-02 19:33:00 【Technical Notes from HUI】
To test the browserMSE的多媒体框架,搭建一个MSEService will be much more convenient,这里记录下fragment mp4服务的搭建过程.
生成fragment mp4
下载安装bento4
Bento4是一个C++类库和工具,用于读取和写入ISO-MP4文件.除了支持ISO-MP4外,Bento4Parsing and reuse are also supportedH.264和H.265 ES流,将ISO-MP4转换为MPEG2-TS,打包HLS和MPEG-DASH、CMAF、内容加密、解密等.
# http://zebulon.bok.net/Bento4/binaries/
wget http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-639.x86_64-unknown-linux.zip
unzip Bento4-SDK-1-6-0-639.x86_64-unknown-linux.zip
cd Bento4-SDK-1-6-0-639.x86_64-unknown-linux/
# 直接放到/usr目录下
sudo cp * /usr/. -rf
输入mp4,tab键补全,可以看到,可用的binarycan be found:
$ mp4
mp42aac mp42hevc mp42ts mp4dash mp4dcfpackager
mp4dump mp4encrypt mp4fragment mp4iframeindex mp4mux
mp4split mp42avc mp42hls mp4compact mp4dashclone
mp4decrypt mp4edit mp4extract mp4hls mp4info
mp4rtphintinfo mp4tag
转换mp4为fragment mp4
使用mp4fragment
,将普通mp4转换为fragment mp4,不指定--fragment-duration
,生成的fragment duration按default值:
$ mp4fragment video.mp4 fragmented-default.mp4
found regular I-frame interval: 1511 frames (at 29.970 frames per second)
auto-detected fragment duration too large, using default
指定fragment时长为2s:
mp4fragment --fragment-duration 2000 video.mp4 fragmented.mp4
通过mp4info查看生成的fragmented.mp4文件信息,这时候fragments字段已经变成yes:
$ mp4info fragmented.mp4
File:
major brand: isom
minor version: 200
compatible brand: isom
compatible brand: iso2
compatible brand: avc1
compatible brand: mp41
compatible brand: iso5
fast start: yes
Movie:
duration: 97903 (media timescale units)
duration: 97903 (ms)
time scale: 1000
fragments: yes
fragment mp4分片
对fragment mp4进行分片:
$ mp4dash fragmented.mp4
Parsing media file 1: fragmented.mp4
WARNING: video segment durations for "File 1#1" vary by more than 10% (consider using --use-segment-timeline)
Splitting media file (video) fragmented.mp4
分片完成后,没有指定output-dir参数,会生成output目录:
$ cd output/video/avc1
$ ls
init.mp4 seg-11.m4s seg-13.m4s seg-15.m4s seg-17.m4s seg-19.m4s
seg-20.m4s seg-22.m4s seg-3.m4s seg-5.m4s seg-7.m4s seg-9.m4s
seg-10.m4s seg-12.m4s seg-14.m4s seg-16.m4s seg-18.m4s seg-1.m4s
seg-21.m4s seg-2.m4s seg-4.m4s seg-6.m4s seg-8.m4s
配置mse-demo
新建4k.html文件,修改baseUrl,templateUrl字段,放到nginx服务的目录下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MSE Demo</title>
</head>
<body>
<h1>MSE Demo</h1>
<div>
<video controls width="80%"></video>
</div>
<script type="text/javascript"> (function() {
var baseUrl = 'http://192.168.31.124/dash/output/video/avc1/'; var initUrl = baseUrl + 'init.mp4'; var templateUrl = baseUrl + 'seg-$Number$.m4s'; var sourceBuffer; var index = 1; var numberOfChunks = 22; var video = document.querySelector('video'); if (!window.MediaSource) {
console.error('No Media Source API available'); return; } var ms = new MediaSource(); video.src = window.URL.createObjectURL(ms); ms.addEventListener('sourceopen', onMediaSourceOpen); function onMediaSourceOpen() {
sourceBuffer = ms.addSourceBuffer('video/mp4; codecs="avc1.4d401f"'); sourceBuffer.addEventListener('updateend', nextSegment); GET(initUrl, appendToBuffer); video.play(); } function nextSegment() {
var url = templateUrl.replace('$Number$', index); GET(url, appendToBuffer); index++; if (index > numberOfChunks) {
sourceBuffer.removeEventListener('updateend', nextSegment); } } function appendToBuffer(videoChunk) {
if (videoChunk) {
sourceBuffer.appendBuffer(new Uint8Array(videoChunk)); } } function GET(url, callback) {
var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = 'arraybuffer'; xhr.onload = function(e) {
if (xhr.status != 200) {
console.warn('Unexpected status code ' + xhr.status + ' for ' + url); return false; } callback(xhr.response); }; xhr.send(); } })(); </script>
</body>
</html>
播放测试
$ google-chrome http://192.168.31.124/mse-demo/4k.html
- https://github.com/hongszh/mse-demo
边栏推荐
- golang源码分析(5):sync.Once
- 再获权威认证!马上消费安逸花APP通过中国信通院“金融APP人脸识别安全能力评测”
- H.265视频流媒体播放器EasyPlayer.js集成时报错“SourceBuffer ”如何解决?
- golang源码分析(6):sync.Mutex sync.RWMutex
- cpolar应用实例之多设备数据采集
- 蔚来杯2022牛客暑期多校训练营5 ABCDFGHK
- SQL语句基础
- JS数组删除其中一个元素
- npm install报gyp info it worked if it ends with ok
- When Oracle analyzes the archive log content, it finds many nulls?
猜你喜欢
nacos简单使用
Five speakers: seventy genius_platform software platform development 】 【 turn YUY2 RGB24 implementation source code
Kubernetes:(五)Pod进阶(资源限制、健康检查)
FP6606CLP5 SOP-8 USB Type-C和PD充电控制器
Gartner released, annual Challenger!
oracle 和mysql 语句结果不一致问题
潮玩的“第二春”,在哪?
Kubernetes:(七)优化大法(江湖失传已久的武林秘籍)
Continuous integration (4) Jenkins configuration alarm mechanism
「全球数字经济大会」登陆 N 世界,融云提供通信云服务支持
随机推荐
Nacos配置中心用法详细介绍
Wechat Gymnasium Appointment Mini Program Graduation Design Finished Works Mini Program Graduation Design Finished Work (6) Question Opening Reply PPT
二舅“反转”了?
持续集成(四)Jenkins配置报警机制
什么是实时流引擎?
图解LeetCode——622. 设计循环队列(难度:中等)
Five speakers: seventy genius_platform software platform development 】 【 turn YUY2 RGB24 implementation source code
Pytest学习笔记
金仓数据库KingbaseES安全指南--6.10. Peer身份验证
什么是APS系统?导入APS要注意什么?值得反复观看
小程序毕设作品之微信体育馆预约小程序毕业设计成品(5)任务书
AI+医疗:使用神经网络进行医学影像识别分析
golang源码分析(10)slice
NeRF:火爆科研圈的三维重建技术大揭秘
Common software silent installation parameters
Flink学习9:配置idea开发flink-Scala程序环境
边界访问的空间权限
罗敏背后是抖音
MySQL——慢查询日志分析
Numpy those things