bentasker / HLS-Stream-Creator

Simple Bash Script to take a media file, segment it and create an M3U8 playlist for serving using HLS
BSD 3-Clause "New" or "Revised" License
273 stars 101 forks source link

Can't play m3u8 #30

Closed ar0ra1 closed 5 years ago

ar0ra1 commented 5 years ago

Just used the basic command to check

./HLS-Stream-Creator.sh -i test_file.mp4 -s 60

I can see the files in the output directory, but I cannot play it on VLC/QuickTime.

Even tried running it on HTML

<video width="100%" controls>
    <source src="test_file.mp4.m3u8" type="application/x-mpegURL">
</video>

It still doesn't work.

Also,
I want to use encryption, since for OSX I had to install using --with-default-names. I get error Error: invalid option: --with-default-names

Running : Mojave, iTerm2, ZSH

ar0ra1 commented 5 years ago

Update :

Got the basic command to work.

Just help me with Error: invalid option: --with-default-names

bentasker commented 5 years ago

Ah, looks like brew have removed the --with-default-names option - https://github.com/Homebrew/homebrew-core/commit/43f2e19d93f04eddf24ec19187b3648f594b80e2

If you run brew install gnu-sed it should also print some output telling you how to make them available with their default names (you can see it in that commit too). Think I preferred the old way, but meh.

I'll raise a task to update the README for modern brew - if you could just confirm that the new way works for you?

ar0ra1 commented 5 years ago

If I install without the option :

brew install gnu-sed
==> Downloading https://homebrew.bintray.com/bottles/gnu-sed-4.7.mojave.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring gnu-sed-4.7.mojave.bottle.2.tar.gz
==> Caveats
GNU "sed" has been installed as "gsed".
If you need to use it as "sed", you can add a "gnubin" directory
to your PATH from your bashrc like:

    PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

&&

brew install grep
==> Downloading https://homebrew.bintray.com/bottles/grep-3.3.mojave.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring grep-3.3.mojave.bottle.2.tar.gz
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"

basically it is installed with a different name

bentasker commented 5 years ago

Yep, that's expected, you now need to follow the steps in the caveat section:

If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"

so vi ~/.bashrc and insert that line. Open a new terminal and you should now get the "correct" grep (if you do echo $PATH you should see the gnubin entry in there).

ar0ra1 commented 5 years ago

Added gnubin to PATH and replaced sed with gsed in the script.

The script was able to generate the key.

Surprisingly, Safari cannot play the encrypted stream now.

Will implement hls.js and update you anyway, even though it doesn't concern your repo directly (Unless it's a key issue)

bentasker commented 5 years ago

You shouldn't have needed to replace sed with gsed, if you look in /usr/local/opt/grep/libexec/gnubin you should (hopefully) see sed and be able to use it directly.

Odd that Safari cannot play, are you getting output to suggest why? Please do let me know how you get on with hls.js.

ar0ra1 commented 5 years ago

I first tried running the script without replacing the sed with gsed, but got this
sed: 1: "./output/test_file.mp4.m3u8": invalid command code .

bentasker commented 5 years ago

Hmmm, that definitely suggests that the wrong sed is being used. If you do echo $PATH | grep gnubin do you get any output? It might be that your bashrc isn't getting loaded, this page suggests OS X is a bit stupid in that regard

bentasker commented 5 years ago

Hi,

Slight change of plans here. Although I wasn't initially keen to have extra checks in there just for the sake of OS X, it does look like there's potential for quite a lot of inconsistency for Mac users (depending on which terminal they use) if they rely on brew's new method of exposing default names.

So, I've written a check into the script so that it'll use ggrep and gsed if they exist. Would you mind pulling the latest revisions and giving it a test run for me? I don't have a Mac available to check with.

bentasker commented 5 years ago

HLS-33 Refers to the changes (or will once the mirror updates later)

ar0ra1 commented 5 years ago

First I thought it was my dumb mistake not to include the PATH in .bashrc but I just checked and and it definitely needs gsed to work and not sed.

I'm gonna pull the latest release and update you!

ar0ra1 commented 5 years ago

Also, just checked the new script.

Dropped back to default BASH, didn't have a .bashrc file so just added the PATH for the current session.

PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
echo $PATH
/usr/local/opt/grep/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin

Ran the script (updated one), works smoothly. Thank You!

PS - I even tried running the script without the PATH and it failed (just the encryption part though).

ar0ra1 commented 5 years ago

@bentasker
Hello, I'm back.. seems like the new script does not work.
It is basically suppressing the sed error, i.e., sed: 1: "./output/dil.mp4.m3u8": invalid command code .

