Shortly on MPEG-DASH
DASH is a complex hierarchical schema: MPD-file (the manifest file) is divided into periods, each period is divided into adaptation sets, adaptation set is divided in representations and each representation is divided into segments:
How Generate MPEG-DASH with shaka-packager
A single DASH segment is commonly not decodable since SPS/PPS are not present in the meta-data of segments. They are present in a special ‘init’ mp4-file. Even if you extract the video stream from such mp4 segment it would not playable, you need add SPS/PPS.
To extract the video stream form a mp4 segment i suggest to perform the following operations:
1) to concatenate ‘init’ mp4 file with the segment file (e.g. by using Linux command ‘cat’)
2) then to apply ffmpeg to extract video stream with SPS/PPS present. For example:
ffmpeg -i test.mp4 -vcodec copy -vbsf h264_mp4toannexb -f h264 test.h264
Example: How Shaka packager generates MPEG-DASH mp4 segments with the init-file (test_init.mp4):
/packager-linux ‘in=test.ts , stream=video, init_segment=test_init.mp4, segment_template=test_$Number$.mp4’ –profile vod –mpd_output test.mpd –dump_stream_info –min_buffer_time=0.1 –segment_duration=0.5 –strip_parameter_set_nalus=false
As a results test_1.mp4, test_2.mp4, … segments are generated and in addition test_init.mp4 file is also produced (this file test_init.mp4 contains SPS/PPS).
How Assembly All Segments
Shaka Packager produces tons of mp4-segments and it can be required to extract video excerpts from all mp4-segments and to assemble the overall elementary video stream. The following bash-script ExtractVideoSegments.sh extracts all video excerpts and compose them in correct order (consequently the overall elementary video stream is generated):
#!/bin/bash
if (( $#<2 ))then
echo ‘Usage: indir init-mp4 outstream tempfolder (default /.)’ >&2
exit 1
fi
indir=$1
initmp4=$2
outfile=$3
tempdir=${4:-./}
if [ ! -d $indir ]; then
echo $indir is not directory or not exist
exit 1
fi
if [ ! -f $initmp4 ]; then
echo $initmp4 is not exist
exit 1
fi
if [ ! -d $tempdir ]; then
echo $tempdir is not directory or not exist
exit 1
fi
if [ -d $outfile ]; then
echo $outfile is directory
exit 1
fi
if [ -f $outfile ]; then
echo $outfile exist and to be overwritten
rm $outfile
fi
# add ‘/’ to the end folder path if it’s absent
lastSym=”${indir: -1}”
if [[ $lastSym != “/” ]]; then
indir=”${indir}/”
fi
lastSym=”${tempdir: -1}”
if [[ $lastSym != “/” ]]; then
tempdir=”${tempdir}/”
fi
nfiles=0
for mp4file in $( ls ${indir}*.mp4 );
do
bname=$(basename “$mp4file”) # filename without directory path
fname=”${bname%.*}” # filename without extension
lastSym=”${fname: -1}” # files with names not ending numerals are not segments, even if they are segments we can’t sorted
if [[ $lastSym == [0-9] ]]; then
mp4segment=”${tempdir}${fname}.mp4″
h264segment=”${tempdir}${fname}.264″
cat $initmp4 $mp4file > $mp4segment
ffmpeg -loglevel quiet -i $mp4segment -vcodec copy -vbsf h264_mp4toannexb -f h264 -y $h264segment
# get file pattern
if (( nfiles==0 ))
then
filepattern=${fname%_*}
echo “file pattern $filepattern”
fi
rm $mp4segment
let nfiles++
fi
done
echo
echo “total number of segments $nfiles”
echo
cnt=1
touch $outfile # create empty file
while [ $cnt -le $nfiles ]
do
filename=”${tempdir}${filepattern}_${cnt}.264″
if [ ! -f $filename ]; then
echo $filename not exist
exit 2
fi
cat $filename >> $outfile
let cnt++
done
exit 0
Usage of the above script is simple:
indir – the directory where mp4-segments are located. Notice that each segment should have the extension ‘mp4’ and patterned as ‘xxxx_<num>.mp4’ , e.g ‘slava_13.mp4’
init-mp4 – init-mp4 file
outstream – output h264 file
tempfolder – folder where intermediate files are stored
23+ years’ programming and theoretical experience in the computer science fields such as video compression, media streaming and artificial intelligence (co-author of several papers and patents).
the author is looking for new job, my resume
I am not positive the place you’re getting your information, but great topic. I needs to spend a while studying more or figuring out more. Thank you for wonderful info I was searching for this information for my mission.
Awsome post and straight to the point. I don’t know if this is in fact the best place to ask but do you folks have any thoughts on where to hire some professional writers? Thx 🙂
we work for free
F*ckin’ awesome things here. I am very glad to peer your article. Thank you so much and i am having a look forward to contact you. Will you kindly drop me a e-mail?
slavah264@gmail.com
I like what you guys are up also. Such clever work and reporting! Keep up the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my web site 🙂
Everything is very open and very clear explanation of issues. was truly information. Your website is very useful. Thanks for sharing.
I will immediately snatch your rss feed as I can not find your email subscription link or newsletter service. Do you have any? Please let me recognize in order that I could subscribe. Thanks.
on the main page there is Newletter button
I have learn some good stuff here. Certainly worth bookmarking for revisiting. I wonder how so much effort you set to create any such magnificent informative site.
all weekends in last three years
Very excellent visual appeal on this site, I’d value it 10 10.
I will immediately seize your rss as I can’t find your email subscription hyperlink or newsletter service. Do you have any? Kindly permit me know in order that I may subscribe. Thanks.
I always was concerned in this subject and stock still am, thankyou for putting up.
Does your site have a contact page? I’m having problems locating it but, I’d like to send you an email. I’ve got some ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it expand over time.
slavah264@gmail.com
Howdy! Do you use Twitter? I’d like to follow you if that would be ok. I’m undoubtedly enjoying your blog and look forward to new posts.
I’ve been surfing on-line more than three hours lately, but I never discovered any attention-grabbing article like yours. It is lovely worth sufficient for me. In my view, if all web owners and bloggers made good content material as you probably did, the internet might be much more useful than ever before.
Some really interesting points you have written.Helped me a lot, just what I was looking for : D.
I went over this website and I think you have a lot of good info , bookmarked (:.
Keep up the wonderful piece of work, I read few blog posts on this site and I think that your website is very interesting and contains circles of good info .
You are my inspiration , I own few blogs and rarely run out from to post : (.