Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCTE-35 Preroll #26

Closed
BartmanEH opened this issue May 7, 2021 · 55 comments
Closed

SCTE-35 Preroll #26

BartmanEH opened this issue May 7, 2021 · 55 comments
Assignees

Comments

@BartmanEH
Copy link

BartmanEH commented May 7, 2021

I think your side of the conversation in the tsduck thread was deleted. Let's pick it up here.

It will take me some time to get up to speed on installing and using threefive. In the meantime, where do I grab the latest version that you added preroll to?

edit: I see it, it's the 'master' code thread (terrible name, github... come on)

@futzu
Copy link
Owner

futzu commented May 11, 2021

I deleted them. I thought it was kind of rude of me to post my stuff on his repo.
This repo has the preroll stuff in it, you can clone this repo, or
I'll do a release by morning with the preroll stuff added. Then you can just pip install it.

https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py

@BartmanEH
Copy link
Author

Never used pip on my mac, only homebrew. This will take me some time to figure out.

@vladdoster
Copy link
Contributor

vladdoster commented May 12, 2021

The master nomenclature is deprecated. If you create a new repository today it will be called main.

Never used pip on my mac, only homebrew. This will take me some time to figure out.

I'd suggest adding the following python shebang

#!/usr/bin/env python3

Then you can do

# install latest stable python3 release
brew install python@3.9

# if you get a link warning
brew link python@3.9 --force

# finally
python3.9 -m pip install <whatever PyPi pkg you need>
chmod +x preroll.py
python3 preroll.py

@futzu
Copy link
Owner

futzu commented May 12, 2021

I was going to ask Vlad how to do it :))

@BartmanEH
Copy link
Author

BartmanEH commented May 12, 2021

python3.9
Python 3.9.4 (default, Apr  5 2021, 01:50:46) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
python3.9 -m pip install https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
Collecting https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
  Downloading https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
     / 129 kB 2.0 MB/s
  ERROR: Cannot unpack file /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-unpack-7hm83lz0/preroll.py (downloaded from /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-req-build-emltns2t, content-type: text/html; charset=utf-8); cannot detect archive format
ERROR: Cannot determine archive format of /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-req-build-emltns2t
WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the '/usr/local/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip' command.
python3.9 -m pip install --upgrade pip                                                            
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.0.1)
Collecting pip
  Downloading pip-21.1.1-py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 15.9 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.0.1
    Uninstalling pip-21.0.1:
      Successfully uninstalled pip-21.0.1
Successfully installed pip-21.1.1
python3.9 -m pip install https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
Collecting https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
  Downloading https://github.com/futzu/threefive/blob/master/examples/stream/preroll.py
     | 129 kB 1.8 MB/s
  ERROR: Cannot unpack file /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-unpack-_p6lsl_w/preroll.py (downloaded from /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-req-build-1not7dec, content-type: text/html; charset=utf-8); cannot detect archive format
ERROR: Cannot determine archive format of /private/var/folders/ty/vzb3w1655dx8jf08sg83nfpm0000gp/T/pip-req-build-1not7dec

I have no idea what I'm doing but clearly I should not be trying to install the linked python script using pip.

This stuff is insanely hard for the uninitiated. I tried to install pypy3 so I went to https://www.pypy.org/download.html#. First you have to figure out that PyPy3.7 is probably PyPy3 despite being under the heading "PyPy v7.3.4" so I'm already not confident that I'm in the right spot. Downloading PyPy3.7 for macOS puts a tarball in my Downloads folder. In what way is that a download and install per the page heading "Download and Install"?

Edit: a little Google searching revealed that pypy3 can be installed with brew so I'm doing that now. Why don't they say that on the pypy 'install' webpage?

Edit2: pypy3 installed:

