AvalpaBroadcastServerUserManual-v1 0
AvalpaBroadcastServerUserManual-v1 0
AvalpaBroadcastServerUserManual-v1 0
http://www.avalpa.com
Thanks to:
http://www.avalpa.com
Table of contents
General Index
Avalpa Broadcast Server User Manual...............................................................1 Table of contents.................................................................................................3 Introduction........................................................................................................6 Introduction to Avalpa Broadcast Server........................................................6 Introduction to Avalpa.....................................................................................6 Introduction to OpenCaster............................................................................7 Use cases: some examples..............................................................................7 Demonstration.................................................................................................7 System integration..........................................................................................8 Technical overview..........................................................................................8 Scope of the manual and intended audience..................................................8 Copyright and warranty..................................................................................8 OpenCaster, the software............................................................................8 Avalpa Broadcast Server, the manual..........................................................9 How to read the manual................................................................................10 Interesting and basic readings......................................................................10 Avalpa Broadcast Server installation................................................................12 Login into the system....................................................................................12 Setting up a fixed IP address........................................................................12 Configure multicast routing..........................................................................12 Avalpa Broadcast Server basic concepts and usage.........................................13 Your first transport stream goes on air.........................................................13 Multiplexing a Single Program Transport Stream........................................21 Generating PSI/SI basic tables......................................................................23 Transport stream bitrate...............................................................................27 Avalpa Broadcast Server media ingestion .......................................................28 Introduction to ingestion...............................................................................28 Extracting Program and Elementary Streams: ts2pes..................................30 Analysing video files: esvideoinfo.................................................................31 Picture coding type....................................................................................31 Tool vbv......................................................................................................32 Analysing audio elementary streams: esaudioinfo........................................34 How to encode digital video files with ffmpeg..............................................35 How to encode digital audio files with ffmpeg..............................................36 How to capture DV input...............................................................................38 Audio and video real case ingestion study ...................................................39 Audio and video initial synchronization....................................................40 Play out scheduling from command line...........................................................41 Starting at a given time................................................................................47 Avalpa Broadcast Server advanced services....................................................49 EPG................................................................................................................50 3 http://www.avalpa.com
Avalpa Broadcast Server user manual Multiplexing a Multiple Program Transport Stream....................................54 BISS-E and CSA output support....................................................................58 IP network tools............................................................................................60 Teletext support............................................................................................61 DSMCC carousels and data casting..............................................................65 DVB-SSU....................................................................................................65 Interactive TV support..................................................................................69 Tool oc-update.sh.......................................................................................69 MHP/MHEG5 signalling............................................................................69 Update an object carousel with running applications...............................74 Signalling Stream Events..........................................................................75 DVB-S receiver..............................................................................................80 Dvblast tool ...............................................................................................80 Transmodulation and re-multiplexing...........................................................82 tsorts .........................................................................................................82 tsororts .....................................................................................................83 Transport stream data analysis........................................................................84 Tool dvbsnoop................................................................................................84 dvbsnoop on dvb-s input............................................................................85 dvbsnoop on Avalpa Broadcast Server output..........................................87 Tool dsmcc-receive and ts2ec.......................................................................88 Avalpa Broadcast Server:Avalpa Playlist Editor GUI........................................89 Introduction...................................................................................................89 Technology and features...............................................................................89 Todo, known issues and nasty features.........................................................90 Daily usage....................................................................................................91 Web front-end................................................................................................91 Configuration strategies of the APE.............................................................91 Basic best-effort schedule configuration...................................................92 How to insert events at the right (fixed) time...............................................94 Dataset description...................................................................................94 How to insert fixed time events.................................................................94 Random programming..................................................................................95 Quick schedule features............................................................................96 Graphical interface features......................................................................96 Add a new content to APE.............................................................................98 Marking content..........................................................................................101 Adding new markers...................................................................................102 Avalpa Playlist Edtitor script: Introduction.................................................103 Avalpa Playlist Editor scripts customization...............................................104 Avalpa Broadcast Server:Avalpa Web EPG GUI..............................................105 Introduction.................................................................................................105 Week view....................................................................................................106 EPG editing.................................................................................................107 Appendix A: Acronyms, glossary and references............................................108 Appendix B: DVB-T transmission parameters and net bitrates......................109 Appendix C: Related readings .......................................................................110 4 http://www.avalpa.com
Avalpa Broadcast Server user manual Appendix D: Mpeg2 transport stream overview.............................................111
ADB Global, Adobe, Computer Modules, DekTec, Dell, DVB, Firefox, Gnu, Ibm, Java, Linux, Mainconcept, Mozilla, PowerPc, Premiere, Sun Microsystems are registered Trademarks of their respective owners.
http://www.avalpa.com
Introduction
Introduction to Avalpa Broadcast Server
Avalpa Broadcast Server is a single unit system featuring a collection of tools to generate, process, multiplex, play out and broadcast MPEG-2 transport stream content. Transport stream (usual file suffixes are .TS, .TP, MPEG-TS, or .M2T) is a communication protocol for audio, video, and data which is specified in MPEG-2 (ISO/IEC standard 13818-1). An overview of the protocol is available on Appendix. Transport stream offers features for error correction for transport over unreliable media, and is used in broadcast networks such as DVB. Inputs for the systems are audio and video coming from: files stored on the hard disk, DVB-S satellite signal or firware using DV standard. Avalpa Broadcast Server output comes with two configurations: for DVB networks integration it features DVB-ASI output or as stand along box features a DVB-T modulator output option. MPEG2 Transport Stream over UDP (IPTV) output and file output are also available on both configurations. The DVB-T output can be directly received by low cost Set Top Boxes or Digital Tv set with hardware decoders and integrated DVB tuner. Unique features among others are the support of advanced data casting through DSMCC and IP over Transport stream (IP-MPE), interactive television both MHP and MHEG5, EPG, LCN, etc... Avalpa Broadcast Server runs over a Linux Debian Stable system with a customized kernel and feature web GUIs for scheduling events, mhp and videos.
Introduction to Avalpa
Avalpa is an Italian company working in the digital television market since a long time with a quite broad range of products and services for broadcaster, great skills, creativity and an open mind attitude. Avalpa http://www.avalpa.com/ is the main developer of OpenCaster and wrote this manual too; Avalpa offering include also:
Custom installations and maintenance of solutions Integration with others DVB systems Training, support and consultancy Further development of features and customization. [email protected] CEO [email protected] CTO [email protected] for general questions or ordering info.
Contacts:
http://www.avalpa.com
Introduction to OpenCaster
OpenCaster is the GPL v2 open source software developed mainly by Avalpa People and its the heart of Avalpa Broadcast Server. OpenCaster is available also as standalone download from Avalpa web site (www.avalpa.com) to anybody that wants to work on it source code and develop it further. Avalpa Broadcast Server however IS NOT what you get installing OpenCaster on your Linux pc! Avalpa Broadcast Server also features APE, Avalpa Playlist Editor, a gui for drag'n'drop audio/video interactive playout schedule and AWE, Avalpa Web EPG, for event information insertion and generation. A long list of hardware boards, software libraries and kernel modules has been choose, installed, customized, integrated and configured to get the best stability and performance out of OpenCaster.
Demonstration
You can download a transport stream multiplexed by OpenCaster showing many advanced features at: http://www.avalpa.com/the-key-values/15-free-software/59opencaster-demo-roll The transport stream is ready to be broadcast with a DVB-T modulator using QAM 16, guard interval 1/4 and code rate 2/3,you can watch on your tv or stb. You can play it on pc by VLC or streamed on IP setting bitrate at 13271000 bps.
http://www.avalpa.com
System integration
Avalpa Broadcast Server generated output has been successfully integrated on top of many third parties systems, among them it was already deployed with systems by Cisco/Scientific Atlanta, Ericsson/Tandberg, Eurotek, Scopus now Harmonic, Mitan and Screen Service Contact [email protected] for information about system integration or live systems proposal with third parties hardware.
Technical overview
Tools and libraries are mainly written in 2 languages: Python (2.5) and C (ANSI '99). Python is used for section data generation while C is used for transport stream encoding, processing and multiplexing.
Avalpa Broadcast Server user manual details.YoushouldhavereceivedacopyoftheGNUGeneralPublic Licensealongwiththe OpenCastersoftware;ifnot,writetothe Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,MA021101301USA
http://www.avalpa.com
The following symbols will serve as follow: Symbol Description Pay attention to this note, it should be a hint for a smarter usage of the software
Beware, you can get some undesirable effect if you don't understand instructions and follow them carefully
Help! This part is not completely up to date or finished; maybe you can help us, would you like?
Then, in the paragraphs where there are practical exercises using materials to be found in the OCtutorials directories on the server, we list them in advance with such a graphical hint: [OCTutorials/sample.ts]
Avalpa Broadcast Server user manual read Appendix by prof. Antonio Navarro from Aveiro University for an introduction, for a more deeper overview have a look at A Guide to MPEG Fundamentals and Protocols Analysis freely available by Tektronix. Good books to get into the details are: Digital Video and Audio Broadcasting Technology by W.Fisher and Interactive TV standards by Steve Morris, The main specification OpenCaster refers to is: ISO/IEC 13818-1 Information technology -- Generic coding of moving pictures and associated audio information: Systems As the specifications are a bit dry and don't really explain the context we suggest you to read them after you are already quite confident with the overall picture, however it's quite useful to have it on your desk to check the exact meaning of every parameter used by OpenCaster that strictly follows the name used in the specification for every variable.
11
http://www.avalpa.com
After the file is saved (F2 then F10) you have to restart the network issuing:
/etc/init.d/networking restart
12
http://www.avalpa.com
next we are showing DtPlay tool usage for output with DVB-T modulator:
DtPlay sample.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
if your server is using a DVB-ASI output you will need to specify the bitrate and command is:
DtPlay sample.ts -r 13271000
Since OpenCaster 2.0 you can also output over IP networking with tsudpsend, a tool for broadcasting using multicast; to manage this you can try: 13 http://www.avalpa.com
The first problem we face is that sample.ts is too short and you won't have enough time to tune and search the service on the set top box so let's introduce a tool: tsloop This tool will put the transport stream file on loop generating a new "endless" stream where the original file sample.ts is repeated.
Tsloop is a very simple tool and will just fix the continuity counter at transport level so there is not a transport error. This is perfect for broadcasting data but not audio and video because at the end of the stream the clock of audio and video will go back in time: Tolerant decoders will detect a time skew on the stream clock and correct their internal clock so you won't see any glitch. Many decoders, however, will have problems with such a simple set-up because they are expecting a progressive video and audio time line and a correct buffer management always progressive and forward-looking, we will address all these issues later on, for now to keep first steps easy remind that every 8 seconds there could be some artefacts due to 14 http://www.avalpa.com
Avalpa Broadcast Server user manual the improper loop and to the modest decoder recovery skills. VLC versions after 0.8.4 are reported to don't work any more with the tutorial files sample.ts and firstvideo.ts because of these reasons so even if VLC works correctly with real set-up of OpenCaster it will fail to show the tutorials. (Check Demonstration chapter for a transport stream that plays correctly on VLC for a longer time) Before using tsloop tool we need to introduce an important concept in OpenCaster operations: the fifo (First In First Out) fifo connections are the way OpenCaster tools pass TS packets to each other, the packets are usually pulled out from the fifo but later on we will see more complex set-ups where pull and push live together. The following command creates a fifo:
mkfifo myfirstfifo.ts
after you can execute tsloop and the play command together:
tsloop sample.ts > myfirstfifo.ts & DtPlay myfirstfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
The '&' at the end of tsloop command is necessary to put the process in background . The tsloop command will wait or the second command to "pull" the data out of the myfirstfifo.ts. You will be able to receive the stream with a dvb-t decoder tuning to 578 MHz, the following pictures show the procedure step by step. Set top box manual scan men reports a signal is locked: the scan finds 1 service: Avalpa 1
15
http://www.avalpa.com
Check the modulation parameters that the decoder is using actually match the one from the command line, the signal status strength is also high.
16
http://www.avalpa.com
you will probably notice a lot of artefacts and the colour bars won't turn smoothly over Avalpa logo, let's check what's happening with some analyser tool.
17
http://www.avalpa.com
We will show, as example, some screenshots from StreamXpert analyzer by Dektec, here they come:
18
http://www.avalpa.com
something seems wrong with the PCR, that's the timing information of the transport stream, there are two reasons for this:
we need to properly manage the loop of the video to avoid the embedded time info to go backward in time sample.ts was a result of a multiplexing without PCR correction,
both problems can be addressed using tsstamp and another fifo connection, so here we go:
mkfifo mysecondfifo.ts tsloop sample.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & DtPlay myfirstfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
As you can see PCR is better now and an error can occur at maximum at the end of the loop, some red lights about Electronic Program Guide are reported, however many decoder will still have problem to decode this stream after the first loop, because a transport stream needs to respect not only transport constraints but also many constraints at elementary stream level on how the end and the start of the streams actually chain together. This kind of constraints are related to the inner elementary streams themselves and are not shown in this analyser that is focused on the transport stream level. We will 19 http://www.avalpa.com
Avalpa Broadcast Server user manual address them later on. As we want to give away tutorial examples for OpenCaster without huge video file downloads we have prepared some loop-able transport streams for the next chapters but don't forget that usually a transport stream is not seamless loop-able on any decoder without some more processing of its elementary streams, advanced chapters will show how to deal with this issue. Pressing the info button on the decoder we figure out what were the last complains of the analyser tool:
the Electronic Program Guide info are missing and time information looks odd! We will fix them later, in the mean time notice that the decoder is so smart to remind us of audio and video PIDs, they will come handy soon...
20
http://www.avalpa.com
N.B. you need to stop tscbrmuxer with a signal (CTRL-C) or it will go on filling your hard disk, that's because input files are looped and muxed.ts is not a fifo. The resulting muxed.ts will have a total bit rate sum up of the the bit rate of all the ts input files that is: 2496916 bit per second. The bit rate of the video stream and of the audio stream comes from the encoder settings, so for now just take them as reported, for the other bit rates will introduce some concepts here. Bit rates are very important, MPEG networks are usually constant bit rate so you will often need to output files at the correct bit rate or you will have a countless number of side effects. How do we know the bit rate of the signalling streams? MPEG, DVB and all the others standards specify the bit rates, you just need to pay attention to a detail: PSI bit rates are expressed as section per second, for example a PAT has to be broadcasted every 500 ms, but a PAT, as all the other sections, can be 1 ts packet up to 23 ts packets depending on its content, so bit rate needs to be changed according to the sections size. Set the bit rate to the maximum allowed is not a wise choice because 99% of the signal tables are usually 1 or 2 packets, so it would result in a big waste of bandwith. Plan carefully your bit-rates when starting the muxing so you won't need to stop it later on, bit-rates can't be changed without artefacts and for the decoders the best way to do this is stop all the muxing and restart. There is still another point to face before you can broadcast the multiplexed .ts, the bit rate of the resulting muxed.ts is not a bit-rate that matches a DVB modulation scheme. How can we fix that? 21 http://www.avalpa.com
Avalpa Broadcast Server user manual An option is to just make some data stream faster or to increase the video bit rate but there is also another choice: add a "NULL PID" filling stream.
tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:10774084 null.ts > sample.ts
A null stream is a stream made of empty packets (0xFF) with fixed PID 8191, to get the required bit rate you need to add a null.ts to the multiplexing with the missing bit rate to reach the required one. In the example there is a massive insertion of null packets, more than 10Mbps but this is just an example! Noticed that also sample.ts from the first tutorial was generated in the same way, just to make thing easier to start. To output the final result use tscbrmuxer instead of tsloop from the previouse example:
mkfifo myfirstfifo.ts mkfifo mysecondfifo.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:10774084 null.ts> myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & DtPlay mysecondfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
On the other hand if you are going to broadcast a TS over an UDP network, where there are no fixed bit rates, you will be better to avoid sending null packets so the final batch will be:
mkfifo myfirstfifo.ts mkfifo mysecondfifo.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 2496916 > mysecondfifo.ts & tsudpsend mysecondfifo.ts 224.0.1.2 7001 2496916
Now you could try to tune this program on the decoder as for the sample.ts the outcome should be the same audio/video. If you are broadcasting on an IP network, any modern pc with VLC will be able to display the stream with an input like: udp://@224.0.1.2:7001 , most of the IPTV set top box should also easily manage it. If you want to record your output you can use the tool tsdoubleoutput:
mkfifo myfirstfifo.ts mkfifo mysecondfifo.ts mkfifo mythirdfifo.ts touch outputcopy.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 2496916 > mysecondfifo.ts & tsdoubleoutput mysecondfifo.ts outputcopy.ts > mythirdfifo.ts & tsudpsend mythirdfifo.ts 224.0.1.2 7001 2496916
Pay attention outputcopy.ts file will grown and fill your hard disk! However we will see that you often want to check your output when you are trying new setups so it is very useful.
22
http://www.avalpa.com
sdt.sec is the section of the sdt, 17 is the well known pid number for the sdt stream. To generate the sdt.sec we need to use a different language called python, have a look at firstsdt.py, here is reported the main part:
[...] # Service Description Table (ETSI EN 300 468 5.2.3) sdt = service_description_section( transport_stream_id = 1, # demo value, an official value should be demanded to dvb org original_network_id = 1, # demo value, an official value should be demanded to dvb org service_loop = [ service_loop_item( service_ID = 1, # demo value EIT_schedule_flag = 0, # 0 no current even information is broadcasted, 1 broadcasted EIT_present_following_flag = 0, # 0 no next event information is broadcasted, 1 yes running_status = 4, # 4 service is running, 1 not running, 2 starts in a few seconds,3 pause free_CA_mode = 0, # 0 means service is not scrambled, 1 means at least a stream is scrambled service_descriptor_loop = [ service_descriptor( service_type = 1, # digital television service service_provider_name = "Avalpa", service_name = "Avalpa 1", ), ], ), ], )
and will generate sdt.sec. You can edit firstsdt.py to change the service_name value and then execute it again to generate the new sdt.sec.
mc -e firstsdt.py
After you located and changed the service name, save the file (F2) exit (F10) and enter the following command:
./firstsdt.py
23
http://www.avalpa.com
Avalpa Broadcast Server user manual this command will generate a new firstsdt.sec, while:
sec2ts 17 < firstsdt.sec > firstsdt.ts
will generate a new firstsdt.ts What will happen to the old one? if you the old firstsdt.ts was being multiplexed the tscbrmuxer will get the new firstsdt.ts as soon as the previous one was sent for the last time. So get back to "Multiplexing a Single Program Transport Stream" set up, replace firstsdt.ts while the processes are running and rescan the service on the box. As you have probably noticed firstsdt.py has a complex structure, that's because it maps 1:1 the original specifications and allows to use all of its signalling. If you look at "ISO/IEC 13818-1" and "EN 300 468" you will find the description of every single table and field, OpenCaster implements the most important of them. Have a look at firstconfig.py for a complete example of signalling, a single python script describes all of the signalling tables you are using, you can split it in more files but a single file is probably easier to edit until you don't need to manage a very complex setup . Take your time to understand it properly and compare it with the specifications of the single tables.
[...] # # Shared values # avalpa_transport_stream_id = 1 # demo value, an official value should be demanded to dvb org avalpa_original_transport_stream_id = 1 # demo value, an official value should be demanded to dvb org avalpa1_service_id = 1 # demo value avalpa1_pmt_pid = 1031 # # Network Information Table # this is a basic NIT with the minimum desciptors, OpenCaster has a big library ready to use # nit = network_information_section( network_id = 1, network_descriptor_loop = [ network_descriptor(network_name = "Avalpa",), ], transport_stream_loop = [ transport_stream_loop_item( transport_stream_id = avalpa_transport_stream_id, original_network_id = avalpa_original_transport_stream_id, transport_descriptor_loop = [ service_list_descriptor( dvb_service_descriptor_loop = [ service_descriptor_loop_item( service_ID = avalpa1_service_id, service_type = 1, # digital tv service type ), ], ), ], ), ], version_number = 1, # you need to change the table number every time you edit, so the decoder
24
http://www.avalpa.com
25
http://www.avalpa.com
], version_number = 1, # you need to change the table number every time you edit, so the decoder will compare its version with the new one and update the table section_number = 0, last_section_number = 0, ) [...]
firstconfig.py ends with system commands invoking sec2ts so they directly generates .ts files without the need to execute manually sec2ts so execute them to generate the psi .ts files.
26
http://www.avalpa.com
Where 4000000 is your initial guess of the bit rate, the tool needs a guess because it will compare the input guess value with the real bit rate giving information about the differences. After the first execution you can try again with the values suggested by the tool. Usually you should just verify that "instant bit rate prints" are quite constant that means the transport stream is not corrupted and can be processed. Sometimes bit rate is not constant because null packets have been removed for storage purpose, in this case null pids need to be reinserted before use. For a better understanding of PCR have a look at Tektronix's "A Layman's Guide to PCR Measurements" A typical print of tspcrmeasure is:
pid 2064, new pcr is 614805912, pcr delta is 676290, (25.047778 ms), indices delta is 41548 bytes, ( 25.568000 ms), pcr accuracy is -0.0005202222, instant ts bit rate is 13269999.5564033184
The first value is the pid number of the pcr/video stream. The second value is the pcr value itself. The third value is the pcr difference from the previous pcr value and in brackets there is the time passed counting the pcr ticks. The fourth value is the difference in bytes from the pcr position into the file and in brackets there is the time passed with the guessed bitrate on input. The fifth value is the accuracy of the predicted pcr. The last value is the actual bit rate measure between pcr ticks and ts bytes. If the transport stream brings PCR information the tool will be able to do the computations otherwise the bit rate information need to be known out-of-band.
27
http://www.avalpa.com
This shot shows the play out system in action, straight from a budget tv set, hence the interlacing, moire' and horizontal scanline artifacts!! Many tv services are just the broadcasting of recorded events, video and films (think business television, hospitality and some satellite channels) . This context is a perfect match for Avalpa Broadcast Server. Using the following tools the broadcaster can avoid expensive real-time systems greatly reducing costs, parts, complexity and the storage needs for the running play out system. To understand the play out system is necessary to understand the tools presented in this section, at the end of the chapter the simplest possible play out is realized with just a few command lines, later on the manual introduces you to a more user friendly web based GUI useful when your scheduling needs get larger. Command line playout is still quite useful also for system integration with other GUIs and CMS are used or STB test environment and so on.
Introduction to ingestion
The most important issue about the ingestion of content is to validate it before 28 http://www.avalpa.com
Avalpa Broadcast Server user manual usage so in the next chapters some analysis' tools are presented to make sure Avalpa Broadcast Server is filled with proper input from the encoders. Audio encoders usually won't present a difficult challenge because their bit rate is constant and frame size is constant too so you will have only to get some parameters from the encoders' configuration and match them with Avalpa Broadcast Server's parameters. Many MPEG2 audio encoders are available on the market, some can run for hours, others for days, some are free others need to be licensed, some are open source others are binary software or hardware. Avalpa Broadcast Server comes with ffmpeg installed with suitable encoders both for andio and video. MPEG2 video Elementary Stream input, however, is a far more complex subject so we need to check them with an analyser tool called vbv (Video Buffer Verifier) that will report problem with the video input doing a decoder buffer simulation. MPEG2 Video can be both Variabile Bit Rate (VBR) or Constant Bit Rate (CBR) however in a digital video broadcasting architecture VBR makes sense only if multiplexers and encoders talk to each other and realize a statistical multiplexing otherwise using a VBR encoding without a statistical multiplexing would be just a waste of bandwidth. As far as we know there is not a standard about statistical multiplexing and every vendor has its own lock-in proprietary protocol between encoders, also statistical multiplexing is valuable only on some context and requirement. Working with pre-encoded files the choice of CBR is a must especially for VOD services but also for scheduled services with small number of live programes. To get your video encoded there are many possibilities, we describe some of the most common: An open source GPL MPEG2 encoder is available inside libavcodec from ffmpeg, you will be able to encode CBR MPEG2 video elementary stream as described in the chapters below without problem check later chapters for details. The mpeg2 reference encoder is also available from mpeg web site but it will probably be more cpu hungry and less effective, other software decoders are available both binary, open source, licensed and/or free. MainConcept licenses software encoders with a CBR TS VBV compliant Video ES for a good price as standalone solution also on Linux workstations or it is available as a plug-in for Adobe Premiere and many other Non Linear Editing (NLE) softwares, even Adobe Premier Elements has a high quality MPEG2 video encoder option. A free trial download from their web site is also available with the only limitation of a watermark. Pay attention however GUIs are not always clear on how to generate a CBR TS. It is worthless to say that any professional broadcasting industrial encoder hardware will be also suitable, then some inexpensive pc hardware has been also reported to work good enough too if configured properly with up-to-date firmware. Anyway in the following pages we will present examples with ffmpeg because it is installed and it has also a quite wide range of supported input formats making the tutorials easier.
29
http://www.avalpa.com
A program elementary stream files will be generated, usually audio or video. pesinfo will report informations about the program elementary streams, usage is simple:
pesinfo videoutput.pes
so you can learn about presentation (PTS) and decoding time stamps (DTS) of the elementary stream of the program stream, for example you can see in the above print that decode time stamp is correctly a bit earlier than presentation time stamp for the same frame. The time is printed as seconds and as 90Hz clock, we will discuss again PTS and DTS later on while discussing synchronization, remember that pesinfo will give you the necessary information. pes2es tool will allow you to extract from a program elementary stream its elementary stream. The tool takes as input a program elementary stream file and a stream header id, you can read the header id using pesinfo as just shown in the example.
pes2es videooutput.pes 224 > video.es
will extract the stream 0xe0 (224), that's a typical video id while typical audio id is 0xc0 (192)
ts2pes firstaudio.ts 2068 > audiooutput.pes pes2es audiooutput.pes 192 > audio.es
30
http://www.avalpa.com
will print out information from the video frames header, here is a typical print of a Group Of Picture (GOP):
[...] Sequence header: format: 720x576, 4:3, 25fps, bitrate: 6.00Mbs, vbv buffer size: 112, constrained: no Sequence header extension: profile is Main, level is Main GOP header: measured size: 344267 bytes, bitrate from measured size (formula has rounds): 5737783.461583bps, drop: no, time code: 00:00:04 pictures:18, closed: no, broken: no frame size: 20490 Postion 3525284, picture 119 start header: temporal reference: 2, picture coding type: I-Frame, vbv delay: 22414 frame size: 78958 Postion 3604242, picture 120 start header: temporal reference: 0, picture coding type: B-Frame, vbv delay: 16539 frame size: 17697 Postion 3621939, picture 121 start header: temporal reference: 1, picture coding type: B-Frame, vbv delay: 18015 frame size: 18223 Postion 3640162, picture 122 start header: temporal reference: 5, picture coding type: P-Frame, vbv delay: 19428 frame size: 30385 Postion 3670547, picture 123 start header: temporal reference: 3, picture coding type: B-Frame, vbv delay: 19382 frame size: 18138 Postion 3688685, picture 124 start header: temporal reference: 4, picture coding type: B-Frame, vbv delay: 20806 frame size: 23426 Postion 3712111, picture 125 start header: temporal reference: 8, picture coding type: P-Frame, vbv delay: 21595 frame size: 29984 Postion 3742095, picture 126 start header: temporal reference: 6, picture coding type: B-Frame, vbv delay: 21597 frame size: 17189 Postion 3759284, picture 127 start header: temporal reference: 7, picture coding type: B-Frame, vbv delay: 23134 frame size: 20719 Postion 3780003, picture 128 start header: temporal reference: 11, picture coding type: P-Frame, vbv delay: 24248 frame size: 30980 Postion 3810983, picture 129 start header: temporal reference: 9, picture coding type: B-Frame, vbv delay: 24130 frame size: 22844 [...]
Some of these parameters are relevant because they will be useful for multiplexing, so let's have a short description of relevant parameters in the next chapter.
Avalpa Broadcast Server user manual compression is achieved by reducing spatial redundancy, but not temporal redundancy. They can be used periodically to provide access points in the bitstream where decoding can begin. 'Predictive' pictures (P-pictures) can use the previous I- or P-picture for motion compensation and may be used as a reference for further prediction. Each block in a Ppicture can either be predicted or intra-coded. By reducing spatial and temporal redundancy, P-pictures offer increased compression compared to I-pictures. 'Bidirectionally-predictive' pictures (B-pictures) can use the previous and next Ior P-pictures for motion-compensation, and offer the highest degree of compression. Each block in a B-picture can be forward, backward or bidirectionally predicted or intra-coded. To enable backward prediction from a future frame, the encoder reorders the pictures from natural 'display' order to 'bitstream' order so that the B-picture is transmitted after the previous and next pictures it references. This introduces a reordering delay dependent on the number of consecutive Bpictures. The different picture types typically occur in a repeating sequence, termed a 'Group of Pictures' or GOP. A typical GOP in display order is:
B1 B2 I3 B4 B5 P6 B7 B8 P9 B10 B11 P12
A regular GOP structure can be described with two parameters: N, which is the number of pictures in the GOP, and M, which is the spacing of P-pictures. The GOP given here is described as N=12 and M=2. MPEG-2 does not insist on a regular GOP structure. For example, a P-picture following a shot-change may be badly predicted since the reference picture for prediction is completely different from the picture being predicted. Thus, it may be beneficial to code it as an I-picture instead. For a given decoded picture quality, coding using each picture type produces a different number of bits. In a typical example sequence, a coded I-picture was three times larger than a coded P-picture, which was itself 50% larger than a coded B-picture. The number after the picture type is the temporal reference inside the single GOP. On broadcasting environment an external additional constraint comes from the user acceptable zapping time because a decoder needs to wait an I picture to start displaying the video so the usual number of GOP size for broadcasting is 12, less than half a second at 25 frames per second: (12 * 1/25 = 0.48 sec.) Closed gop have a different sequence, they start with an I picture with time reference 1 and allow them to be the start of an encoded video. This peculiar GOP feature allows also GOP to be chained without re-encoding the video, we will get on this topic later on.
Tool vbv
Another interesting tool is "vbv", that's Video Buffer Verifier, the tool tries to simulate a 32 http://www.avalpa.com
will print underrun and overrun of the buffer if they happen or stay quiet if the video stream respects the limits reporting found 0 errors at the end. If vbv reports error it is a hint that the video was encoded with a bit rate that's not enough constant. N.b. this tool is a simulator that tries to be strict, sometime a video stream happens to work properly on real decoders (as they should be far more tolerant) even if vbv reports errors. It can also happen a video won't work properly even if vbv doesn't complain because buffer fullness is not the only important issue for a proper playback, the vbv tool fills the buffer at a constant bit rate (CBR) but on real transmission the model may look more like many small burst getting an average cbr-ness, if the burstiness is not properly managed a vbv complaint stream will fail to be decoded correctly. Vbv information is also collected in a log file vbvData.dat that can be plotted with the command:
gnuplot plot.p
the plot.p file is available in the directory Opencaster.version/tools/vbv, the result looks like:
The Y is reporting the vbv buffer fullness while X is reporting the time in frame number. gnuplout let you zoom in an area using right click so you can analyse peaks and everything else.
33
http://www.avalpa.com
MPEG-1 Audio Layer II is an audio codec defined by ISO/IEC 11172-3. While MP3 is much more popular for PC and internet applications, MP2 remains a dominant standard for audio broadcasting. Understanding mpeg audio compression features is beyond our interest but to multiplex audio you will need to know some of the information printed here: bit rate, sampling rate and frame size. Sampling rate is the number of samples present in 1 second, that's why is expressed in Hz, while frame size is the dimension in bytes of all the audio frame. 48000 Hz is quite a common sample rate but also others are supported. Knowing frame size and bit rate you can figure out how long the frame lasts and how many samples it brings with the sampler rate information. Summary: to analyse an audio stream from a input.ts you will need the following commands:
[...] ts2pes input.ts audiopid > audiooutput.pes pes2es audiooutput.pes stream_id_usually_192 > audiooutput.es esaudioinfo audiooutput.es [...]
34
http://www.avalpa.com
-i input file, that can be video file supported by ffmpeg decoding -an no audio, if audio is present in the input it will be ignored -vcodec video codec, mpeg2video is the video codec we are looking for mpeg2 video -f output format, this mpeg2video is the output file format we are looking, elementary stream video -b, -maxrate, -minrate bitrate in kbps, that's depend on you, pay attention some version of ffmpeg use kbps as input, others bps so you need to add zeros -bf number of b-frame for gop -bufsize vbv buffersize, the version of ffmpeg used while writing this document is expecting the buffer size in bit, so it's vbv_buffer_size * 1024 * 16: 1835008, however in many encoders vbv for mpeg 2 video codec is often expressed in 16Kbits unit. Be sure to check the output with esvideoinfo and vbv as explained in "Analysing video files", when you are done with encoding you will need to do encapsulation, ffmpeg actually has an option to output elementary stream encapsulated into transport stream but as of this writing it's totally broken. You can encapsulate the video elementary stream into program stream with esvideo2pes like this:
esvideo2pes video.mp2 > video.pes
2064 is the video pid. 25 is the frame per second, 112 half vbv (on many decoders 224 is fine, others have half of it because DVD uses half and sometimes it happens also DVB decoder get the same limitation), 5270000 is the ts bit rate, it has to be bigger than the video bit rate, automatic minimum guess is still not available on the software, 15% more should be fine; the tool will adjust the pts and the dts to take into account first frame transmission delay. To improve the quality and compression of the video is suggested to use yuvdenoise tool, as shown below:
fmpeg -i input.ext -an -s 720x576 -deinterlace -r 25 -aspect 4:3 -f yuv4mpegpipe - | yuvdenoise | ffmpeg -i - -an -vcodec mpeg2video -f mpeg2video -b 2000k -maxrate 2000k -minrate 2000k -bf 2 -bufsize 1343488 video.mp2
35
http://www.avalpa.com
You can encapsulate the audio into ps with esaudio2pes like this:
esaudio2pes audio.mp2 1152 48000 768 3600 > audio.pes
48000 sample rate, should be known or can be learn with esaudioinfo, a pts_step is 1152 / sample_rate * 90000, 1152 is fixed for mpeg2 layer 2 so for 48khz comes 2160 1152 audio frame size, you can read it with esaudioinfo, it's in bytes (NB this 1152 is by chance 1152 as the number of samples) 3600 first pts, this an important value for audio/video synchronization, read more below. You can analyse the output with:
pesinfo audio.pes
2068 is the pid number 1152 is the number of sampler per frame 48000 is the sample rate 768 is the es frame size 3600 first pts, this an important value for audio/video synchronization, read more below. 0 the audio won't be on loop, again this is for future usage constant bit rate. To calculate the output bit rate steps are: 1 second is 90000 pts ticks, sample rate is 48000 hz, 1 frame is 1152 samples. so: 36 http://www.avalpa.com
Avalpa Broadcast Server user manual (90000 * 1152) / 48000 = 2160 is how many ticks is a frame an audio pes frame is made for example of 384 byte so this means 384/184 = 2.08 TS packets, with padding on third packet so 3 packets * 188 bytes = 564 bytes = 4512 bit per pes audio frame. 4512 bit for 2160 ticks you convert with bps it comes: (4512 * 90000) / 2160 = 188000 bps When bit rate is not round, you should consider using the floor integer.
37
http://www.avalpa.com
But this way it will never stop recording, so to stop it you can use ctrl+c or use a duration time:
dvgrab -d 3:30:10 recorded.dv
will record for 3 hours, 30 minutes and 10 seconds, here is other time specification supported:
SMIL time value: XXX[.Y]h, XXX[.Y]min, XXX[.Y][s], XXXms, [[HH:]MM:]SS[.ms] smpte=[[[HH:]MM:]SS:]FF
The resulting recordDV.avi file can be converted as explain in previous chapter into audio and video streams. The next chapter will show a complete ingestion from DVD data available on the net, you can replace the vob file with your DV file and execute the same steps You can also connect DVGrab directly into ffmpeg and then directly to a playout:
dvgrab -format dv1 - | /home/avalpa/ffmpeg/ffmpeg -f dv -i - -acodec mp2 -ac 2 -ab 128000 -ar 48000 -f mp2 -y live.mp2 -s 720x576 -deinterlace -r 25 -aspect 4:3 -f yuv4mpegpipe -y - | /home/avalpa/mjpegtools-1.9.0/yuvdenoise/yuvdenoise | /home/avalpa/ffmpeg/ffmpeg -i - -an -vcodec mpeg2video -f mpeg2video -b 2000k -maxrate 2000k -minrate 2000k -bf 2 -bufsize 1343488 -y live.mpv
38
http://www.avalpa.com
wget http://video.blendertestbuilds.de/topdir/ED/movie_only_pal.iso
wget will download the .iso of Elephant Dreams short and the following command will encode audio and video adding an external logo and enabling the initial synchronization.
sudo mount -o loop movie_only_pal.iso /mnt/ ffmpeg -vn -ab 128k -ar 480000 -i /mnt/VIDEO_TS/VTS_01_1.VOB -acodec mp2 -ac 2 ed.mp2 ffmpeg -i /mnt/VIDEO_TS/VTS_01_1.VOB -an -vhook 'vhook/imlib2.so -F /usr/share/fonts/truetype/freefont/FreeSansBold.ttf/16 -x 0 -y 0 -i /home/avalpa/OCTutorial10/logo_tv.png' -f mpeg2video -vcodec mpeg2video -b 2600k -maxrate 2600k -minrate 2600k -bf 2 -bufsize 1835008 -aspect 4:3 ed.m2v sudo umount /mnt esvideo2pes ed.m2v 1> ed.video.pes 2> ed.pes.length esaudio2pes ed.mp2 1152 48000 384 3600 > ed.audio.pes
39
http://www.avalpa.com
Avalpa Broadcast Server user manual The file ed.pes.length is generated by esvideo2pes and it's the length of the video in PTS ticks, in this case we will get that ed.pes.length is 57286800, ticks of 90Khz so 1 frame is 90000/25 frame per second = 3600 pts ticks and 57286800/3600 = 15913 frames / 25 fps = 636.52 seconds of video We need to compare this with the audio length to ensure the audio is a little shorter than the video, this is the only requirement to chain two videos encoded as just described! ed.audio.pes size is 10530284, 1 frame is 1152 sample and sample rate is 48000 so 10530284 / (384+14) = 26458 frames * 1152 / 48000 = 634.992 seconds of audio In this case audio is shorter so there is no problem, otherwise:
esaudio2pes ed.mp2 1152 48000 384 3600 57286800 > ed.audio.pes
would have cut the audio before the end of the video. To have some video clips for the playout you should repeat the same commands for another short Big Buck Bunny (the second release still courtesy from the Blender Foundation), available from: http://www.archive.org/details/BigBuckBunny To match our set up in the next chapters you should encode VTS_05_1.VOB and
VTS_02_1.VOB
40
http://www.avalpa.com
This will output three files with audio and video connected seamlessly, please notice some points about why this works: ed, bb and bb2 have all the same bandwidth both audio and video and all the bandwidths are CBR
the first GOP of every video is closed pesvideo2ts controls vbv fullness all the time and also on the switch between streams.
Basically the prints report about the tools closing the previous files and opening the new files however something fishy is going on because we read that:
bb.audio.pes new presented audio frame will be at 57164400, 635.1600 sec. bb.video.pes new presented video frame is at: 57290400, 636.5600 sec.
We are out of synchronization! The first value is the time in PTS ticks (90 KHZ) the second is the first time in seconds (57164400 / 90000). This problem is also signalled by a warning message: 41 http://www.avalpa.com
we specified that the audio file must be generally shorter than the video file however for pesaudio2ts to know about how much short it is the audio compared to the video it needs additional information files: ed.audio.pes.length, bb.audio.pes.length and bb2.audio.pes.length that are the same files we generated while encapsulating the video files to pes in the previous chapter so just rename them as:
mv bb.pes.length bb.audio.pes.length mv bb2.pes.length bb2.audio.pes.length mv ed.pes.length ed.audio.pes.length
and restart the whole processes, after the first video you will correctly read that both pesaudio2ts and pesvideo2ts report the exact PTS that is going to be the first frame. of the incoming video:
pesaudio2ts: closing ed.audio.pes... closed pesaudio2ts: opening bb.audio.pes... open pesaudio2ts sync: bb.audio.pes new presented audio frame will be at 57290400, 636.5600 sec., last presented audio frame was at 57161520, 635.1280 sec. pesvideo2ts: closing ed.video.pes... closed pesvideo2ts: opening bb.video.pes... open pesvideo2ts sync: bb.video.pes new presented video frame is at: 57290400, 636.5600 sec., decode time stamp is at: 57286800, 636.5200 sec.
To recover from an out of synchronization after it is signalled you will need to do some mathematics and add at the current.audio.pes.length value the missing time so that while passing to the new stream from the current the synch is gained. In the next pages a gallery of some screen shots from different analysers is shown:
42
http://www.avalpa.com
43
http://www.avalpa.com
44
http://www.avalpa.com
45
http://www.avalpa.com
Avalpa Broadcast Server user manual Now another step towards a more flexible play out system: what if we want to change our schedule after it started? We can do that easily with some symbolic linking, suppose that instead to use file names we use symbolic links:
ln -s ed.audio.pes audio1.pes ln -s ed.video.pes video1.pes ln -s ed.audio.pes audio2.pes ln -s ed.video.pes video2.pes ln -s ed.audio.pes audio3.pes ln -s ed.video.pes video3.pes pesvideo2ts 2064 25 112 2900000 1 video1.pes video2.pes video3.pes > video.ts & pesaudio2ts 2068 1152 48000 384 1 audio1.pes audio2.pes audio3.pes > audio.ts &
To change a scheduled file we just need to change the symbolic link before it starts to be play:
rm rm ln ln audio2.pes video2.pes -s bb.audio.pes audio2.pes -s bb.video.pes video2.pes
With this last set up we can script the schedule of contents as long as we care, however check the manual later on for APE a web based GUI already able to schedule videos with a user friendly interface. APE also uses scripting and scripting is going to be a stable feature of Avalpa Broadcast Server because it is essential while integrating with third parties Content Management System.
46
http://www.avalpa.com
Pesclock get as inputs a couple of 0 that we will discuss later and a sequence of .pes files. The first pes file of every couple is copied in the second pes file but in the meanwhile pesclock is keeping track of the time passed for every pes. Here is where the first parameter comes to action, if let to 0 pesclock will just monitor and the behaviour will be like it doesn't exists but if a PTS time is passed as first parameter pesclock will stop. In the following example 2 minutes, 2*60 120 seconds, * 90000, 10800000 PTS ticks is used to stop every video after 2 minutes from its start (remove any .length file if present in the directory)
mkfifo video.ts mkfifo audio.ts mkfifo muxed.ts mkfifo stamped.ts mkfifo audio0.pes mkfifo audio1.pes mkfifo audio2.pes mkfifo video0.pes mkfifo video1.pes mkfifo video2.pes pesclock 10800000 0 ed.video.pes video0.pes ed.audio.pes audio0.pes & pesclock 10800000 0 bb.video.pes video1.pes bb.audio.pes audio1.pes & pesclock 10800000 0 bb2.video.pes video2.pes bb2.audio.pes audio2.pes & pesvideo2ts 2064 25 112 2900000 1 video0.pes video1.pes video2.pes > video.ts & pesaudio2ts 2068 1152 48000 384 1 audio0.pes audio1.pes audio2.pes > audio.ts & tscbrmuxer b:2800000 video.ts b:188000 audio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:10174084 null.ts > muxed.ts & tspcrstamp muxed.ts 13271000 > stamped.ts & DtPlay stamped.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
As you can see the synch is fine, but it complains about the missing .length file, this is ok because the synchronization is guaranteed by pesclock so pesaudio2ts shouldn't have a .length file. 47 http://www.avalpa.com
Avalpa Broadcast Server user manual Another feature of pesclock is to interrupt the video at an unspecified time, that's why it read on a given udp port for a signal, the port number is the second parameter of pesclock:
pesclock 10800000 7000 ed.video.pes video0.pes ed.audo.pes audio0.pes
This pesclock will end after two minutes or earlier if a command like this is given:
netcat -u here.goes.play.out.ip.address 7000
48
http://www.avalpa.com
49
http://www.avalpa.com
EPG
[OCTutorial4] An interesting signalling is the EIT, Event Information Table, these tables are received by the box and used to generate the Electronic Program Guide. Have a look at eitconfig.py, it is a template, so you'll need to change the date and the time from the python config to your current time so the decoder will show the events as they are coming in a short time.
[...] # # Event Information Table (ETSI EN 300 468 5.2.4) # eit = event_information_section( table_id = EIT_ACTUAL_TS_PRESENT_FOLLOWING, service_id = avalpa1_service_id, transport_stream_id = avalpa_transport_stream_id, original_network_id = avalpa_original_transport_stream_id, event_loop = [ event_loop_item( event_id = 1, start_year = 108, # since 1900 start_month = 6, start_day = 10, start_hours = 0x00, # use hex like decimals start_minutes = 0x00, start_seconds = 0x00, duration_hours = 0x23, duration_minutes = 0x00, duration_seconds = 0x00, running_status = 4,#service is running,1 not running,2 starts in a few seconds,3 pause free_CA_mode = 0, # service is not scrambled, 1 means at least a stream is scrambled event_descriptor_loop = [ short_event_descriptor ( ISO639_language_code = "ita", event_name = "epg event name", text = "this is an epg event text example", ) ], ), ], version_number = 1, section_number = 0, last_section_number = 1, # pay attention here, we have another section after this! ) eit_follow = event_information_section( table_id = EIT_ACTUAL_TS_PRESENT_FOLLOWING, service_id = avalpa1_service_id, transport_stream_id = avalpa_transport_stream_id, original_network_id = avalpa_original_transport_stream_id, event_loop = [ event_loop_item( event_id = 2, start_year = 108, # since 1900 start_month = 06, start_day = 10, start_hours = 0x23, start_minutes = 0x30,
50
http://www.avalpa.com
To add EPG to your set up you will need to add the firsteit.ts to your muxing and it would be wise also to signal a time info. That's what tstdt tool is for. tstdt is a tool that set the time of the service, this is just a hint for the decoders user clock and doesn't affect any low level buffer synchronization issue, the time is read from the pc clock. The usage is very simple:
tstdt inputs.ts > output.ts
The input ts needs to already have stub tdt packets inserted at multiplexing time so the tool will replace them with packets at the current time. Pay attention that if you are processing the transport stream faster than realtime I.e. with a rate higher then the own bit rate you are going to write into the hard disk a tdt time information quite meaningless.
mkfifo fifomuxed.ts mkfifo fifotdt.ts mkfifo fifotsstamp.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:2000 firsteit.ts b:2000 firsttdt.ts b:10770084 null.ts > fifomuxed.ts & tstdt fifomuxed.ts > fifotdt.ts & tsstamp fifotdt.ts 13271000 > fifotsstamp.ts & DtPlay fifotsstamp.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
51
http://www.avalpa.com
52
http://www.avalpa.com
All green lights! This is as we like it most, as you can see there are no more errors because the last red lights were about missing EIT and TDT, tables.
53
http://www.avalpa.com
The clip files are very short and with a very small bit rate, many decoders can have problems decoding channel 2 and channel 3, channel 1 should play smooth on all decoders, this can also be a test on your mpeg2 decoder recovery capabilities. A problem arises because the videos are looped and so, from the point of view of the decoder, the PCR goes back in time after the end of the first loop when we come back playing the same ts loop a second time; you can try to fix PCR using tsstamp like here:
tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:2300000 secondvideo.ts b:188000 secondvideo.ts b:2300000 thirdvideo.ts b:188000 thirdaudio.ts b:3008 mptspat.ts b:3008 mptspmt1.ts b:3008 mptspmt2.ts b:3008 mptspmt3.ts b:1400 mptsnit.ts b:1500 mptssdt.ts b:5792069 null.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & /usr/local/bin/DtPlay mysecondfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
54
http://www.avalpa.com
55
http://www.avalpa.com
56
http://www.avalpa.com
Finally let's check the analyser again for the services and their PCR:
57
http://www.avalpa.com
Now you are ready to use tscrypt, the basic usage is:
tscrypt input.ts file.cw > crypted.ts
the input transport stream will be crypt using control words from file.cw, those are 8 bytes twice, odd and even keys, it is a perfect match for a biss cam. The PSI signalling required is carried out in the pmt:
pmt = program_map_section( program_number = avalpa1_service_id, PCR_PID = 2064, program_info_descriptor_loop = [], stream_loop = [ stream_loop_item( stream_type = 2, # mpeg2 video stream type elementary_PID = 2064, element_info_descriptor_loop = [ ca_descriptor ( CA_system_ID = 0x2600, CA_PID = 0x1FFF, ), ] ), stream_loop_item( stream_type = 4, # mpeg2 audio stream type elementary_PID = 2068, element_info_descriptor_loop = [ ca_descriptor ( CA_system_ID = 0x2600, CA_PID = 0x1FFF, ), ] ), ],
58
http://www.avalpa.com
The control word used is 0x00 0x00 0x00 0x00 0x01 0x02 0x03 0x6 This won't be enough to support any available CAS system but OpenCaster is also able to signal ECM, EMM and CAT in the same way as described for the others PSI/SI shown in the previous examples so the support is quite complete.
The scrambling processing is quite computational expensive so pay attention to your cpu usage.
59
http://www.avalpa.com
IP network tools
[OCTutorial1] OpenCaster 2.0 for the first time featured some tools to send a transport stream over an IP network and their usage is very simple to exploit. As in every real word problem, there are some issues you should be concerned of. Let's see an example:
tstcpreceive 7001 > received.ts Binding the socket...
This command will start a process waiting for an incoming connection on port 7001 that can be made from another pc:
tstcpsend sample.ts 192.168.1.2 7001 3000000
Where the parameters are the transport stream to send, the destination ip address and port and the bit rate of the transfer. The first thing to keep in mind is that the bit rate is the transport stream bit rate and not the ip packets bit rate . As far as there is enough bandwidth the file will be transferred and due to the TCP properties we won't miss any packet. Another option is to use UDP packets instead of TCP but this implies that same packet could be lost or repeated so there is no guarantee that a transport stream received from an UDP stream is going to be error-free and so it's a risk to use UDP as a contribution link between OpenCaster tools without implementing some recovery strategy. The main reason to send a transport stream over UDP is to enable multicast for end user distribution; the decoder receiving the stream will implement the necessary algorithms of error-concealment to manage packet loss while decoding the stream in the same way it recovers from broadcast errors for weak signal conditions.
60
http://www.avalpa.com
Teletext support
[OCTutorial7] This tutorial describes support for digital teletext generation and multiplexing. To describe how does teletext works and its packets layout is out of this document but we will address how teletext packets are encapsulated into transport stream. Once a receiver decoded the packets has two choices not exclusive: modulate the teletext signal into an analog video output and/or render the teletext as on screen graphics, however when the video output is HDMI, the only way to support teletext for the decoder is on screen graphics because up to now HDMI is not supporting in band teletext. Teletext packets are generated by pythons scripts presented later, let's suppose we have some teletext packets stored in one file, we will present two utilities that take care of the forthcoming process: txt2pes and pesdata2ts:
txt2pes pages.txt 15 3600 1800 > txtpage.pes &
Txt2pes will generate PES packets from TXT packets, the first parameter 15 is how many TXT packets should be inserted in a single PES packet. This information is related to the PES packet time information and also bit rate. Teletext has maximum number of packet per frame that is actually split in halft per field. 3600 is the number of PTS clocks for the first PES packet while 1800 is the increment of the PTS clock every PES packet, 1800 is actually 50 PES packet per second, so the result is the command line states that every 15 TXT packet a new PES packet will be generated and every PES packet matches a video field.
pesdata2ts txtpage.pes 1978 > txt.ts &
Pesdata2ts, the second tool we are using, will just encapsulate PES packets in TS packet with the given PID, in this case is 1978. To know the bit rate for the teletext transport stream math is easy, after starting to execute txt2pes it will report about PES packet size, for example: pes packet size without 6 byte header is 1144 this means: 1144 + 6 = 1150 bytes per packet 1150 / 184 (TS packet payload) = 7 TS packet every PES packet 7 * 188 * 8 -> 10528 per PES if PES goes at 3600 means: 10528 * (90000 / 3600) -> 263200 bps For the previous example we have: 730 + 6 -> 736 / 184 -> 4 * 188 * 8 -> 6016 * (90000 / 1800) -> 300800 bps So the final processes layout assuming the teletext packets are already generated and 61 http://www.avalpa.com
The tutorial is transmitting 4 pages: 100, 202, 302 and 404 Page 100 has also fast link for the others pages connected to colour keys. The final look is:
About the teletext packet generation it can be done with python libraries but requires knowledge of the teletext itself. Basic information is presented here and will allow you to properly display text only pages.
62
http://www.avalpa.com
63
http://www.avalpa.com
Avalpa Broadcast Server user manual Every pages is made of teletext packets, each packet is an unit. The first packet is the header line packets and looks like this:
EBUTeletext( data_unit_id = 0x02, # 0x02 non-subtitle, 0x03 subtitles, 0xFF field_parity = 01, # which field odd or even? line_offset = 0x7, # this is the first useful analog line to insert magazine = 0x04, # here we describe page 404 row = 0x00, # 24 (0x17) lines per magazine, 0 is the page header page = 0x04, subpage = 0x0000, erase_page = 0, # no special request for this page newsflash = 0, subtitle = 0, suppress_header = 0, update_indicator = 1, interrupted_sequence = 0, inhibit_display = 0, magazine_serial = 1, country_code = 0x03, chars = " Avalpa-TXT 10 04 2009 15 00" # the header itself
),
Packets belonging the the page will report only the magazine number 4, so this can lead to wrong pages is some pes packets are lost, anyway a typical teletext text line looks like:
EBUTeletext( data_unit_id = 0x02, field_parity = 01, line_offset = 0x8, magazine = 0x04, row = 0x01, # the first teletext page row line, just after the header chars = " A_404_1 " + " A_404_1 " , ),
64
http://www.avalpa.com
DVB-SSU
[OCTutorial8] The tutorial shows how to set-up a DVB-SSU update with OpenCaster. Many parameters regarding the client configuration are needed to be inserted so it's not expected to work out of the box for any decoder, it's just a skeleton useful for real use cases. Contact [email protected] for more details. To signal DVB-SSU you need to add a linkage descriptor to NIT, have a look to ssu-datageneration.py
nit = network_information_section( network_id = 1, network_descriptor_loop = [ network_descriptor(network_name = "Avalpa",), linkage_descriptor( transport_stream_id = avalpa_transport_stream_id, original_network_id = avalpa_original_transport_stream_id, service_id = 1, linkage_type = 0x09, OUI_loop = [ OUI_data ( OUI = 0x15A, # any OUI selector_bytes = "", ) ], private_data_bytes = "", ), ],
65
http://www.avalpa.com
Avalpa Broadcast Server user manual It is also necessary to add the dsmcc descriptor to the pmt:
pmt = program_map_section( program_number = avalpa1_service_id, PCR_PID = 8191, program_info_descriptor_loop = [], stream_loop = [ stream_loop_item( stream_type = 11, # data stream type elementary_PID = avalpa1_dsmcc_pid, element_info_descriptor_loop = [ stream_identifier_descriptor( component_tag = dsmccB_association_tag, ), ] ) ],
For using more advanced DVB-SSU you will also need another descriptor in the pmt regarding a new table, the UNT:
pmt = program_map_section( program_number = avalpa1_service_id, PCR_PID = 8191, program_info_descriptor_loop = [], stream_loop = [ stream_loop_item( stream_type = 11, # data stream type elementary_PID = avalpa1_unt_pid, element_info_descriptor_loop = [ data_broadcast_id_descriptor( data_broadcast_ID = 0x000A, # DVB-SSU OUI_info_loop = [ OUI_info_loop_item ( OUI = anyOUI, update_type = 0x02, # with broadcasted UNT, 0x01 without UNT: it requires a stream_identifier_descriptor update_versioning_flag = 0, # no version change update_version = 1, # increment this at update change selector_bytes = "", ), ], private_data_bytes = "", ), ] ), stream_loop_item( stream_type = 11, # data stream type elementary_PID = avalpa1_dsmcc_pid, element_info_descriptor_loop = [ stream_identifier_descriptor( component_tag = dsmccB_association_tag, ), ] ) ],
DVB-SSU carousel is simpler than MHP and MHEG5 and just requires each file to be transmitted to be specified as a module, the last part of ssu-data-generation.py configuration file shows how to specify them, for a complete description of values check: ETSI TS 102 006
66
http://www.avalpa.com
Finally a script will take care of convert all the generated sections to a transport stream file:
./ssu-update.sh datacarousel 2003 0
The script file gets the sections generated by ssu-data-generation.py a converts them to transport stream using sec2ts 67 http://www.avalpa.com
Avalpa Broadcast Server user manual The last part is the usual multiplexing carried out with these commands:
tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:1000000 datacarousel.ts b:9774081 null.ts > fifomuxed.ts & tstdt fifomuxed.ts > fifotimed.ts & tspcrstamp fifotimed.ts 13271000 > fifostamped.ts & DtPlay stamped.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 514 &
68
http://www.avalpa.com
Interactive TV support
Interactive television standards usually requires a data casting more complex than dvb-ssu so instead to describe modules one by one as shown in ssu-data-generation.py followed by ssu-update.sh an automatic tool will take care of all the processing:
Tool oc-update.sh
Usage:
oc-update.sh object_carousel_directory association_tag module_version dsmcc_pid carousel_id [compress_on] [padding_on] [clean_off] carousel_directory: the directory to marshal in an object carousel association_tag aka common tag: is referenced by PMTs and AITs, every carousel has its own, values is hex (check Application signalling chapter for more information) modules_version: all the modules will have the same version, you need to change this if you want to change the carousel content and to notify to the box files are changed, goes from 0 to 15 pid: the pid of the transpor stream that will be generated carousel_id: referenced by PMTs using this carousel, every carousel has its own (check Application signalling chapter for more information) compress_on, compress the carousel, default off padding_on, every section is padded, usuful with some buggy decoder, waste bandwith, default off clean_off, don't delete temp file, default off
will generate ocdir1.ts than can be muxed to all the other transport stream files, the parameters passed specifies that:
the carousel directory to marshal is: ocdir1 the association_tag to use for PMT and AIT is: 0xB (11) the version of the modules and sections of the carousel is: 5 the pid of the stream is: 2003 the id of the carousel to use in the PMT is: 1
and finally: the carousel will be compressed, without padding and temp files deleted Running again the command with a different version number will generate a new ocdir1.ts marshalling again the directory
oc-update.sh ocdir1 0xB 6 2003 1 1 0 0
MHP/MHEG5 signalling
[OCTutorial9]
69
http://www.avalpa.com
Avalpa Broadcast Server user manual Now that we have learnt how to marshal a file system, the big thing is that in the file system we can bring to an interactive decoder the applications. We need to insert the Application Information Table signalling if we want the MHP decoders to be aware of applications and we also need to properly set up DSMCC references. The complete basic workflow at decoder side for receiving applications is: 1) the MHP/MHEG5 decoder tunes the channel 2) the MHP/MHEG5 decoder parses PAT and PMT 3) the MHP decoder parses the AITs signalled by the PMT 4) the MHP decoder presents to the user the application list got from the AITs (it can be necessary to press the "app" button on the remote control) 5) the user selects an application 6) the MHP/MHEG5 decoder loads the DSMCC carousel referenced by the application descriptor 7) the MHP/MHEG5 decoder executes the application So let's have a look at mhpconfig.py on how to active this, first of all the PMT for the required referencing of AIT and DSMCC streams looks like this:
# # Program Map Table (ISO/IEC 13818-1 2.4.4.8) # this is PMT with DSMCC and AIT descriptor for MHP interactive applications # pmt = program_map_section( program_number = avalpa1_service_id, PCR_PID = 2064, program_info_descriptor_loop = [], stream_loop = [ stream_loop_item( stream_type = 2, # mpeg2 video stream type elementary_PID = 2064, element_info_descriptor_loop = [] ), stream_loop_item( stream_type = 3, # mpeg2 audio stream type elementary_PID = 2068, element_info_descriptor_loop = [] ), stream_loop_item( stream_type = 5, # AIT stream type elementary_PID = 2001, element_info_descriptor_loop = [ application_signalling_descriptor( application_type = 1, # 1 DVB-J application, 2 DVB-HTML AIT_version = 1, # current ait version ), ] ), stream_loop_item( stream_type = 11, # DSMCC stream type elementary_PID = 2003, element_info_descriptor_loop = [ # a number of descriptors specifying DSMCC properites association_tag_descriptor( association_tag = 0xB, # this association tag identifys the carousel, it is used also while generating the DSMCC with oc-update.sh and referenced by the AIT use = 0, # some default values follow, don't change them selector_lenght = 0, # ... transaction_id = 0x80000000, # ...
70
http://www.avalpa.com
), stream_identifier_descriptor( component_tag = 0xB, # it is the same as the assocation tag, some decoders will look for the component tag, others for the association tag, the same value should be used ), carousel_identifier_descriptor( carousel_ID = 1, # carousel id number, it's a different number from association/ component tag, but it has a similiar purpouse: identifying the carousel format_ID = 0, # no enhanced boot supported private_data = "", ), data_broadcast_id_descriptor( data_broadcast_ID = 240, # 240 is the code specifying this is DSMCC-MHP , 262 for mheg5 ID_selector_bytes = "", # for mheg5 you need selector bytes "\001\001\000\000", ), ] ) ], [...]
N.B. To add another AIT stream or another DSMCC you will have to add more stream_loop_items ! In mhpconfig.py you can also find an AIT example that will generate an firstait.ts transport stream file, let's have a look at it:
# Application Informaton Table (ETSI TS 101 812 10.4.6) ait = application_information_section( application_type = DVB_J_application_type, common_descriptor_loop = [], application_loop = [ # here we list only 1 application, adding another application loop item will signal a second application in the sam AIT, you can signal applications in the same AIT or more AITs application_loop_item( organisation_id = 10, # this is a demo value, dvb.org should assign an unique value application_id = 1001, # should be unique for every organisation id in the same program application_control_code = 2, # is PRESENT, the decoder will add this application to the user choice of application, 1 is AUTOSTART, the application will start immedtiatly to load and to execute, 3 is DESTROY, it will signal to the application to stop executing, is KILL, it will stop execute the application application_descriptors_loop = [ transport_protocol_descriptor( protocol_id = MHP_OC_protocol_id, # the application is broadcasted on MHP-DSMCC transport_protocol_label = 1, # carousel id remote_connection = 0, component_tag = 0xB, # carousel common tag and association tag ), application_descriptor( application_profile = 0x0001, # Profile and MHP version version_major = 1, version_minor = 0, version_micro = 2, service_bound_flag = 1, # the application is expected to die on service change, 0 will wait after the service change to receive all the AITs and check if the same app is signalled or not visibility = 3, # the applications is visible to the user, 1 the application is visible only to other applications application_priority = 1, # is lowset, when more than 1 app. is executing transport_protocol_labels = [1], # carousel Id ), application_name_descriptor(application_name = "Text input example"), dvb_j_application_descriptor(parameters = ["dvb://1/sample8"]), # xlet parameters dvb_j_application_location_descriptor( base_directory = "/", # base directory, if set to "/hello" the xlet will act as "/hello" is its root directory
71
http://www.avalpa.com
], ) [...]
),
],
),
Now execute:
./mhpconfig.py
to generate ocdir1.ts so you are ready to multiplex your first Single Program Transport Stream with an interactive application:
tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:1000000 ocdir1.ts b:2000 firstait.ts b:9772084 null.ts> myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & DtPlay mysecondfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
Now, to test it, proceed to the decoder tuning and select the example application:
72
http://www.avalpa.com
73
http://www.avalpa.com
when the multiplexing is running and wait a few moments, here how it looks after update:
74
http://www.avalpa.com
This event has id 1 and brings some private date in the payload: "event 1 private data". This event is a Do It Now Event, the only kind of stream event supported by OpenCaster and actually the only one supported among all MHP decoders. "Do It Now" means that as soon as the decoder receive the event it should be sent to the applications waiting for it.
75
http://www.avalpa.com
Avalpa Broadcast Server user manual To have the demo running execute:
./mhpconfig2.py oc-update.sh ocdir1 0xB 5 2003 1 1 0 0 oc-update.sh ocdir2 0xC 5 2004 2 1 0 0 tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:1000000 ocdir1.ts b:1000000 ocdir2.ts b:2000 firstait.ts b:2000 firstste.ts b:8770084 null.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & DtPlay mysecondfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578
Now you can tune the decoder and look for the application "Test Stream Event":
If you execute the application, it will start and wait for the Stream Event:
76
http://www.avalpa.com
77
http://www.avalpa.com
Avalpa Broadcast Server user manual If you didn't notice the multiplexing is using also a firstste.ts file, this file was generated by ./mhpconfig2.py and contains the events themselves sent in a loop. Obviously this is not the usual behaviour because you don't want to send stream event from the very beginning, so you will need to initially mux a null.ts instead of firstste.ts and replace the stream when it's the right time to send the event:
cp null.ts tempste.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:3008 firstpat.ts b:3008 firstpmt.ts b:1500 firstsdt.ts b:1400 firstnit.ts b:1000000 ocdir1.ts b:1000000 ocdir2.ts b:2000 firstait.ts b:2000 firstste.ts b:8770084 null.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & DtPlay mysecondfifo.ts -t 110 -mt OFDM -mC QAM16 -mG 1/4 -mc 2/3 -mf 578 cp firstste.ts tempste.ts
So far so good, but here it comes the difficult part: how the application register to wait for the event. The application, in order to receive the events, has to start executing and register itself to the events. To register to event the application needs a reference object placed in the object carousel so it's necessary to create a Stream Event Object into the file system you want to broadcast, that's possible with: steo.py Have a look at the steo.py script, it will generate three files: .eid .ename .tap, if you put these three in a directory inside the object carousel like: test.event or example.event the carousel generator will create a Stream Event Object instead of a directory. This is a special in-band signaling.
[...] tap = str_event_use_tap() tap.set( id = 0, assocTag = 0xD, # association tag defined into PMT for the Stream Event ) taps = Taps ( taps_count = 1, tap_loop = [ tap,], ) event_count = 3 # number of events event_names = Event_names ( eventnames_count = event_count, event_name_loop = [ "event 1", "event 2", "event 3"], ) event_ids = Event_ids ( eventids_count = event_count, event_id_loop = [ 1, 2, 3,], # id of the events ) [...]
Here is how it looks like in ocdir2 the generated files .eid, .ename and .tap:
lorenzo@nb-lpallara:~/OpenCaster/example-config$ ls -la ocdir2/ total 20 drwxr-xr-x 3 lorenzo lorenzo 4096 2007-12-04 12:17 . drwxr-xr-x 5 lorenzo lorenzo 4096 2008-06-10 02:06 ..
78
http://www.avalpa.com
When the applications querys the test.event object it will find out that can register to three different events: 1, 2, 3 as described by steo.py These three event are sent over the PID specified into the PMT and into steo.py, look for the "component tag" both in steo.py and mhpconfig2.py
[...] stream_loop_item( stream_type = 12, # Stream Event stream type elementary_PID = ste1_pid, element_info_descriptor_loop = [ stream_identifier_descriptor( component_tag = 0xD, ), ] ), [...]
How to receive stream events on a MHP application is out of the scope of this document, but you will find a java example application in the OpenCaster package. The complete workflow after the application is started is: 1) the decoder executes the application TestSte 2) the application looks for "test" Stream Event Object generated by steo.py and placed into the DSMCC at generation time 3) the application subscribe to event 1 4) the application receives event 1 from the firstste.ts generated by mhpconfig2.py
79
http://www.avalpa.com
DVB-S receiver
Avalpa Broadcast Server comes with a dvb-s receiver enabling you many scenarios. While a simple and low profile digital receiver could enable you to just re-broadcast dvb-s over UDP or output on ASI, Avalpa Broadcast Server enables you to directly manipulate the incoming transport stream in many ways up like adding an interactive service from the hard disk or generate a +1 time shifted service on the fly.
Dvblast tool
[OCTutorial12] To control the dvb-s receiver Avalpa Broadcast Server integrates DVBLast tool, let's start with some simple example of usage assuming the server is connected to Hot Bird 13 with a dish using only an universal LNB:
dvblast -c config.file -f 11760000 -s 27500000 -u -U
-f 117600000 is the transponder frequency for a Rai multiplex -s 27500000 is the baud rate of the transponder -u and -U and /udp are parameter to explicit no additional header for TS is required for UDP packets The configuration file states that service 3401 (Rai 1) is going to be broadcaster over 224.0.1.3:1234 multicast address. The resulting print should look like:
warning: restarting warning: raw UDP output is deprecated. Please consider using RTP. warning: for DVB-IP compliance you should use RTP. debug: using linux-dvb API version 5 debug: frequency 11760000 is in Ku-band (higher) debug: configuring LNB to v=13 p=0 satnum=0 debug: tuning QPSK frontend to f=11760000 srate=27500000 modulation=legacy debug: CA interface with 1 slot debug: CI link layer level interface type debug: 0 available descramblers (keys) debug: setting filter on PID 8192 debug: conf: 224.0.1.3:1234 w=1 sid=3401 pids[0]=-1,-1,-1,-1,-1... debug: frontend has acquired signal debug: frontend has acquired carrier debug: frontend has acquired stable FEC debug: frontend has acquired sync debug: frontend has acquired lock debug: - Bit error rate: 0 debug: - Signal strength: 410 debug: - SNR: 172 debug: new PAT ts_id=5200 version=30 current_next=1 debug: * number=0 pid=16
80
http://www.avalpa.com
You can check the transport stream using VLC a common pc if multicast routing between Avalpa Broadcast Server and the pc is properly configured. To configure multicast routing on Avalpa Broadcast Server refer to initial system setup.
81
http://www.avalpa.com
tsorts
[OCTutorial13] Tsorts will listen to input networks and grab a packet from them if it's ready or replace it with a null packet if there was a transmission problem and the packet couldn't be delivered. In the first example set-up a service from an input dvb-s transport stream is filtered among the others and send to the dvb-t modulator:
dvblast -c config.file -f 11760000 -s 27500000 -u -U -d input.ts tsfilter input.ts +0 +1104 +16 +17 +512 +650 +513 +651 +514 +652 +18 +20 > filtered.ts & torts filtered.ts null.ts > tsored.ts & tspcrstamp tsored.ts 24130000 > stamped.ts & DtPlay stamped.ts -r 24130000 &
tsfilter takes care to pass through only the pid we are interested.
82
http://www.avalpa.com
tsororts
[OCTutorial13] Tsororts will listen to input networks, to a local playout and grab a packet from them if it's ready or replace it with a null packet if there was a transmission problem and the packet couldn't be delivered. Here is a set-up example where tre services from an input dvb-s transport stream are filtered among the others and re-multiplexed with a fourth service generated by OpenCaster from hard disk to be finally send on output with dvb-t modulator, null packets are also replaced with dsmcc carousel to don't wast bandwidth:
oc-update.sh ocdir1 0xB 1 2003 1 1 0 0 tsfilter input.ts +512 +650 +513 +651 +514 +652 +18 +20 > filtered.ts tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:10000 mptspat.ts b:10000 mptsnit.ts b:10000 mptssdt.ts b:10000 mptspmt1.ts b:10000 mptspmt2.ts b:10000 mptspmt3.ts b:10000 mptspmt4.ts b:10000 ait.ts > muxed.ts & tstimedwrite muxed.ts 2568000 > timed.ts & tsororts timed.ts filtered.ts null.ts > retimed.ts & tstimedwrite retimed.ts 24128000 > tsored.ts & tsnullshaper tsored.ts +ocdir1.ts > final.ts & tspcrstamp final.ts 24128000 > restamped.ts & DtPlay restamped.ts -t 110 -mt OFDM -mC QAM64 -mG 1/32 -mc 2/3 -mf 578 & sleep 1 dvblast -c config.file -f 11760000 -s 27500000 -u -U -d input.ts
83
http://www.avalpa.com
84
http://www.avalpa.com
Following the dvblast tool configuration from the tuorial directory dvbsnoop should parse the PAT as following:
-----------------------------------------------------------SECT-Packet: 00000002 PID: 0 (0x0000), Length: 60 (0x003c) Time received: Thu 2010-01-07 14:30:41.904 -----------------------------------------------------------0000: 00 b0 39 14 50 fd 00 00 00 00 e0 10 0d 49 e4 50 ..9.P........I.P 0010: 0d 66 e3 02 0d 52 e0 6d 0d ab e0 56 0c f7 e1 0b .f...R.m...V.... 0020: 0c f2 e1 0c 0d 4c e1 04 0d 50 e4 53 0d 4e e1 05 .....L...P.S.N.. 0030: 0d 4b e4 52 0d 4a e4 51 af f0 80 ce .K.R.J.Q.... PID: 0 (0x0000) [= assigned for: ISO 13818-1 Program Association Table (PAT)]
Guess table from table id... PAT-decoding.... Table_ID: 0 (0x00) [= Program Association Table (PAT)] section_syntax_indicator: 1 (0x01) (fixed): 0 (0x00) reserved_1: 3 (0x03) Section_length: 57 (0x0039) Transport_Stream_ID: 5200 (0x1450) reserved_2: 3 (0x03) Version_number: 30 (0x1e) current_next_indicator: 1 (0x01) [= valid now] Section_number: 0 (0x00) Last_Section_number: 0 (0x00) Program_number: 0 (0x0000) reserved: 7 (0x07) Network_PID: 16 (0x0010) Program_number: 3401 (0x0d49) reserved: 7 (0x07) Program_map_PID: 1104 (0x0450) Program_number: 3430 (0x0d66) reserved: 7 (0x07) Program_map_PID: 770 (0x0302) Program_number: 3410 (0x0d52) reserved: 7 (0x07) Program_map_PID: 109 (0x006d) Program_number: 3499 (0x0dab) reserved: 7 (0x07) Program_map_PID: 86 (0x0056) Program_number: 3319 (0x0cf7) reserved: 7 (0x07) Program_map_PID: 267 (0x010b) Program_number: 3314 (0x0cf2) reserved: 7 (0x07)
85
http://www.avalpa.com
86
http://www.avalpa.com
Or you can also record using tstimedwrite instead of DtPlay, here is an example:
tscbrmuxer b:2300000 firstvideo.ts b:188000 firstaudio.ts b:2300000 secondvideo.ts b:188000 secondvideo.ts b:2300000 thirdvideo.ts b:188000 thirdaudio.ts b:3008 mptspat.ts b:3008 mptspmt1.ts b:3008 mptspmt2.ts b:3008 mptspmt3.ts b:1400 mptsnit.ts b:1500 mptssdt.ts b:5792069 null.ts > myfirstfifo.ts & tsstamp myfirstfifo.ts 13271000 > mysecondfifo.ts & tsdoubleoutput mysecondfifo.ts outputcopy.ts mythirdfifo.ts & tstimedwrite mythirdfifo.ts > file.ts (ctrl+c after 10 sconds) dvbsnoop -tsraw -s ts -tssubdecode -if file.ts -N 2 0
87
http://www.avalpa.com
The first command will extract sections from a given PID (2003 in the example) into a transport stream file, the second will output the dsmcc filesystem in the outputdir directory however to process the dsmcc it needs to know the PID (2003) and the component tag (0xB). 100 is a cache value, it specifies that it can store up to 100 sections even if it's not sure if they belong to the current dsmcc or not. To receive an on-air transport stream you could use dvblast tool:
mkfifo output.sec mkfifo output.ts mkdir outputdir dvblast -c config.file -f 11760000 -s 27500000 -u -U -d output.ts & ts2sec output.ts 2003 > output.sec & dsmcc-receive outputdir 100 2003 0xB < output.sec
You can't know in advance which PIDs are DSMCC so you have to analyse the PMT to find out about component tag and dsmcc pid, for this task you should use dvbsnoop, have a look at dvbsnoop chapter for more information. 2003 here is reported as an example, no DSMCC is available on hot-bird right now.
88
http://www.avalpa.com
Avalpa Broadcast Server is running both a web server and a mysql server to allow the GUI to work. You can use the GUI as is, without any changes, to schedule audio and video playout of a single service. To have the GUI already functional at the time of boot up of the server 2 Creative Common contents are already loaded so you can schedule them and get confident with the interface. These chapters tell about the simple Avalpa Playlist Editor (hence on APE), the way you can visually edit a playlist through a web browser. This could be useful, for example, if you want to broadcast a digital television service made of pre-recorded audio/video elementary streams. This work has been funded by Lepida Spa for their Lepida.tv service and roughly follows their specifications. If you do have different requirements, you can of course hire Avalpa people and get the job done with some fairly good result.
Avalpa Broadcast Server user manual configuration task and so is composed of a set of PHP scripts, some HTML web pages and template and some Javascript libraries. The PHP scripts have been tested on a Mysql database engine. The APE is a GPL licensed software based on a GPL AJAX widget toolset made by DhtmlX. Many thanks to them for their top notch release. The user experience has been tested through a Mozilla Firefox web browser on a GNU/Linux Debian based desktop PC. Mozilla and Debian are too fine free software. The killer feature here is that editing the playlist can be done with a simple drag and drop action from everywhere without the need to install anything on the local computer. To setup your television schedule, you just need a web browser pointing to your APE from anywhere .
90
http://www.avalpa.com
Daily usage
Fire your web browser and point it to the proper web site starting page like, in our example: http://server.ip.address/gui/PlaylistEditor.html It's easy and smooth, right?
Web front-end
Here it is a clean sheet configuration:
2 1
You should see this standard configuration: 1. an empty schema on the left with one week of programming available (the default week is the one including the actual day) divided in seven columns 2. a list of contents available on the right (if the database is populated, of course) 3. some buttons on the top for the more frequently used features, like calendar selection, random programming, copy paste and delete and so on 4. at the top and bottom, the Avalpa Digital Engineering web link. You should find an easy way to get in touch with Avalpa People (TM).
Avalpa Broadcast Server user manual This way, every event lasts for the proper time (I.e. the one configured in the db) to the natural end so you will not have easily events at a fixed time (it would be just a chance) and you should check carefully if events start and stop near a given time to eventually fulfill your best matching schedule (for example newcasts regularly aired near 8 o'clock PM and so on..). This strategy could already give enough precision to the user. Please consider that also public national broadcasters do not have have the greatest precision of their event schedule. Anyway the second technique available in APE gives you a way to broadcast some events at a fixed time. Practically speaking, we'll see the previous programmed event cut abruptly when the fixed time ticks to make room to the programmed event. The filling event is chosen in a special pool made of breakable events. Filling in fixed time events should be the first task in the schedule configuration job. The time of the day which you want to fill with special events should be configured previously as a Marker in the database. This task is out of topic and not described here. The third and actually last strategy for playlist configuration is a simple way to fill quickly a day schedule by random choice. You can randomize a schedule with just pressing a button on the top line and selecting the right day of the week. Usually the random function is used as a filler of empty spaces left after the two previous techniques. If there's no more room for a complete event, the left space will be eventually filled with an event chosen in the Breakable event-list and marked with a > sign on the time-sheet.
92
http://www.avalpa.com
Avalpa Broadcast Server user manual Then, drag and drop the content from the right panel to the left on the right day column. The default behaviour is that the content fills the playlist starting from the time 00:00 downward. If you drop an event over another, this event will be inserted after it and before the next one (if present). If you drop an event over the start label, this will become the first one of the day. If you drop an event at the end of the list, this will become the last one. Each programmed event shows the starting time: there's no blank space between the events if inserted into the system this way (provided the database informations are consistent like, for example, the real event duration is the same of the configured one). If you insert an event in a schedule but there's no enough room because there's already a following fixed time event, you'll get an alert window like here:
The final step to finalize a day schedule and fill the gaps is always a random fill with breakable spots. If you want to delete an event, just select it and push the right mouse button. All the subsequent events should slip back in time filling the gap. If you need to put some events at a fixed time, have a look at the next paragraph. For ease of management, you should put fixed time events at the beginning of the playlist editing. If you want to fill all the blank space with random events you should use the Random feature, check it in the next paragraphs. Beware, random events inserted can last less then their natural duration as they are cut for a perfect filling of the blank space. 93 http://www.avalpa.com
Avalpa Broadcast Server user manual That's all. Isn't it easy? Beware you can insert more the 24 hours of programmed events per day. We don't enforce here a limit. It's up to the playout system to cut out, at midnight tick, the rest of the programmed events and begin the next day.
Dataset description
Those events are described in the database as belonging to a marker tag (for example Prime time, or Late nite)
94
http://www.avalpa.com
You should see a star sign at the left of the starting time showing this event is a fixed one. If you continue selecting and dropping marked events on the day, these events we'll be put at the end of the already present list of fixed one. It's a standard behaviour as they are slipping over other fixed events. You can easily delete a programmed fixed event with the right mouse button.
Random programming
Configuring days and days of scheduled events could quickly become a boring task, one that you want as soon as possible to be done with some more automatic presets. We just put in place the more basic one: complete random selection. If you press the Random drop down button and select a day, that day will be filled of randomly chosen events for all the blank areas.
Beware, the last random event inserted can last less then its natural duration as it's cut for a perfect filling of the blank space. Broken events should be marked with a > sign in the time cell. Many more randomize behaviours could be implemented here. You can ask Avalpa for a quotation or you can implement it yourself. It's up to you. 95 http://www.avalpa.com
96
http://www.avalpa.com
If you hoover with the pointer for some time on a event entry, you can have a tooltip with the full description of the content like here:
More info could be add in the tooltip with some patch on the source code. If you press the calendar button, you'll get a calendar that can make you easily move to different weeks of schedule.
97
http://www.avalpa.com
Here you can select a content a click delete to remove a content or click add to add a new content. Every time you add a new content you should use a unique number, most of the others fields are optional and can be omitted.
98
http://www.avalpa.com
99
http://www.avalpa.com
Avalpa Broadcast Server user manual After the informations are filled the system will look for progressive_number.video.pes and progressive_number.audio.pes in the APE/content directory, so make sure to upload the files before schedule them and make sure to delete the files after they are not scheduled anymore! Refere to Intestion chapters to know how to encode your contents. Take great care the time you inserted is less than the time reported by pesinfo, here is an example:
pesinfo 55.audio.pes [..] pes header: 00 00 01 c0, audio stream Stamp is: 41644080, 462.7120 sec. pes header: 00 00 01 c0, audio stream Stamp is: 41646240, 462.7360 sec. pes header: 00 00 01 c0, audio stream Stamp is: 41648400, 462.7600 sec. pes header: 00 00 01 c0, audio stream Stamp is: 41650560, 462.7840 sec. Pesinfo 55.video.pes [...] pes header: 00 00 01 e0, 41623200, 462.4800 sec. pes header: 00 00 01 e0, 41637600, 462.6400 sec., pes header: 00 00 01 e0, 41630400, 462.5600 sec. pes header: 00 00 01 e0, 41634000, 462.6000 sec. pes header: 00 00 01 e0, 41648400, 462.7600 sec., pes header: 00 00 01 e0, 41641200, 462.6800 sec. pes header: 00 00 01 e0, 41644800, 462.7200 sec. pes header: 00 00 01 e0, 41652000, 462.8000 sec., number 0, pes size 392, header length: 5, Presentation Time number 0, pes size 392, header length: 5, Presentation Time number 0, pes size 392, header length: 5, Presentation Time number 0, pes size 392, header length: 5, Presentation Time
video stream number 0, header length: 5, Presentation Time Stamp is: video stream number 0, header length: 10, Presentation Time Stamp is: Decode Time Stamp is: 41626800, 462.5200 sec. video stream number 0, header length: 5, Presentation Time Stamp is: video stream number 0, header length: 5, Presentation Time Stamp is: video stream number 0, header length: 10, Presentation Time Stamp is: Decode Time Stamp is: 41637600, 462.6400 sec. video stream number 0, header length: 5, Presentation Time Stamp is: video stream number 0, header length: 5, Presentation Time Stamp is: video stream number 0, header length: 10, Presentation Time Stamp is: Decode Time Stamp is: 41648400, 462.7600 sec.
here using 462 seconds as length is ok because it less than both actual streams length.
100
http://www.avalpa.com
Marking content
To tag and mark content you can use the MarkerContentEditor from the ContentEditor page, select a content and click MarkerContentEditor
Click on Add and insert the marked Id among the availables on the right.
101
http://www.avalpa.com
You will have to use a progressive number and specifiy the start time.
102
http://www.avalpa.com
Now you should be able to get your scheduled list on the receiver, have a look!
103
http://www.avalpa.com
As you can see the configuration looks like the example from the chapter: Play out scheduling from command line For changes to the generated PSI tables, have a look at APEconfig.py
104
http://www.avalpa.com
AWE can manage information for more than 1 service, so for every service this status page displays information for the current and the next event. Click on the service name to display the week view for the current week:
105
http://www.avalpa.com
Week view
The week view will tell you about the events inserted, and you can also switch the week you are interested, moving also on previous and next years:
106
http://www.avalpa.com
EPG editing
First of all is necessary to log into the system clicking login and inserting user avalpa, password avalpa. More user access control is needed and on development. After clicking on Add Event, the event insertion screenshot will appear:
107
http://www.avalpa.com
108
http://www.avalpa.com
109
http://www.avalpa.com
UITBOUWEN VAN EEN TESTOPSTELLING VOOR TESTEN VAN MHP-FUNCTIES VOOR DIGITALE TELEVISIEONTVANGERS about how OpenCaster has been used for MHP conformance test An open source software framework for DVB-* transmission Acm paper presented jointly with ftw. Telecommunications Research Center Vienna, Vienna, Austria at 16th ACM international conference on Multimedia Vancouver, British Columbia, Canada
110
http://www.avalpa.com
111
http://www.avalpa.com