This is a method used to distribute videos for iPhone on our own website.
- Note
HTTP Live Streaming(Encrypt)
This is detailed, but I am arranging it because it cannot be played well when encrypted.
iPhone, iPad, iPod – HTTP Live Streaming (HLS) with free tools on Windows
Encoding options are helpful.
- Policy
Original video
↓
mpeg2ts
↓
Splitting
↓
Encryption
↓
Regeneration
- Platform
Ubuntu 12.04
ffmpeg is installed with apt-get.
Split into mpeg2ts [code light="true"] ffmpeg -i ./hoge.3gp -f segment -segment_time 10 -segment_list hoge.m3u8 -segment_format mpegts -vcodec libx264 -vbsf h264_mp4toannexb -flags -global_header - r 30 -s 640x480 -qmax 51 -b 300k -g 150 -qcomp 0.7 -qmin 10 -qdiff 4 -subq 6 -me_range 16 -i_qfactor 0.714286 -acodec libmp3lame -ar 48000 -ab 64k -g 30 hoge%05d.ts [/code]
Highlights
-g Specifies the same value (integer) as the frame rate. This will insert the IDR-Frame at the beginning of each segmented file.
If you don't do this, you won't be able to play normally if you encrypt it. (If you don't encrypt it, you can play it without any problems for some reason.)Encryption Create a key
[code lang="shell" light="true"] #/bin/sh keyFile="key.txt" openssl rand 16 > $keyFile [/code]
Encrypt
crypt.sh
[code lang="shell" light="true"] #/bin/sh hexKey=$(cat $4 | hexdump -e '16/1 "%02x"') hexIV=`printf '%032x' $3` openssl aes-128-cbc -e -in $1 -out $2 -p -nosalt -iv ${hexIV} -K ${hexKey} [/ code] crypt.sh [target file] [output destination] [sequential number] [key]
Highlights
iv If you do not specify the sequential number, the decryption on the iPhone side will not work and it will not play normally.
Create a playlist (m3u8)
[code light="true"] #EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-KEY:METHOD=AES-128,URI="https://[Key Location]" #EXTINF:10, http://[ts File Location] #EXTINF:10, http://[TS File Location\ ] . . #EXT-X-ENDLIST [/code]
20. Rebirth
Apache Configuration
Add to Apache's mime.types
[code light="true"] application/x-mpegURL m3u8 video/MP2T ts [/code]
add to conf [code light="true"] AddType application/x-mpegURL .m3u8 AddType video/MP2T .ts [/code] playback page
video tag
[code lang="html" light="true"] [/code]