pypy3
Python 3.7.10 (51efa818fd9b24f625078c65e8e2f6a5ac24d572, Apr 08 2021, 17:43:00)
[PyPy 7.3.4 with GCC Apple LLVM 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> exit()

Now I think I need to clone the threefive git?

@BartmanEH
Copy link
Author

I cloned the threefive git and 'make install' worked but 'make pypy3' doesn't:

>make pypy3
rm -f dist/*
rm -rf build/*
pypy3 setup.py sdist bdist_wheel
/usr/local/Cellar/pypy3/7.3.4/libexec/site-packages/setuptools-54.2.0-py3.7.egg/setuptools/dist.py:645: UserWarning: Usage of dash-separated 'install-scripts' will not be supported in future versions. Please use the underscore name 'install_scripts' instead
  % (opt, underscore_opt))
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'
make: *** [pypy3] Error 1

@futzu
Copy link
Owner

futzu commented May 12, 2021

Pip is the way to go

Do this as root.

pypy3 -mpip install threefive

https://github.com/futzu/threefive#install

I don't mean to discourage your efforts,
however, threefive is a python library,
if you aren't comfortable python,
threefive may not be the best tool for you.

@BartmanEH
Copy link
Author

BartmanEH commented May 12, 2021

i deleted my cloned git and ran pypy3 -mpip install threefive but now have no idea where threefive is installed:

pypy3 -mpip install threefive
Collecting threefive
  Downloading threefive-2.2.87-py3-none-any.whl (19 kB)
Installing collected packages: threefive
Successfully installed threefive-2.2.87

Indeed I'm not comfortable with python or macOS command line at all but the Venn diagram intersection between broadcast engineers who know something about SCTE-35 and software engineers who know something about python and command line must be incredibly small.

@futzu
Copy link
Owner

futzu commented May 12, 2021

You don't need to know where it's installed actually :)
Since you already have the git repo,
cd to the threefive/examples/stream directory
and run:

pypy3 preroll.py  your_vid.ts

@futzu
Copy link
Owner

futzu commented May 12, 2021

Screenshot_2021-05-12_16-48-03

@BartmanEH
Copy link
Author

BartmanEH commented May 12, 2021

no, I deleted the git clone and installed via pip with pypy3 -mpip install threefive. I don't have a threefive folder and have been unable to locate or find anything related such as preroll.py. Whatever Successfully installed threefive-2.2.87 means, it doesn't mean there's a threefive folder I can cd into.

@futzu
Copy link
Owner

futzu commented May 12, 2021

@futzu
Copy link
Owner

futzu commented May 14, 2021

Did you get it running?
You don't need to be in the threefive directory to run it.

just download preroll.py , I use curl.

curl https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py -o preroll.py
  • output from curl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2556  100  2556    0     0   8088      0 --:--:-- --:--:-- --:--:--  8114
  • Run the script
pypy3 preroll.py myvideo.ts 
  • output
next file: myvideo.ts
Program: 1050   Splice Insert @ 21940.656778    Splice Time: 21951.133267       Preroll: 10.476489
Program: 1050   Splice Insert @ 21942.672778    Splice Time: 21951.133267       Preroll: 8.460489
Program: 1050   Splice Insert @ 21944.688778    Splice Time: 21951.133267       Preroll: 6.444489
Program: 1010   Splice Insert @ 22508.436511    Splice Time: 22516.907656       Preroll: 8.471145
Program: 1010   Splice Insert @ 22510.452511    Splice Time: 22516.907656       Preroll: 6.455145
Program: 1050   Splice Insert @ 22015.680778    Splice Time: 22026.133267       Preroll: 10.452489
Program: 1050   Splice Insert @ 22017.696778    Splice Time: 22026.133267       Preroll: 8.436489
Program: 1050   Splice Insert @ 22019.712778    Splice Time: 22026.133267       Preroll: 6.420489
Program: 1040   Splice Insert @ 22857.8786      Splice Time: 22864.350067       Preroll: 6.471467
Program: 1040   Splice Insert @ 22863.9266      Splice Time: 22870.350067       Preroll: 6.423467
Program: 1010   Splice Insert @ 22688.436511    Splice Time: 22696.907656       Preroll: 8.471145
Program: 1010   Splice Insert @ 22690.452511    Splice Time: 22696.907656       Preroll: 6.455145
Program: 1040   Splice Insert @ 22953.9266      Splice Time: 22960.350067       Preroll: 6.423467
Program: 1010   Splice Insert @ 23508.372511    Splice Time: 23516.827656       Preroll: 8.455145
Program: 1010   Splice Insert @ 23510.388511    Splice Time: 23516.827656       Preroll: 6.439145
Program: 1010   Splice Insert @ 23688.372511    Splice Time: 23696.827656       Preroll: 8.455145
Program: 1010   Splice Insert @ 23690.388511    Splice Time: 23696.827656       Preroll: 6.439145
Program: 1030   Splice Insert @ 23676.9783      Splice Time: 23683.480033       Preroll: 6.501733

@vladdoster
Copy link
Contributor

vladdoster commented May 15, 2021

  1. Create a file called get-deps.sh
  2. Copy and paste the following script
#!/usr/bin/env bash

echo "--- Checking for Python 3"
if command -V python3; then
    echo "--- Python 3 is available"
else
    echo "--- Install Python 3!"
fi

echo "--- Installing threefive"
python3 -m pip install --user threefive

echo "--- Downloading pre-roll.py"
curl \
    --url https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py \
    --output preroll.py

echo "--- Adding Python3 shebang"
sed -i '1s/^/#!/usr/bin/env python3\n/' pre-roll.py
  1. In a terminal where you created the script, run
chmod +x get-deps.sh
  1. Next, run
./get-deps.sh
  1. Now, you should be able to run the following with no issues
python3 preroll.py VIDEO_FILE.ts

@BartmanEH
Copy link
Author

Ok, the curl command snagged preroll.py and I was able to run it. Results are a bit different than what I'm looking for and more along the lines of tsduck (maybe due to the same limitations of processing in realtime rather than with the multi-pass benefit of offline?):

Program: 600	Splice Insert @ 18728.588444 	Splice Time: 18734.293011	Preroll: 5.704567
Program: 600	Splice Insert @ 18729.164444 	Splice Time: 18734.293011	Preroll: 5.128567

DVB Inspector and Sencore Compressed Stream Analyzer:
splice_time (preroll time = 5.810 secs)
splice_time (preroll time = 5.272 secs)

@BartmanEH
Copy link
Author

BartmanEH commented May 17, 2021

python3 -m pip install --user threefive

python3 -m pip install --user threefive
Requirement already satisfied: threefive in /usr/local/lib/python3.9/site-packages/threefive-2.2.88-py3.9.egg (2.2.88)

so that didn't work.
One of my pip commands worked and dropped threefive into a pypy3 folder:
image
...but that folder doesn't have preroll.py

I suspect I have a mess: a slew of folders from multiple attempts to install threefive

@vladdoster
Copy link
Contributor

vladdoster commented May 17, 2021

You don't need to mess with site packages. It is imported in the pre-roll.py file and Python will take care of all that behind the scenes.

If it is already installed then you can just move on to the next step of the process I outlined.

The only thing that I see that needs to be added to pre-roll.py is the shebang.

Add the following line to the first line of the pre-roll.py:

#!/usr/bin/env python3

@BartmanEH
Copy link
Author

thank you @vladdoster, both commands do work indeed:

% pypy3 preroll.py <path to file>.ts 
next file: <path to file>.ts
Program: 600	Splice Insert @ 18728.588444 	Splice Time: 18734.293011	Preroll: 5.704567
Program: 600	Splice Insert @ 18729.164444 	Splice Time: 18734.293011	Preroll: 5.128567
% python3 preroll.py <path to file>.ts 
next file: <path to file>.ts
Program: 600	Splice Insert @ 18728.588444 	Splice Time: 18734.293011	Preroll: 5.704567
Program: 600	Splice Insert @ 18729.164444 	Splice Time: 18734.293011	Preroll: 5.128567

@vladdoster
Copy link
Contributor

Happy to help 😃 .

@BartmanEH

@futzu
Copy link
Owner

futzu commented May 18, 2021

Ok, the curl command snagged preroll.py and I was able to run it. Results are a bit different than what I'm looking for and more along the lines of tsduck (maybe due to the same limitations of processing in realtime rather than with the multi-pass benefit of offline?):

Program: 600	Splice Insert @ 18728.588444 	Splice Time: 18734.293011	Preroll: 5.704567
Program: 600	Splice Insert @ 18729.164444 	Splice Time: 18734.293011	Preroll: 5.128567

DVB Inspector and Sencore Compressed Stream Analyzer:
splice_time (preroll time = 5.810 secs)
splice_time (preroll time = 5.272 secs)

That's the beauty of threefive, it can include whatever you like.
Do you want it more like DVB inspector?
Show me what you want the output to look like.

@futzu
Copy link
Owner

futzu commented May 18, 2021

Here's one that matches DVB inspector's output.

https://github.com/futzu/threefive/blob/master/examples/stream/preroll2.py

pypy3 preroll2.py plp0.ts 
21951.133267(preroll time = 10.476489)
21951.133267(preroll time = 8.460489)
21951.133267(preroll time = 6.444489)
22516.907656(preroll time = 8.471145)
22516.907656(preroll time = 6.455145)
22026.133267(preroll time = 10.452489)
22026.133267(preroll time = 8.436489)
22026.133267(preroll time = 6.420489)
22864.350067(preroll time = 6.471467)
22870.350067(preroll time = 6.423467)
22696.907656(preroll time = 8.471145)
22696.907656(preroll time = 6.455145)
22960.350067(preroll time = 6.423467)
23516.827656(preroll time = 8.455145)
23516.827656(preroll time = 6.439145)
23696.827656(preroll time = 8.455145)
23696.827656(preroll time = 6.439145)
23683.480033(preroll time = 6.501733)

@futzu
Copy link
Owner

futzu commented May 18, 2021

vlad ,

try

sed -i '1i\#\!/usr/bin/env python3\n\n' preroll.py

@BartmanEH
Copy link
Author

BartmanEH commented May 18, 2021

Show me what you want the output to look like.

I'm referring to the values, not the formatting. The whole thread I started on tsduck was about the values computed for preroll. The gold standard is the offline processing by Sencore Compressed Media analyzer (CMA). The author of DVB Inspector added preroll at my request and his computation agrees with Sencore CMA. Author of tsduck added splicemonitor plugin at my request but the computed results for preroll differ from Sencore CMA. Your results also differ.

Here's the original thread on tsduck and here's the original thread on DVB Inspector. In these threads are examples and screenshots of the different values computed for preroll by the different tools.

@futzu
Copy link
Owner

futzu commented May 18, 2021

How much do they differ?
I use only PTS because that's what SCTE-35 uses and, I often find PCR times that differ greatly from PTS
because the video has been transcoded.

Using PCR will be different because PCR is 33 bit + 9 bit extension
PTS is 33 bit.

SCTE-35 specifies time in PTS, so I use PTS not PCR.

@BartmanEH
Copy link
Author

I cited an example:
preroll.py:
Program: 600 Splice Insert @ 18728.588444 Splice Time: 18734.293011 Preroll: 5.704567
Program: 600 Splice Insert @ 18729.164444 Splice Time: 18734.293011 Preroll: 5.128567
DVB Inspector and Sencore Compressed Stream Analyzer:
splice_time (preroll time = 5.810 secs)
splice_time (preroll time = 5.272 secs)
these results are from the same ts sample.

SCTE-35 specifies time using PTS indeed, however, there is no PTS associated with the actual SCTE-35 command packets--they free run on their own with no associated PTS.

@futzu
Copy link
Owner

futzu commented May 18, 2021

I see your point. Let me try using PCR and see what I get.

@futzu
Copy link
Owner

futzu commented May 18, 2021

Run this and see what what you get.
download it here:
preroll3.txt
then run it

python3 preroll3.txt  vid.ts

@BartmanEH
Copy link
Author

 % python3 preroll3.txt <path_to_file>.ts 
next file:<path_to_file>.ts
Program: 600	Splice Insert @ 18728.461719 	Splice Time: 18734.293011	Preroll: 5.831292
Program: 600	Splice Insert @ 18729.018911 	Splice Time: 18734.293011	Preroll: 5.2741

so that's much closer to the gold standard results:
DVB Inspector and Sencore Compressed Stream Analyzer:
splice_time (preroll time = 5.810 secs)
splice_time (preroll time = 5.272 secs)

I can definitely work with that. How robust is this new calculation? Are you counting packets from last PTS to the SCTE-35 command packet and using bitrate to calculate the time to the SCTE-35 command packet? That's what the others do.

@futzu
Copy link
Owner

futzu commented May 18, 2021

This is just a quick hack to see if I can do it.
This is "closest PCR" instead of closest "PTS"
for the SCTE-35 packet .

preroll = (SCTE-35.command.pts_time) - (closest PCR time to the SCTE-35 packet)

If you think about it though,
using PTS is really the safer method,
since it consistently shows smaller preroll times
and the specification says at least 4 seconds prior.

I bet a lot of people use PCR ,
and I bet a lot of People use PTS.

Which is the proper method is not really clear.

@BartmanEH
Copy link
Author

You can extrapolate the PTS. Start with closest PTS then add the time it takes for the number of packets between last PTS and the SCTE-35 packet. The time is the (# of packets X bits/packet) / bitrate.

@BartmanEH
Copy link
Author

BartmanEH commented May 19, 2021

$time python3 preroll4.txt sample.ts
next file: sample.ts
 Splice Time: 18734.293011 Preroll: (PCR): 5.831292 (PTS): 5.704567
 Splice Time: 18734.293011 Preroll: (PCR): 5.2741 (PTS): 5.128567
python3 preroll4.txt sample.ts  4.75s user 0.21s system 98% cpu 5.019 total
$time pypy3 preroll4.txt sample.ts                                                                                                          
next file: sample.ts
 Splice Time: 18734.293011 Preroll: (PCR): 5.831292 (PTS): 5.704567
 Splice Time: 18734.293011 Preroll: (PCR): 5.2741 (PTS): 5.128567
pypy3 preroll4.txt sample.ts  1.41s user 0.20s system 95% cpu 1.689 total

First of all, I started using pypy3--it is WAY faster as you noted... somewhere... :-)

I still think if you could add (# of packets X bits/packet) / bitrate to the last PTS packet, it would be the closest most reliable value. Do you know/calculate bitrate?

@futzu
Copy link
Owner

futzu commented May 19, 2021

Thank you for trying pypy3,
nobody believes me when I tell them it's three times faster.
It's especially fast at bit wise operations.... like parsing video data.

Firstly, you're assuming they are doing it correctly.
honestly, I think PTS is the time intended to be used,
but I don't know for sure.

The PCR Preroll is ~0.02 higher on the first Splice time
and ~0.002 higher on the second Splice.

0.021292000000000755

0.0020999999999995467

I've been working in broadcasting for some time,
and ads aren't spliced in at millisecond accuracy,
that's why God invented all black frames. :)

@BartmanEH
Copy link
Author

BartmanEH commented May 19, 2021

We are doing frame accurate splicing. In conjunction with the encoder providing an I-Frame at the exact PTS time, we do frame-accurate SCTE-35 splicing out and back in to the live stream: Edgecaster Pro frame-accurate ad insertion news and Edgecaster Pro product

Notwithstanding that, I agree that I do not need any more accuracy on the preroll calculation. As you say, the SCTE standard requires simply a minimum of 4 seconds for preroll timing.

Believe you me... it took me months to get a customer to get this right which is what precipitated my need for a free tool to analyze the preroll timing.

Thanks for your efforts!

@futzu
Copy link
Owner

futzu commented May 19, 2021

You're very welcome.
I really appreciate the input, seriously.

Give me a day or two, and I'll have a new release with the PCR and PTS baked in.

@futzu
Copy link
Owner

futzu commented May 19, 2021

One idea I had was to
work off the PCR, they should be every 100ms,
but if I calculated the number of packets between PCRs
and where the SCTE-35 packet is in relation,
that could be millisecond accurate or better.

I'll keep thinking about it.

@BartmanEH
Copy link
Author

Ultimately the tool, as you have it now, really meets the fundamental purposes of preroll analysis. Thanks again.

@futzu
Copy link
Owner

futzu commented May 19, 2021

Could I get a copy of your test video,
so I can have something to benchmark against?

I have servers you can upload it to if needed.

@BartmanEH
Copy link
Author

sure, for your personal use only. not sure how to DM server credentials...

@futzu
Copy link
Owner

futzu commented May 20, 2021

I'm calculating pre-roll as the difference between when a SCTE-35 packet is seen and the splice PTS time.
Using PCR is more accurate, simply because it's updated more often.

I think pre-roll is more better defined as the difference between the PCR of the SCTE-35 packet and the PCR of the actual splice point, not the Splice Insert PTS specified in the Cue message.

As you mentioned earlier,
this can be harder to predict with real time processing.

The real-time calculation is more a function of the rules imposed by the splicer.

  • Does it insert I-frames?
  • Does it only splice on I-frames
  • Will the splicer splice before the Splice Insert PTS time?
  • etc....

6.1.4.2 Frame Accuracy

Frame accuracy describes whether the transition between sequences occurs at exactly the frame specified. Assuming that a given splicer can be commanded to splice at an exact frame, the issue is whether the splicer can perform the splice at exactly the
desired point. As discussed in prior sections, splicers will typically place some restrictions on the types of frames that can be used for in-points and out-points. Hence, when discussing the frame accuracy of a splicer,
it is important that the condition under which the accuracy is to be determined is specified.

For example,

almost any splicer can be frame accurate when commanded to splice at pre-conditioned Splice Points, whereas only splicers that can produce I-frames on demand can be frame accurate when commanded to splice in a situation where neither the in-point or out-point are anchor frames.

Other splicers can be frame accurate when commanded to splice where the out-point is an anchor frame and the in-point is an I-frame. Unfortunately, there are different views among the manufacturers regarding what constitutes “frame accurate”. Therefore it is important to articulate what the range of possible circumstances is and how the Splice Point might be adjusted in these circumstances.**

@futzu
Copy link
Owner

futzu commented May 20, 2021

1. Create a file called `get-deps.sh`

2. Copy and paste the following script
#!/usr/bin/env bash

echo "--- Checking for Python 3"
if command -V python3; then
    echo "--- Python 3 is available"
else
    echo "--- Install Python 3!"
fi

echo "--- Installing threefive"
python3 -m pip install --user threefive

echo "--- Downloading pre-roll.py"
curl \
    --url https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py \
    --output preroll.py

echo "--- Adding Python3 shebang"
sed -i '1s/^/#!/usr/bin/env python3\n/' pre-roll.py

try it this way.

#!/bin/sh

target=python3
url="https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py"
filename=$(basename "$url")
py3="which ${target}"

if $py3;then
   printf "Installing threefive\n"
   `${py3}` -m pip install --upgrade  threefive
    
    #  add shebang
    printf "#!`${py3}`\n\n" > $filename
        
    printf " Downloading $filename\n"
    curl -s --url $url >> $filename
    
    printf " making $filename executable"
    chmod +x $filename 

else
        printf  "\ntarget ${target} not found\n"
fi

@futzu
Copy link
Owner

futzu commented May 20, 2021

We are doing frame accurate splicing. In conjunction with the encoder providing an I-Frame at the exact PTS time, we do frame-accurate SCTE-35 splicing out and back in to the live stream: Edgecaster Pro frame-accurate ad insertion news and Edgecaster Pro product

Notwithstanding that, I agree that I do not need any more accuracy on the preroll calculation. As you say, the SCTE standard requires simply a minimum of 4 seconds for preroll timing.

Believe you me... it took me months to get a customer to get this right which is what precipitated my need for a free tool to analyze the preroll timing.

Thanks for your efforts!

Now I can't stop thinking about it........
I found part of the difference.
I was rounding PCR and then rounding the preroll .
If I remove the rounding it gets closer.
I have a few more ideas I want to try ,

I am reopening this.

@futzu futzu reopened this May 20, 2021
@futzu
Copy link
Owner

futzu commented May 22, 2021

Testing threefive with ffmpeg.

threefive is __ 0.0074079999999999__ higher than ffmpeg for the packet time,
ffmpeg shows the Splice Insert I-frame at the same time as threefive parses from the data.


SCTE-35 Packet


ffmpeg

[PACKET] pts_time = 38199.918911

threefive

Cue.packet_data['pcr'] = 38199.926319


SCTE-35 Splice Insert


ffmpeg

[FRAME

media_type=video

stream_index=0

key_frame=1

pkt_pts_time = 38203.125478

### threefive

"name": "Splice Insert",

"time_specified_flag": true,

"pts_time" = 38203.125478

@futzu futzu closed this as completed May 23, 2021
@futzu
Copy link
Owner

futzu commented May 27, 2021

I believe I have it accurate now.

ffmpeg

    [PACKET] pts_time = 38199.918911

threefive

    Cue.packet_data["pcr"] =  38199.918911

@futzu futzu reopened this May 27, 2021
@futzu
Copy link
Owner

futzu commented May 27, 2021

Here's the commit.
b9bb14d

@futzu
Copy link
Owner

futzu commented May 27, 2021

https://github.com/futzu/threefive/releases/tag/v.2.2.89
there is the release

pypy3 -m pip install --upgrade threefive 

@BartmanEH
Copy link
Author

OK, you've gotten way ahead of me. I've run pypy3 -m pip install --upgrade threefive and I have a folder buried way down here:
Screen Shot 2021-05-27 at 7 46 34 AM
and version.py has contents including version_tuple = "2.2.89" so the pip upgrade worked.

  1. I don't see preroll.py in this folder. Have you rolled the preroll function into another py file?
  2. How do I run any of these .py scripts? Do I have to preface every .py command with the whole gory pypy3 installation folder path? None of the pypy3 threefive .py files are found in my terminal command path:
$pypy3 version.py                                                              
/usr/local/bin/pypy3: can't open file version.py: [Errno 2] No such file or directory
$/usr/local/Cellar/pypy3/7.3.4/libexec/site-packages/threefive/version.py      
zsh: permission denied: /usr/local/Cellar/pypy3/7.3.4/libexec/site-packages/threefive/version.py
$pypy3 /usr/local/Cellar/pypy3/7.3.4/libexec/site-packages/threefive/version.py

@futzu
Copy link
Owner

futzu commented May 28, 2021

You really have to know python to use threefive.

@BartmanEH
Copy link
Author

OK, I made it abundantly clear at the beginning that I do not know python. In any event, I ran the script you posted above:

#!/bin/sh

target=python3
url="https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py"
filename=$(basename "$url")
py3="which ${target}"

if $py3;then
   printf "Installing threefive\n"
   `${py3}` -m pip install --upgrade  threefive
    
    #  add shebang
    printf "#!`${py3}`\n\n" > $filename
        
    printf " Downloading $filename\n"
    curl -s --url $url >> $filename
    
    printf " making $filename executable"
    chmod +x $filename 

else
        printf  "\ntarget ${target} not found\n"
fi

that seems to have (re)upgraded threefive and grabbed the example script preroll.py.

Is there a typo in @vladdoster's original script?

#!/usr/bin/env bash

echo "--- Checking for Python 3"
if command -V python3; then
    echo "--- Python 3 is available"
else
    echo "--- Install Python 3!"
fi

echo "--- Installing threefive"
python3 -m pip install --user threefive

echo "--- Downloading pre-roll.py"
curl \
    --url https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py \
    --output preroll.py

echo "--- Adding Python3 shebang"
sed -i '1s/^/#!/usr/bin/env python3\n/' pre-roll.py

where the last line should be sed -i '1s/^/#!/usr/bin/env python3\n/' preroll.py?

@vladdoster
Copy link
Contributor

vladdoster commented May 28, 2021

lol, good catch. I didn't escape the forward slashes.

Try this:

#!/usr/bin/env bash

echo "--- Checking for Python 3"
if command -V python3; then
    echo "--- Python 3 is available"
else
    echo "--- Install Python 3!"
fi

echo "--- Installing threefive"
python3 -m pip install --user threefive

echo "--- Downloading pre-roll.py"
curl \
    --url https://raw.githubusercontent.com/futzu/threefive/master/examples/stream/preroll.py \
    --output pre-roll.py

echo "--- Adding Python3 shebang"
sed -i '1s/^/#!\/usr\/bin\/env python3\n/' pre-roll.py

echo "--- Adding executable bit to pre-roll.py"
chmod +x pre-roll.py

@BartmanEH
Copy link
Author

Nice. NOW I know python :-)

of course I'm kidding: I know there's a lot more to threefive that can be done by creating comprehensive python scripts and importing threefive as a library. It's just not where I am. I need simple tools to measure preroll and I have a plethora now including the sample script preroll.py so thanks!

@futzu
Copy link
Owner

futzu commented Jun 2, 2021

Check https://github.com/futzu/scte35 in a couple weeks.
I'm making it into a executable, it will be easier for you to use.

@futzu
Copy link
Owner

futzu commented Jun 7, 2021

@BartmanEH ,
do you know that DTMF Descriptors include a preroll variable?

preroll – This 8-bit number is the time the DTMF is presented to the analog output of the device in tenths of seconds. This gives a pre-roll range of 0 to 25.5 seconds. The splice info section shall be sent at least two seconds earlier then this value. The minimum suggested pre-roll is 4.0 seconds.

Here's a Splice Insert with a DTMF Descriptor.

{
    "info_section": {
        "table_id": "0xfc",
        "section_syntax_indicator": false,
        "private": false,
        "sap_type": "0x3",
        "sap_details": "No Sap Type",
        "section_length": 44,
        "protocol_version": 0,
        "encrypted_packet": false,
        "encryption_algorithm": 0,
        "pts_adjustment": 0.0,
        "cw_index": "0x0",
        "tier": "0xfff",
        "splice_command_length": 15,
        "splice_command_type": 5,
        "descriptor_loop_length": 12
    },
    "command": {
        "calculated_length": 15,
        "name": "Splice Insert",
        "time_specified_flag": true,
        "pts_time": 38203.125478,
        "splice_event_id": 94,
        "splice_event_cancel_indicator": false,
        "out_of_network_indicator": false,
        "program_splice_flag": true,
        "duration_flag": false,
        "splice_immediate_flag": false,
        "unique_program_id": 0,
        "avail_num": 0,
        "avail_expected": 0
    },
    "descriptors": [
        {
            "tag": 1,
            "descriptor_length": 10,

            "name": "DTMF Descriptor",
            "identifier": "CUEI",
----------------------------------------
|            "preroll": 177,             |
----------------------------------------

            "dtmf_chars": [
                "1",
                "2",
                "1",
                "#"
            ]
        }

@BartmanEH
Copy link
Author

I did not know that but then, our solution is purely digital working with SCTE-104/35 Splice In commands only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants