我研究了一个星期,找到一种简单且独立于平台的方法,将mp4文件流式传输到任何浏览器。在浏览器不兼容的情况下,将使用渐进流(直接下载)方法。我的情况是这样的:
在研究Apple HLS,Adobe Flash Stream,Microsoft Smooth,RTSP和MPEG-DASH之后,似乎 MPEG-DASH 是正确的解决方案。但问题是MPEG-DASH迫使我将mp4文件拆分为单独的分段文件,导致重复消耗空间来存储mp4文件,因为在浏览器不兼容的情况下我必须支持渐进式流。然后存储带有分段mp4文件的单个mp4文件是不可避免的。
问题是:有没有办法将单个 mp4文件作为 http stream &在任何浏览器中渐进式流?
MPEG-DASH协议表示它支持多路复用文件,但问题是dash.js不支持它。有没有其他javascript播放器支持带字节范围请求的多路复用和单个mp4文件?
欢迎提交我的场景条件的任何其他解决方案。 感谢。
参考文献: BitCodin.com 1 BitCodin.com 2
答案 0 :(得分:5)
是的,有一个解决方案。 dash.js只播放已打包的碎片mp4。然而,来自Telecom Paristech的Cyril的这个项目将做你想要的:
https://github.com/gpac/mp4box.js/
这是mp4box的js版本。它可以做的是将非碎片mp4动态转换为媒体片段,然后将其馈送到MSE sourceBuffer。他们有一个样本播放器,你可以复制它:
http://download.tsi.telecom-paristech.fr/gpac/mp4box.js/
干杯 将
答案 1 :(得分:2)
我认为所有主流浏览器都支持mp4。 http://caniuse.com/#feat=mpeg4。您可以使用一个好的旧http服务器来流式传输它。只有当你需要自适应比特率流,多语言,drm等花哨的东西时才需要MPEG-DASH
。
如果您坚持使用MPEG-DASH
,您可以使用服务器端的mp4box来简单地分割您的mp4文件(您只需要执行一次)。结果不是多个mp4文件,而是一个更适合流式传输的单个mp4文件。
答案 2 :(得分:2)
您可以使用单个mp4文件为dash player提供服务。但是,您需要将索引信息放在此mp4文件的sidx框中。你可以用bento4去做。实际上,对于ondemand情况,通常使用一个文件来传输。您也可以在本地下载此文件。 如果您只有一个比特率,则短划分流不需要更多存储空间。并且有很多javascript播放器支持破折号像shakashaka播放器,dashif播放器......
答案 3 :(得分:1)
也许这会帮助您:
#!/bin/bash
# THIS SCRIPT CONVERTS EVERY MP4 (IN THE CURRENT FOLDER AND SUBFOLDER) TO A MULTI-BITRATE VIDEO IN MP4-DASH
# For each file "videoname.mp4" it creates a folder "dash_videoname" containing a dash manifest file "stream.mpd" and subfolders containing video segments.
# Explanation:
# Validation tool:
# http://dashif.org/conformance.html
# MDN reference:
# https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Setting_up_adaptive_streaming_media_sources
# Add the following mime-types (uncommented) to .htaccess:
# AddType video/mp4 m4s
# AddType application/dash+xml mpd
# Use type="application/dash+xml"
# in html when using mp4 as fallback:
# <video data-dashjs-player loop="true" >
# <source src="/walking/walking.mpd" type="application/dash+xml">
# <source src="/walking/walking.mp4" type="video/mp4">
# </video>
# DASH.js
# https://github.com/Dash-Industry-Forum/dash.js
MYDIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
SAVEDIR=$(pwd)
# Check programs
if [ -z "$(which ffmpeg)" ]; then
echo "Error: ffmpeg is not installed"
exit 1
fi
if [ -z "$(which MP4Box)" ]; then
echo "Error: MP4Box is not installed"
exit 1
fi
cd "$MYDIR"
TARGET_FILES=$(find ./ -maxdepth 1 -type f \( -name "*.mov" -or -name "*.mp4" \))
for f in $TARGET_FILES
do
fe=$(basename "$f") # fullname of the file
f="${fe%.*}" # name without extension
if [ ! -d "${f}" ]; then #if directory does not exist, convert
echo "Converting \"$f\" to multi-bitrate video in MPEG-DASH"
mkdir "${f}"
ffmpeg -y -i "${fe}" -c:a aac -b:a 192k -vn "${f}_audio.m4a"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 22 -maxrate 5000k -bufsize 12000k -pix_fmt yuv420p -f mp4 "${f}_5000.mp4"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -f mp4 "${f}_3000.mp4"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 1500k -bufsize 3000k -pix_fmt yuv420p -f mp4 "${f}_1500.mp4"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 800k -bufsize 2000k -pix_fmt yuv420p -vf "scale=-2:720" -f mp4 "${f}_800.mp4"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 400k -bufsize 1000k -pix_fmt yuv420p -vf "scale=-2:540" -f mp4 "${f}_400.mp4"
# static file for ios and old browsers
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -c:a aac -b:a 160k -c:v libx264 -crf 23 -maxrate 2000k -bufsize 4000k -pix_fmt yuv420p -f mp4 "${f}/${f}.mp4"
rm -f ffmpeg*log*
# if audio stream does not exist, ignore it
if [ -e "${f}_audio.m4a" ]; then
MP4Box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a" -out "${f}/${f}.mpd"
rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a"
else
MP4Box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" -out "${f}/${f}.mpd"
rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4"
fi
# create a jpg for poster. Use imagemagick or just save the frame directly from ffmpeg is you don't have cjpeg installed.
ffmpeg -i "${fe}" -ss 00:00:00 -vframes 1 -qscale:v 10 -n -f image2 - | cjpeg -progressive -quality 75 -outfile "${f}"/"${f}".jpg
fi
done
cd "$SAVEDIR"