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

PIPE to FFMPEG? #162

Open
dromicron opened this issue Apr 19, 2023 · 48 comments
Open

PIPE to FFMPEG? #162

dromicron opened this issue Apr 19, 2023 · 48 comments
Labels
enhancement New feature or request

Comments

@dromicron
Copy link

hi, i try to use pipe function but i only get .TS file
it is possible to pipe to ffmpeg to make live hls output?

@nilaoda nilaoda added the enhancement New feature or request label Apr 19, 2023
@atuctuc
Copy link

atuctuc commented Apr 19, 2023

yes, i would also appreciate it if it could redirect the output to a unix pipe!!

nilaoda added a commit that referenced this issue Jun 14, 2023
@edgar017
Copy link

@nilaoda how to use live pipe options?

@nilaoda
Copy link
Owner

nilaoda commented Jun 15, 2023

@nilaoda how to use live pipe options?

For example:

set RE_LIVE_PIPE_OPTIONS="-c copy -f flv rtmp://your-streaming-server-url/your-stream-key"

N_m3u8DL-RE.exe --live-real-time-merge --live-pipe-mux "http://path/to/a.mpd"

This will change the command line used for mixing streams and output it to the server you specify. You can also output it as HLS segments by set specific value of RE_LIVE_PIPE_OPTIONS.

On Linux, If you only want it to take effect on a specific command line:

RE_LIVE_PIPE_OPTIONS="..." ./N_m3u8DL-RE ...

@edgar017
Copy link

@nilaoda Very thanks!

@Shporterator
Copy link

Shporterator commented Jun 18, 2023

I noticed that in this mode, temporary files are not deleted after completion. The folder remains
The command looks like this. Maybe I did something wrong?

RE_LIVE_PIPE_OPTIONS="-c copy -f mpegts pipe:1" /home/N_m3u8DL-RE --log-level off --tmp-dir /tmp --no-log --ffmpeg-binary-path /home/ffmpeg --decryption-binary-path /home/mp4decrypt --key 0:0 "$URL" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" --del-after-done true --mp4-real-time-decryption true --live-keep-segments false --live-real-time-merge true --live-pipe-mux true --thread-count 3 -sv best -sa all

And I also noticed that errors in the image periodically freezes if you use this method. I can't figure out what this is related to yet. I tried different versions of ffmpeg, the result is the same

@liimee
Copy link

liimee commented Jun 27, 2023

I noticed that in this mode, temporary files are not deleted after completion.

@Shporterator have you figured this out? noticed this too

@Shporterator
Copy link

have you figured this out?

No.
Do you have any problems with the video when using this method?

@liimee
Copy link

liimee commented Jun 27, 2023

And I also noticed that errors in the image periodically freezes if you use this method.

what do you mean by periodically freezes? the stream/pipe stops?

@Shporterator
Copy link

what do you mean by periodically freezes? the stream/pipe stops?

During the loading of new fragments, the image stops for a few seconds, the sound continues to work normally.

@liimee
Copy link

liimee commented Jun 27, 2023

I think that happens to me too... the video fragment loads way slower (pauses for a moment) than the audio

@nilaoda
Copy link
Owner

nilaoda commented Jun 27, 2023

You can try set a smaller value for --live-wait-time

@Shporterator
Copy link

You can try set a smaller value for --live-wait-time

Problem remains

@nilaoda
Copy link
Owner

nilaoda commented Jun 28, 2023

@Shporterator Then there's nothing I can do. 🫠

@Shporterator
Copy link

Then there's nothing I can do.

Very sad

@Shporterator
Copy link

Then there's nothing I can do.

