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

Problem streaming/recording a program at transponders where all programs are associated with PMT packets with same PMT_ID #106

Open
Azureit opened this issue Sep 30, 2022 · 0 comments

Comments

@Azureit
Copy link

Azureit commented Sep 30, 2022

I'm not a developer, and to solve this is needed a special kind of developers that knows how to build advanced demux filters and deal with them.

mpegts has PMT packets that look like this e.g.:

PMT packet hex representation:
------------------------------------------------------------
  0000:  02 b0 26 17 92 e1 00 00  f3 b1 f0 09 09 07 18 14   ..&.............
  0010:  e6 34 02 52 11 1b f3 b1  f0 00 04 f3 b2 f0 06 0a   .4.R............
  0020:  04 65 6e 67 00 94 0d 38  ab                        .eng...8.
------------------------------------------------------------

PMT packet decoded:
------------------------------------------------------------
Table_ID: 2 (0x02)  [= Program Map Table (PMT)]
section_syntax_indicator: 1 (0x01)
(fixed '0'): 0 (0x00)
reserved_1: 3 (0x03)
Section_length: 38 (0x0026)
Program_number: 6034 (0x1792)
reserved_2: 3 (0x03)
Version_number: 16 (0x10)
current_next_indicator: 1 (0x01)  [= valid now]
Section_number: 0 (0x00)
Last_Section_number: 0 (0x00)
reserved_3: 7 (0x07)
PCR PID: 5041 (0x13b1)
reserved_4: 15 (0x0f)
Program_info_length: 9 (0x0009)

        MPEG-DescriptorTag: 9 (0x09)  [= CA_descriptor]
        descriptor_length: 7 (0x07)
        CA_system_ID: 6164 (0x1814)  [= Kudelski SA]
        reserved: 7 (0x07)
        CA_PID: 1588 (0x0634)
        Private Data:
              0000:  02 52 11                                           .R.

Stream_type loop: 

    Stream_type: 27 (0x1b)  [= AVC video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video]
    reserved_1: 7 (0x07)
    Elementary_PID: 5041 (0x13b1)
    reserved_2: 15 (0x0f)
    ES_info_length: 0 (0x0000)


    Stream_type: 4 (0x04)  [= ISO/IEC 13818-3 Audio]
    reserved_1: 7 (0x07)
    Elementary_PID: 5042 (0x13b2)
    reserved_2: 15 (0x0f)
    ES_info_length: 6 (0x0006)

            MPEG-DescriptorTag: 10 (0x0a)  [= ISO_639_language_descriptor]
            descriptor_length: 4 (0x04)
               ISO639_language_code:  eng
               Audio_type: 0 (0x00)  [= undefined]
------------------------------------------------------------

Most transponders, each program is associated with one exclusive PMT_ID,
e.g. 1)
program_number=100 is associated with PMT_ID=800
program_number=150 is associated with PMT_ID=807
program_number=155 is associated with PMT_ID=845

but the most complicated to demux transponders(e.g.: hispasat 30W - Network_ID: 54 (0x0036)), all programs are associated with one PMT_ID,
e.g. 2)
program_number=100 is associated with PMT_ID=817
program_number=150 is associated with PMT_ID=817
program_number=155 is associated with PMT_ID=817

In the first transponder it's easy to apply a demux filter DMX_SET_PES_FILTER for PMT packets associated with the program we want by PMT_ID, like is done at demux.cpp#L872, but in the second transpoder if we apply the filter the same way, we will get a mpegts with the PMT packets of all the programs of that transponder, so we need an advanced demux filter using DMX_SET_FILTER to filter the PMT packets by program_number and deal with it to have a mpegts of the program.

This type of mpegts with one PMT_ID for all the programs is unplayable for 99% of video players. In the case of mpv, I didn't analise the code, but just by using mpv with mpegts streams/files, I know it orders streams by reading PMT tables packets and then try to play the program of the first PMT table packet received and will hang, without even starting the GUI, waiting for streams --vid=1 and/or --aud=1, because most of the time the first PMT packet will not be of the program the demuxer is filtering, so there will never be the streams --vid=1 and/or --aud=1.


I have a workaround using inetd and ffmpeg:

/etc/services

ffmpeg-e2       8002/tcp

/etc/inetd.conf

ffmpeg-e2      stream  tcp     nowait  root    /home/root/ffmpeg-e2.sh ffmpeg-e2.sh

/home/root/ffmpeg-e2.sh

#!/bin/bash

read request

request_arr=($request)
if [ "${request_arr[0]}" == "GET" ]; then
	sref=${request_arr[1]:1}
	IFS=':' sref_arr=($sref)
	if [ "${#sref_arr[@]}" -ge "10" ]; then
		program_id=${sref_arr[3]}
		network_id_sat=${sref_arr[5]}":"${sref_arr[6],,}
		serviceplayable=1
		if ! wget -q --timeout=5 -O- "http://127.0.0.1/api/serviceplayable?sRef=${sref}" 2> /dev/null | grep -q isplayable.*true; then
			serviceplayable=0 # try to make the service playable by zapping to it.
			wget -q --timeout=5 -O /dev/null "http://127.0.0.1/api/zap?sRef=${sref}" > /dev/null 2>&1
			sleep 3; wget -q --timeout=5 -O- "http://127.0.0.1/api/serviceplayable?sRef=${sref}" 2> /dev/null | grep -q isplayable.*true && serviceplayable=1
		fi
		if [ $serviceplayable -eq 1 ]; then
			if [ "$network_id_sat" == "36:ce40000" ]; then
				echo -ne "HTTP/1.0 200 OK\nContent-Type: video/mpeg\nConnection: Close\nServer: streamserver\n\n"
				ffmpeg -hide_banner -loglevel quiet -i "http://127.0.0.1:8001/${sref}" -map "0:p:0x${program_id}" -c copy -abort_on empty_output_stream -f mpegts -
				sleep 2; exit 0
			else
				ip_addr=$(ip -4 -o addr show up primary scope global | grep -ohm1 'inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | awk '{print $2}')
				echo -ne "HTTP/1.0 302 Found\nLocation: http://${ip_addr}:8001/${sref}\nConnection: Close\nServer: streamserver\n\n"
				sleep 2; exit 0
			fi
		else
			echo -ne "HTTP/1.0 503 Service Unavailable\nConnection: Close\nServer: streamserver\n\n"
			sleep 2; exit 1
		fi
	fi
fi

echo -ne "HTTP/1.0 400 Bad Request\nConnection: Close\nServer: streamserver\n\n"
sleep 2; exit 1

/etc/enigma2/settings

config.OpenWebif.streamport=8002
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

1 participant