This is my m3u8 file created by the new script.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:101
#EXTINF:100.480000,
dil.mp4_00000.ts
#EXTINF:99.960000,
dil.mp4_00001.ts
#EXTINF:30.640000,
dil.mp4_00002.ts
#EXT-X-ENDLIST

I used the encrypted options -e. But the key meta is missing from the file.
But it did generate a key file. Just the entry for the key file is missing here.

The code at line 280

for manifest in ${OUTPUT_DIRECTORY}/*.m3u8
    do
        # Insert the KEY at the 5'th line in the m3u8 file
        sed -i "5i #EXT-X-KEY:METHOD=AES-128,URI="${KEY_PREFIX}${KEY_NAME}.key "$manifest"
    done

This is not being executed.

bentasker commented 5 years ago

Have you definitely got the newest revision? That should be

for manifest in ${OUTPUT_DIRECTORY}/*.m3u8
do
    # Insert the KEY at the 5'th line in the m3u8 file
    $SED -i "5i #EXT-X-KEY:METHOD=AES-128,URI="${KEY_PREFIX}${KEY_NAME}.key "$manifest"
done

(https://github.com/bentasker/HLS-Stream-Creator/blob/master/HLS-Stream-Creator.sh#L277)

ar0ra1 commented 5 years ago

Yup the newer file. I just copied wrong, was comparing. Didn't look that I copied the old one.

But the code doesn't work. The only way for me to get it to work is to replace sed with gsed in the original script.

bentasker commented 5 years ago

Hmm, can you provide the output of both of these for me?

command -v gsed
command -v sed

I suspect the first will fail when it should not. This is the test the script is using to identify whether gsed is available or not

Thanks for your help on this, I don't have a Mac available to do this on

ar0ra1 commented 5 years ago

Here you go

$ command -v gsed
/usr/local/bin/gsed

$ command -v sed
/usr/bin/sed
bentasker commented 5 years ago

Hmmm, that's odd. I wonder if it doesn't like the ternary operator, could you try pasting the following into a terminal and providing the output (or a screenshot if that's easier for you)

SED='sed'
command -v gsed >/dev/null 2>&1
if [ "$?" == "0" ]
then
SED='gsed'
fi
echo $SED

command -v foobar >/dev/null 2>&1
echo $?

command -v command >/dev/null 2>&1
echo $?

Thanks

ar0ra1 commented 5 years ago

Basically wrapped your code in a script file and ran it.

Tested on both ZSH and BASH (same output for both)

gsed
1
0
bentasker commented 5 years ago

OK, so exit statuses are at least as would be expected.

Could you give the latest revision a try? I've swapped from using ternary's to an explicit if on the exit status of command. If it's not that, then I've obviously missed something somewhere :)

ar0ra1 commented 5 years ago

Recorded : https://youtu.be/UegO2bMzAlg

PS - Recorded this before you made latest changes (swapping ternary -> if)

ar0ra1 commented 5 years ago

Could you give the latest revision a try? I've swapped from using ternary's to an explicit if on the exit status of command. If it's not that, then I've obviously missed something somewhere :)

Just tested this. No luck!

bentasker commented 5 years ago

OK, bear with me, I'm going to have to have a rethink on this one - clearly I'm missing something simple...

ar0ra1 commented 5 years ago

Take your time at least my work is not being held up.

I'm still happy running the original script (replacing sed with gsed).

Also, when I changed sed to gsed, I had to replace it 3 times. If that's what you are missing

ar0ra1 commented 5 years ago

I fixed it!

GREP="grep"
command -v ggrep >/dev/null 2>&1
if [ "$?" == "0" ]
then
    SED="ggrep"
fi

Should be


GREP="grep"
command -v ggrep >/dev/null 2>&1
if [ "$?" == "0" ]
then
    GREP="ggrep"
fi
bentasker commented 5 years ago

OK, this should now be fixed. It was a small idiotic error - https://github.com/bentasker/HLS-Stream-Creator/commit/2114885fc19d3dd80db9cb89c40fbe1b0f4c756f

I've temporarily laid hands on a Mac running Mojave and it's working for me now

bentasker commented 5 years ago

Sorry, I only just noticed your earlier message :) Yep that lines up exactly with my fix. Said it'd be something simple....

Thanks for your help. Im going to mark this fixed.

As I've been through the process now I've also updated the README with install steps for Macs

ar0ra1 commented 5 years ago

@bentasker I had a few questions. Could you spare few minutes?