This problem is absolutely with any streams, which makes this new feature useless:(

@andremxmx
Copy link

Then there's nothing I can do.

This problem is absolutely with any streams, which makes this new feature useless:(

Yep i have the same problem, fo now just do this, maybe you do the same as me for now

N_m3u8DL-RE.exe
--save-dir stream
--del-after-done true
--save-name tNoticias
--tmp-dir temp
"url"
--live-real-time-merge true
--live-wait-time 5
--mp4-real-time-decryption true
--live-pipe-mux
-sv best
-sa all
--key xxxxxxxxxx:xxxxxxxxx
--use-system-proxy true
--custom-proxy http://xxx.xxxx.xxx.xxx:3128

FFMPEG

ffmpeg.exe
-re
-i stream/tNoticias.ts
-c copy -f hls
-hls_time 5
-hls_list_size 4
-hls_flags delete_segments
C:/wamp64/www/bin/m3u8/tNoticias.m3u8

@Shporterator
Copy link

Yep i have the same problem, fo now just do this, maybe you do the same as me for now

How can I contact you?

@andremxmx
Copy link

Telegram: @cursoryapp_uy

Yep i have the same problem, fo now just do this, maybe you do the same as me for now

How can I contact you?

@andremxmx
Copy link

Now working grate no jittler or audio loss or stuck, perfect!! thanks!

@alphalneo
Copy link

alphalneo commented Oct 7, 2023

To me the problem seems to be the output
Vid 1920x1080 | 5499 Kbps | 50 00m38s/00m55s 16/23 Recording 69% 0.00Bps(1) ⣟
Aud 129 Kbps | ita | 2CH 00m38s/00m55s 16/23 Recording 69% 0.00Bps(1) ⣯
Can we suppress easily?

Edited: Yes I confirmed, I changed pipe:1 to pipe:2 I sent the stdout to dev null and finally I resent stderr to stdout and evrything is working!!! Therefore is the contamination of the std out that create the problem

@michaelarnauts
Copy link

To me the problem seems to be the output Vid 1920x1080 | 5499 Kbps | 50 00m38s/00m55s 16/23 Recording 69% 0.00Bps(1) ⣟ Aud 129 Kbps | ita | 2CH 00m38s/00m55s 16/23 Recording 69% 0.00Bps(1) ⣯ Can we suppress easily?

Edited: Yes I confirmed, I changed pipe:1 to pipe:2 I sent the stdout to dev null and finally I resent stderr to stdout and evrything is working!!! Therefore is the contamination of the std out that create the problem

Could you share the full command that you used to make this work?

@alphalneo
Copy link

alphalneo commented Oct 12, 2023

Sure, I am using linux

RE_LIVE_PIPE_OPTIONS="-c copy -f mpegts pipe:2" /MYPATH/N_m3u8DL-RE --log-level off --no-date-info --no-log True THEURLOFYOURSTREAM --del-after-done true --mp4-real-time-decryption true --live-keep-segments false --live-real-time-merge true --live-pipe-mux true --thread-count 3 -sv best -sa all --concurrent-download --save-dir pippo_FOLDER 2>&1 >/dev/null

The output is N_m3u8DL-RE is done on STDERR, I am sending the SDTOUT to a devnull and I am sending the STDERR to STDOUT

@alphalneo
Copy link

Waiting for a solution, for now I solved in this way
modify this line
var progress = AnsiConsole.Progress().AutoClear(true);
which you can find in 3 files
with this
var progress = AnsiConsole.Progress().AutoClear(true).AutoRefresh( DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF );

nilaoda added a commit that referenced this issue Oct 14, 2023
@alphalneo
Copy link

Thank you!

@JohnTrabusca
Copy link

@nilaoda is it possible to change the pipe file location (RE_pipe_dc3a37d4-9ef7-482f-975a-e6a6fa6579bf) to another folder instead of /tmp ?

@nilaoda
Copy link
Owner

nilaoda commented Nov 13, 2023

@nilaoda is it possible to change the pipe file location (RE_pipe_dc3a37d4-9ef7-482f-975a-e6a6fa6579bf) to another folder instead of /tmp ?

Latest Actions version supported RE_LIVE_PIPE_TMP_DIR environment var.

@JohnTrabusca
Copy link

@nilaoda It still creates to the default /tmp after setting the new path per example: /tmp/ramdisk

Not sure if I'm doing something wrong.

@nilaoda
Copy link
Owner

nilaoda commented Nov 14, 2023

@JohnTrabusca

RE_LIVE_PIPE_TMP_DIR="/data/my_temp" ./N_m3u8DL-RE xxx

@JohnTrabusca
Copy link

After setting and doing a stat to that file (RE_pipe) in the given path in logs, it cannot be found.

@neorom23
Copy link

Hello. There is such a link mpd...

https://vs12.vcdn.biz/ea7c2a50874e06892616c81fed8764f1_mgg/vod/mpd/b/450_900_1350_1500_2000_5000/u_sid/0/o/176166551/rsid/8a209735-8af0-46f9-afc9-5aae98954316/u_uid/1546846946/u_vod/4/u_device/cms_html5/u_devicekey/_site/u_srvc/2741/te/1760354712/u_did/web_ufUvWAJW4hh3VWBsJtUHNwHAi8JtabBU/wtrmrk/0/manifest.mpd

The program N_m3u8DL-RE 0.2.0 Beta normally downloads temporary video mp4 files 142 pieces (each size 10.0 MB), adds the disputed one 143 piece and the last one has a file size of 1.5 GB. Collect together the mp4 files have a size of - 2.11 GB with a duration of 01:15:38, although it should be 1.39 GB with a duration of 00:49:59 (only the video without sound and subtitles)

Here are the options available on the command line - N_m3u8DL-RE "%mpd%" --check-segments-count:false --save-name "02" --key 7d91116c8f0b95b8db4953f1f26e6aa2:5a4491ef67bc263c0 125c5914322dfba

yt-dlp - this program load normally video size 1.39 GB

@dark125
Copy link

dark125 commented Apr 18, 2024

There is a problem with this option RE_LIVE_PIPE_TMP_DIR="/tmp/channel", the pipe file keeps being created in the /tmp/ folder and N_m3u8DL-RE looks for that file in /tmp/channel/, that's why it gives an error
/tmp/channel/RE_pipe_f2eee6bf-6068-43aa-b36a-ac8bca0e5677: No such file or directory

@Technerd-SG
Copy link

I have the same problem I sovled it like so:

streamlink "http://stream.example/manifest.mpd" best --ffmpeg-dkey "123456789abcdefghijklmnopqrstuvwx" --stdout | ffmpeg -re -i pipe:0 -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -f flv rtmp://server.ip/stream1/stream

the normal streamlink software doesnt support this you would need to use: "https://github.com/sunghome/streamlink_optionalkey". This is not a good solution...
Please implement a pipe function!...

@mamontovmv
Copy link

Now working grate no jittler or audio loss or stuck, perfect!! thanks!

How did you fix this problem?

@matthias1232
Copy link

matthias1232 commented Aug 25, 2024

i compiled the changes what @alphalneo said.
https://github.com/matthias1232/N_m3u8DL-RE/releases/tag/1.0

This Script works for me with TVHeadend Server:

#!/bin/sh
rm /var/www/html/tv/yourchannel/temp -rf
export RE_LIVE_PIPE_OPTIONS="-c copy -f mpegts pipe:2"
./N_m3u8DL-RE --log-level off --no-date-info --no-log True --key yourkey1 --key yourkey2 https://example.com/manifest.mpd --del-after-done true --mp4-real-time-decryption true --live-keep-segments false --live-real-time-merge true --live-pipe-mux true --thread-count 3 -sv best -sa all --concurrent-download --tmp-dir /var/www/html/tv/yourchannel/temp --save-dir /var/www/html/tv/yourchannel/temp --save-name temp 2>&1 >/dev/null
pid=$!

# If this script is killed, kill the `N_m3u8DL-RE'.
#trap "kill $pid 2> /dev/null" EXIT
# While N_m3u8DL-RE is running...
while kill -0 $pid 2> /dev/null; do
    find /var/www/html/tv/yourchannel/temp -mmin +1 -type f -exec rm -fv {} \;
	sleep 1
done

# Disable the trap on a normal exit.

In TVheadend add the MUX:
pipe:///var/www/html/tv/yourchannel/stream.sh

@matthias1232
Copy link

matthias1232 commented Sep 3, 2024

I got it working now without any problems with Jitter, Stream Stucking lost Packets etc.... but the initial stream loading Time is incredibly slow now.
The Stream Start Takes around 10-15 Seconds now. Maybe we can reduce the time to a Minimum, any ideas?

#!/bin/sh
rm /var/www/html/temp/1 -rf
mkdir /var/www/html/temp/1 -p
export RE_LIVE_PIPE_OPTIONS="-movflags faststart -loglevel error -map 0 -c:a copy -c:v copy -c:s copy -f mpegts -y pipe:"
/opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" https://orf3-247.mdn.ors.at/orf/orf3/qxa-247/manifest.mpd -no-log true --use-ffmpeg-concat-demuxer false --no-date-info false --live-real-time-merge true --live-pipe-mux true --save-dir /var/www/html/temp/1 --tmp-dir /var/www/html/temp/1 --check-segments-count false --live-fix-vtt-by-audio true --mp4-real-time-decryption true --skip-merge false --del-after-done true --save-name temp -mt TRUE --thread-count 16 --auto-select --live-take-count 4 --live-wait-time 9 -M format=mp4:muxer=ffmpeg | ffmpeg -loglevel fatal -i pipe:0 -map 0 -c:a copy -c:v copy -c:s copy -mpegts_service_type advanced_codec_digital_hdtv -f mpegts -y pipe:1

The MPD Dash is not DRM Protected in my example. You should be able to try it.

@matthias1232
Copy link

matthias1232 commented Sep 11, 2024

Hi again,
i made a new Version of N_m3u8DL-RE. This should fix the issues with livestreams. I disabled the ffmpeg -re feature, so pipe will send out the first segments directly to the clients, and then stream as usual when new segments are downloaded.
i also added ffmpeg options: -rtbufsize 1G -y -max_interleave_delta 100M -fflags +fastseek+ignidx+discardcorrupt+shortest+genpts

https://github.com/matthias1232/N_m3u8DL-RE/releases/tag/1.8

Im not sure if my version breaks other features, but my purpose is livestreams with TVHeadend, and this works well now.

A working script for tvheadend could look like this:

#!/bin/sh
rm /var/www/html/temp/1 -rf
rm /var/www/html/save/1 -rf
mkdir /var/www/html/temp/1 -p
mkdir /var/www/html/save/1 -p
export RE_LIVE_PIPE_OPTIONS="-dn -drop_pkts_on_overflow 1 -attempt_recovery 1 -recover_any_error 1 -map_metadata:g 1:g -loglevel quiet -mpegts_service_type advanced_codec_digital_hdtv -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -f mpegts -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -movflags +delay_moov+default_base_moof+cmaf+frag_every_frame+separate_moof+rtphint+omit_tfhd_offset -rtpflags +h264_mode0 pipe:1"
/opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE /opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --key xxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxx --key xxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxx https://orf1-247.mdn.ors.at/orf/orf1/drmqxa-247/manifest.mpd --save-dir /var/www/html/save/1 --save-name temp --tmp-dir /var/www/html/temp/1 --auto-subtitle-fix true --live-fix-vtt-by-audio true --mp4-real-time-decryption true --use-ffmpeg-concat-demuxer true --no-date-info --download-retry-count 0 --check-segments-count true --live-real-time-merge false --live-keep-segments false --auto-select --live-take-count 3 --force-ansi-console false --del-after-done false --no-log --log-level OFF --live-pipe-mux true

chmod +x /var/www/html/stream-10.sh

Tvheadend mux:

pipe:///var/www/html/stream-10.sh

@ivovas
Copy link

ivovas commented Sep 16, 2024

Hello, I am trying to decrypt an MPD source and push it to RTMP using the following command:

export RE_LIVE_PIPE_OPTIONS=' -c copy -f flv rtmp://ip:port/live/test_turk ';
N_m3u8DL-RE 'url' --key 'key:key' --use-shaka-packager true --ffmpeg-binary-path /bin/ffmpeg --decryption-binary-path bin/packager-linux-x64 --del-after-done true --mp4-real-time-decryption true --live-keep-segments false --binary-merge --live-pipe-mux true --thread-count 5 --use-ffmpeg-concat-demuxer --auto-select --save-name 10dc0e29-521b-4861-9ee8-3903015a1400

The issue I'm encountering is that the RTMP process stops unexpectedly after around 10 minutes, and I have no idea why. There is nothing in the logs that indicates what might be causing the problem.

Does anyone have any suggestions on how to troubleshoot or resolve this?

@lutfijw
Copy link

lutfijw commented Jan 9, 2025

@matthias1232 tried your command, but not working and seems like the app is not writing anything to the pipe or call ffmpeg. Additionally, I also unable to find any muxed mpegts file. What I can found is the app downloading each segments in a directory and only muxing the segments once download completed.

@matthias1232
Copy link

matthias1232 commented Jan 9, 2025

@lutfijw
I compiled another version a while ago and use it with TVHeadend Server.

https://github.com/matthias1232/N_m3u8DL-RE/releases

https://github.com/matthias1232/N_m3u8DL-RE/commits/main/

#!/bin/sh
rm /var/www/html/temp/1 -rf
rm /var/www/html/save/1 -rf
mkdir /var/www/html/temp/1 -p
mkdir /var/www/html/save/1 -p
export RE_LIVE_PIPE_OPTIONS="-dn -attempt_recovery 1 -recover_any_error 1 -loglevel quiet -mpegts_service_type advanced_codec_digital_hdtv -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -ignore_unknown -f mpegts -preset veryfast -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -movflags +delay_moov+default_base_moof+cmaf+frag_every_frame+separate_moof+rtphint+omit_tfhd_offset -rtpflags +h264_mode0 pipe:1"
/opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg https://orf1-247.mdn.ors.at/orf/orf1/drmqxa-247/manifest.mpd --save-dir /var/www/html/save/1 --save-name temp --tmp-dir /var/www/html/temp/1 --auto-subtitle-fix false --live-fix-vtt-by-audio false --mp4-real-time-decryption false --use-ffmpeg-concat-demuxer false --no-date-info --download-retry-count 3 -mt --check-segments-count false --live-real-time-merge false --live-keep-segments false -ss all -sa all -sv best --live-take-count 2 --force-ansi-console false --del-after-done false --no-log --log-level OFF --live-pipe-mux true

And in tvheadend i run the script with: (must be executable for the tvheadend user, usually user hts)
pipe:///var/www/html/orfon-1.sh

You need to map your created mux first as Service and run from there. I guess there is a bug or something with tvheadend because running the mux directly fails)

Its running very stable, only in the beginning after 5 Seconds i have sometimes a stucking picture for under 1 second but then everything works as expected.

Dont forget to install mp4decrypt otherwhise it will not work.
You can run a bash shell with the user hts and try everything first from putty first

just execute /var/www/html/orfon-1.sh

If nothing happens you can temporary enable all logging features again in the code and check your errors.

Also note that your executing user needs write permissions to all the folders in the script!

Btw this example code will not work for you with this TV Channel because i changed the decryption keys before posting here.

If you work with your own appliaction you can also try around with the "pipe:1" setting and change the value to another one which maybe then works for you.

If everything works, putty should play the pipe directly in the shell. Putty will crash but in that Moment you know everything works. Just reopen another session, disable all loggings again and then all is set for you application.

And yes i know this solution is not perfect but i have not found a better way for a stable tvheadend setup.

Regards

@Technerd-SG
Copy link

@lutfijw I compiled another version a while ago and use it with TVHeadend Server.

https://github.com/matthias1232/N_m3u8DL-RE/releases

https://github.com/matthias1232/N_m3u8DL-RE/commits/main/

#!/bin/sh
rm /var/www/html/temp/1 -rf
rm /var/www/html/save/1 -rf
mkdir /var/www/html/temp/1 -p
mkdir /var/www/html/save/1 -p
export RE_LIVE_PIPE_OPTIONS="-dn -attempt_recovery 1 -recover_any_error 1 -loglevel quiet -mpegts_service_type advanced_codec_digital_hdtv -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -ignore_unknown -f mpegts -preset veryfast -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -movflags +delay_moov+default_base_moof+cmaf+frag_every_frame+separate_moof+rtphint+omit_tfhd_offset -rtpflags +h264_mode0 pipe:1"
/opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg https://orf1-247.mdn.ors.at/orf/orf1/drmqxa-247/manifest.mpd --save-dir /var/www/html/save/1 --save-name temp --tmp-dir /var/www/html/temp/1 --auto-subtitle-fix false --live-fix-vtt-by-audio false --mp4-real-time-decryption false --use-ffmpeg-concat-demuxer false --no-date-info --download-retry-count 3 -mt --check-segments-count false --live-real-time-merge false --live-keep-segments false -ss all -sa all -sv best --live-take-count 2 --force-ansi-console false --del-after-done false --no-log --log-level OFF --live-pipe-mux true

And in tvheadend i run the script with: (must be executable for the tvheadend user, usually user hts) pipe:///var/www/html/orfon-1.sh

You need to map your created mux first as Service and run from there. I guess there is a bug or something with tvheadend because running the mux directly fails)

