我正在尝试在 django 上构建视频播放器。我正在使用 MPEG-DASH 进行视频文件的自适应流式传输。我在一开始就选择了一个示例视频。然后,使用 ffmpeg 命令,我将视频编码为 240p、360p、480p 和 720p 视频。也有单独编码的音频。
然后,使用 mp4box,我生成了 .mpd 文件。我读过 mpd 文件不能从本地文件系统运行,需要托管在服务器上。我有一个破折号播放器设置如下:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>player</title>
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>
<style>
video {
width: 640px;
height: 360px;
}
</style>
</head>
<body>
<div>
<video data-dashjs-player autoplay src="https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd" controls></video>
</div>
</body>
</html>
src 字段中的 url 是我用来测试播放器的随机清单文件。它工作正常。
然后,在我的 django 项目中,我创建了一个媒体文件夹,用于存储通过表单上传的媒体文件(根目录包含在 中settings.py
)。我的问题是我在哪里存储视频、音频和 .mpd 文件,以便我可以使用位于模板文件夹中的 html 代码播放它们。我尝试在源中使用 .mpd 文件的媒体 url,但无法播放视频。
这是生成的mpd文件供参考:
<?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 0.7.0-rev0-gbd5c9af-master at 2018-12-21T18:45:32.091Z-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H1M9.869S" maxSegmentDuration="PT0H0M9.985S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011,http://dashif.org/guidelines/dash264">
<ProgramInformation moreInformationURL="http://gpac.io">
<Title>BBB</Title>
</ProgramInformation>
<Period duration="PT0H1M9.869S">
<AdaptationSet segmentAlignment="true" lang="und" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="44100" startWithSAP="1" bandwidth="130920">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<BaseURL>sample_audio_dashinit.mp4</BaseURL>
<SegmentBase indexRangeExact="true" indexRange="902-1017">
<Initialization range="0-901"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet segmentAlignment="true" group="1" maxWidth="426" maxHeight="240" maxFrameRate="30" par="426:240" lang="und" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Representation id="2" mimeType="video/mp4" codecs="avc1.640015" width="426" height="240" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="590708">
<BaseURL>sample_video_240_dashinit.mp4</BaseURL>
<SegmentBase indexRangeExact="true" indexRange="914-1053">
<Initialization range="0-913"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet segmentAlignment="true" group="1" maxWidth="640" maxHeight="480" maxFrameRate="30" par="4:3" lang="und" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Representation id="3" mimeType="video/mp4" codecs="avc1.64001E" width="480" height="360" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="883873">
<BaseURL>sample_video_360_dashinit.mp4</BaseURL>
<SegmentBase indexRangeExact="true" indexRange="914-1053">
<Initialization range="0-913"/>
</SegmentBase>
</Representation>
<Representation id="4" mimeType="video/mp4" codecs="avc1.64001E" width="640" height="480" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="1188712">
<BaseURL>sample_video_480_dashinit.mp4</BaseURL>
<SegmentBase indexRangeExact="true" indexRange="913-1052">
<Initialization range="0-912"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet segmentAlignment="true" group="1" maxWidth="1280" maxHeight="720" maxFrameRate="30" par="16:9" lang="und" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Representation id="5" mimeType="video/mp4" codecs="avc1.64001F" width="1280" height="720" frameRate="30" sar="1:1" startWithSAP="1" bandwidth="2365717">
<BaseURL>sample_video_720_dashinit.mp4</BaseURL>
<SegmentBase indexRangeExact="true" indexRange="914-1053">
<Initialization range="0-913"/>
</SegmentBase>
</Representation>
</AdaptationSet>
</Period>
</MPD>