Вопрос

I'm having an issue with encrypting HLS using openssl. As described here: Using openssl encryption for Apple's HTTP Live Streaming I'm using following script to encrypt TS files created by ffmpeg:

encyptionKeyFile="crypt.key"
openssl rand 16 > $encyptionKeyFile
encryptionKey=`cat $encyptionKeyFile | hexdump -e '16/1 "%02x"'`

splitFilePrefix="$fileName.split."
encryptedSplitFilePrefix="${splitFilePrefix}enc."

numberOfTsFiles=`ls ${splitFilePrefix}*.ts | wc -l`

for i in {0..$numberOfTsFiles}; do
    initializationVector=`printf '%032x' $i`
    openssl aes-128-cbc -e -in ${splitFilePrefix}$i.ts -out ${encryptedSplitFilePrefix}$i.ts -nosalt -iv $initializationVector -K $encryptionKey
    rm ${splitFilePrefix}$i.ts
done


ffmpeg command used to generate TS file is following:

ffmpeg -i $file -codec copy -map 0 -f segment -vbsf h264_mp4toannexb -segment_list $mainPlaylistName -segment_time 10 ${splitFilePrefix}%d.ts


M3U8 playlist file looks like:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-KEY:METHOD=AES-128,URI=crypt.key
#EXT-X-TARGETDURATION:19
#EXTINF:11.875000,
BigBuckBunnyMovie.split.enc.0.ts
#EXTINF:11.166667,
BigBuckBunnyMovie.split.enc.1.ts
#EXTINF:12.500000,
BigBuckBunnyMovie.split.enc.2.ts
#EXTINF:12.166667,
BigBuckBunnyMovie.split.enc.3.ts
#EXTINF:8.375000,
...
#EXT-X-ENDLIST


I thought that it might be a problem with encoding or something with ffmpeg command format but the thing is that encrypted stream doesn't work on native iOS player (MPMoviePlayerController) but works fine on VLC. What is more, unencrypted stream (using TS files produced by ffmpeg) works on both native player and VLC!

Can you suggest me what can I do to be able to play it on native iOS video player?

Thanks for all your responses!

Это было полезно?

Решение

The draft spec states that the URI value is a quoted string. See section 3.4.4 of the draft spec.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top