Its running very stable, only in the beginning after 5 Seconds i have sometimes a stucking picture for under 1 second but then everything works as expected.

Dont forget to install mp4decrypt otherwhise it will not work. You can run a bash shell with the user hts and try everything first from putty first

just execute /var/www/html/orfon-1.sh

If nothing happens you can temporary enable all logging features again in the code and check your errors.

Also note that your executing user needs write permissions to all the folders in the script!

Btw this example code will not work for you with this TV Channel because i changed the decryption keys before posting here.

If you work with your own appliaction you can also try around with the "pipe:1" setting and change the value to another one which maybe then works for you.

If everything works, putty should play the pipe directly in the shell. Putty will crash but in that Moment you know everything works. Just reopen another session, disable all loggings again and then all is set for you application.

And yes i know this solution is not perfect but i have not found a better way for a stable tvheadend setup.

Regards

Thats awsome! How and did you by any chance have a solution for the changing encryption keys? Is there any software that is capable of automatically fetching the keys? Thanks!!

@lutfijw
Copy link

lutfijw commented Jan 10, 2025

@lutfijw I compiled another version a while ago and use it with TVHeadend Server.

https://github.com/matthias1232/N_m3u8DL-RE/releases

https://github.com/matthias1232/N_m3u8DL-RE/commits/main/

