我正在尝试在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文件的媒体网址,但无法播放视频。
以下是生成的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>