0

I am receiving mpeg-2 transport stream on a buffer and i need to serve the content using HTTP to a web view.

I'm planning to implement it using the mpeg-dash specification and a simple HTTP server. One way is to parse the transport stream packet myself and generate live segments and an mpd file accordingly, but it seems like a long process.

I have gone through tools like mp4box and ffmpeg that are able to generate dash compatible segments using static media files, but the documentation isn't clear enough for beginners.

Is there any easy way to generate dash content live (into the server's root folder) using a buffered transport stream as input (maybe through pipe).

If there is any better way please let me know. You think parsing the transport stream packet ourselves will be a better option?

Ishaan Shringi
  • 103
  • 1
  • 1
  • 6

1 Answers1

0

FFMPEG can read from a pipe instead of a file using the -pipe:N where "N" is the file descriptor.

For testing from the shell, you can cat a file and pipe it to FFMPEG. Something like this:

cat someFile.ts | ffmpeg -re -loglevel verbose -f mpegts \
  -i pipe:0 \
  -map 0:p:8 \
  -filter_complex [v:0]scale=640:-1 \
  -c:v libx264 -b:v 1M -c:a aac -b:a 64k \
  -f dash \
   -dash_segment_type mp4 -movflags +delay_moov -seg_duration 2.000000 \
   -frag_type duration -frag_duration 0.200000 \
   -index_correction 1 \
   -target_latency 1 -window_size 10 -extra_window_size 5 -remove_at_exit 1 -streaming 1 -ldash 1 \
   -use_template 1 -use_timeline 0 -write_prft 1 -avioflags direct -fflags +nobuffer+flush_packets \
   -format_options movflags=+cmaf \
   -utc_timing_url /myServer/time.php  \
   /path/to/master.mpd

If your TS file has multiple programs (MPTS) use -map and specify the program. Make sure to specify the program if you are also scaling!

If you want to do all of this within a program, then:

Fork a separate process with fork(), create a pipe between the processes with pipe, and call FFMPEG with execv() or similar.

The FFMPEG command line passed to exec() must specify the fd for the read side of the pipe. eg, -pipe:9 (or whatever)

In the parent process, read chunks of TS data from the source (file or network) and write to the write side of the pipe.

FFMPEG will read the pipe and create the MPD and chunk files.

Danny
  • 181
  • 1
  • 7