#!/bin/sh
rm /var/www/html/temp/1 -rf
rm /var/www/html/save/1 -rf
mkdir /var/www/html/temp/1 -p
mkdir /var/www/html/save/1 -p
export RE_LIVE_PIPE_OPTIONS="-dn -attempt_recovery 1 -recover_any_error 1 -loglevel quiet -mpegts_service_type advanced_codec_digital_hdtv -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -ignore_unknown -f mpegts -preset veryfast -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -movflags +delay_moov+default_base_moof+cmaf+frag_every_frame+separate_moof+rtphint+omit_tfhd_offset -rtpflags +h264_mode0 pipe:1"
/opt/N_m3u8DL-RE_Beta_linux-arm64/N_m3u8DL-RE --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg --key nxcylhkjfsdaiguweqrmnsdbcsg:nxcylhkjfsdaiguweqrmnsdbcsg https://orf1-247.mdn.ors.at/orf/orf1/drmqxa-247/manifest.mpd --save-dir /var/www/html/save/1 --save-name temp --tmp-dir /var/www/html/temp/1 --auto-subtitle-fix false --live-fix-vtt-by-audio false --mp4-real-time-decryption false --use-ffmpeg-concat-demuxer false --no-date-info --download-retry-count 3 -mt --check-segments-count false --live-real-time-merge false --live-keep-segments false -ss all -sa all -sv best --live-take-count 2 --force-ansi-console false --del-after-done false --no-log --log-level OFF --live-pipe-mux true

And in tvheadend i run the script with: (must be executable for the tvheadend user, usually user hts) pipe:///var/www/html/orfon-1.sh

You need to map your created mux first as Service and run from there. I guess there is a bug or something with tvheadend because running the mux directly fails)

Its running very stable, only in the beginning after 5 Seconds i have sometimes a stucking picture for under 1 second but then everything works as expected.

Dont forget to install mp4decrypt otherwhise it will not work. You can run a bash shell with the user hts and try everything first from putty first

just execute /var/www/html/orfon-1.sh

If nothing happens you can temporary enable all logging features again in the code and check your errors.

Also note that your executing user needs write permissions to all the folders in the script!

Btw this example code will not work for you with this TV Channel because i changed the decryption keys before posting here.

If you work with your own appliaction you can also try around with the "pipe:1" setting and change the value to another one which maybe then works for you.

If everything works, putty should play the pipe directly in the shell. Putty will crash but in that Moment you know everything works. Just reopen another session, disable all loggings again and then all is set for you application.

And yes i know this solution is not perfect but i have not found a better way for a stable tvheadend setup.

Regards

That is awesome @matthias1232 , let me try your script. I am also planning to restream using tvHeadend just like what you did. Will try and report back to you tomorrow.

@matthias1232
Copy link

matthias1232 commented Jan 10, 2025

@Technerd-SG
Yes, you can automate it with python but its illegal, so i cant post any guide or code how to do it. But i can tell you where to find it.

Changing Keys is also the reason why i created a bash script for every channel, because if you always change the mux directly in TVHeadend with the new keys, the Channel mapping will get lost.

How to get the decryption keys:
You first need to obtain a working .wvd file from an Android device. You can use videohelp.com and search for the guide how to do that. I did it with Android Studio and it worked. But there are maybe more ways to get the .wvd. File.

You will also find the guide there in the videohelp Forum how to request the decryption keys with pywidevine from the license Server of the TV Channel provider.

And of course to automate it you need to reverse engineer the API from your provider you want to use to use.

There are some Kodi Projects on Github for simplitv, waipu, etc. where you can see how they did that. You only need to modifiy the code to get it working without Kodi. Instead of using Kodi you need to change the parts of the code and replace it with your own code to obtain the pssh keys and request the decryption keys with pywidevine from the license Server with your .wvd file in the post command.

@Technerd-SG
Copy link

@Technerd-SG Yes, you can automate it with python but its illegal, so i cant post any guide or code how to do it. But i can tell you where to find it.

Changing Keys is also the reason why i created a bash script for every channel, because if you always change the mux directly in TVHeadend with the new keys, the Channel mapping will get lost.

How to get the decryption keys: You first need to obtain a working .wvd file from an Android device. You can use videohelp.com and search for the guide how to do that. I did it with Android Studio and it worked. But there are maybe more ways to get the .wvd. File.

You will also find the guide there in the videohelp Forum how to request the decryption keys with pywidevine from the license Server of the TV Channel provider.

And of course to automate it you need to reverse engineer the API from your provider you want to use to use.

There are some Kodi Projects on Github for simplitv, waipu, zattoo etc. where you can see how they did that. You only need to modifiy the code to get it working without Kodi. Instead of using Kodi you need to change the parts of the code and replace it with your own code to obtain the pssh keys and request the decryption keys with pywidevine from the license Server with your .wvd file in the post command.

Ok got it. I already have the .wcd file (also from Android Studio) and I was able with a Browserextention to get the keys manually from the ORF-ON Site (I'm from Austria) and I was able to write a NodeJS script that provides an emtpy rtsp stream and listens and when someone wants to stream the rtsp stream it uses the decryption keys that I extracted bevorehand to decrypt the stream and stream to Jellyfin. But I didn't know how to automate the key extraction part xd
Thanks for your fast response!

@matthias1232
Copy link

matthias1232 commented Jan 10, 2025

@Technerd-SG
https://github.com/matthias1232/ORF-ON

You need to develop in Austria. They use geoblocking with cloudflare for most of the Programm they stream and also block Datacenter IPs. If you decrypt with the wrong ip, the keys will not work.

@lutfijw
Copy link

lutfijw commented Jan 10, 2025

https://github.com/matthias1232/ORF-ON

Hi @matthias1232 ,
I can't wait till tom then downloading your complied N_m3uDL and try but, it is still not working.
Please see my script below:

#!/bin/sh rm /var/www/temp/temp/1 -rf rm /var/www/temp/save/1 -rf mkdir /var/www/temp/temp/1 -p mkdir /var/www/temp/save/1 -p export RE_LIVE_PIPE_OPTIONS="-dn -attempt_recovery 1 -recover_any_error 1 -loglevel quiet -mpegts_service_type advanced_codec_digital_hdtv -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -ignore_unknown -f mpegts -preset veryfast -protocol_whitelist pipe,file,http,https,tcp,tls,crypto -movflags +delay_moov+default_base_moof+cmaf+frag_every_frame+separate_moof+rtphint+omit_tfhd_offset -rtpflags +h264_mode0 pipe:1" /var/www/temp/N_m3u8DL-RE \ --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" \ --key aabbccddeeff:aabbccddeeff \ [MPD_URL] \ --save-dir /var/www/temp/save/1 \ --save-name temp \ --tmp-dir /var/www/temp/temp/1 \ --auto-subtitle-fix false \ --live-fix-vtt-by-audio false \ --mp4-real-time-decryption false \ --use-ffmpeg-concat-demuxer false \ --no-date-info \ --download-retry-count 3 \ -mt \ --check-segments-count false \ --live-real-time-merge false \ --live-keep-segments false \ -sa best \ -sv best \ --live-take-count 2 \ --force-ansi-console false \ --del-after-done false \ --live-pipe-mux true

Error shown in tvHeadend is as follow:
2025-01-10 20:02:45.492 http: 192.168.1.186: HTTP/1.1 GET (1) /libMediaVLC.xml -- 404 2025-01-10 20:02:46.834 mpegts: TEST in TVKU - tuning on IPTV #1 2025-01-10 20:02:46.839 spawn: Executing "/var/www/temp/test.sh" 2025-01-10 20:02:46.839 subscription: 00D4: "HTTP" subscribing on channel "TEST", weight: 100, adapter: "IPTV #1", network: "TVKU", mux: "TEST", service: "TEST", profile="pass", hostname="192.168.1.186", client="VLC/3.0.21 LibVLC/3.0.21" 2025-01-10 20:03:02.835 subscription: 00D4: service instance is bad, reason: No input detected 2025-01-10 20:03:02.835 mpegts: TEST in TVKU - tuning on IPTV #2 2025-01-10 20:03:02.841 subscription: 00D4: "HTTP" subscribing on channel "TEST", weight: 100, adapter: "IPTV #2", network: "TVKU", mux: "TEST", service: "TEST", profile="pass", hostname="192.168.1.186", client="VLC/3.0.21 LibVLC/3.0.21" 2025-01-10 20:03:02.841 spawn: Executing "/var/www/temp/test.sh" 2025-01-10 20:03:07.469 webui: Stop streaming /stream/channel/3dcc573d34dd3b14ad0075d5db4e70fd, timeout (20 secs) waiting for data packets to start 2025-01-10 20:03:07.469 subscription: 00D4: "HTTP" unsubscribing from "TEST", hostname="192.168.1.186", client="VLC/3.0.21 LibVLC/3.0.21" 2025-01-10 20:03:07.515 mpegts: TEST in TVKU - tuning on IPTV #1 2025-01-10 20:03:07.520 spawn: Executing "/var/www/temp/test.sh" 2025-01-10 20:03:07.520 subscription: 00D5: "HTTP" subscribing on channel "TEST", weight: 100, adapter: "IPTV #1", network: "TVKU", mux: "TEST", service: "TEST", profile="pass", hostname="192.168.1.186", client="VLC/3.0.21 LibVLC/3.0.21"

I did check whether ffmpeg got triggered using ps -aux, but no ffmpeg triggered. Additionally, I tried to change the "pipe:1" command to stream the mux to my RTMP server but again seem no call been made. I also find the save directory is always empty while the temp directory fill with many m4s segments. I am not sure whether the live-pipe-mux is doing the job.

Do you have telegram? Can you contact me at @P4nj183

@matthias1232
Copy link

matthias1232 commented Jan 10, 2025

@lutfijw

IMG_9645

@matthias1232
Copy link

@lutfijw

and in tvheadend you need to add the file like that:
pipe://your/path/to/file.sh

@matthias1232
Copy link

And yes to come back to the issue
You guys with tvheadend can maybe confirm a bug i also couldnt completely solve?

When you play the stream with —live-take-count 2 you will have the best performance and stability with tvheadend, but always after the first played segments the stream reloads and stucks a second and then resumes normaly for hours or days without any problem.

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

No branches or pull requests