The Naive Approach

The following recipe works for mux2:

dd if=mux2.ts bs=1024 skip=488281 | vlc - --program 2000 --demux=ts --intf dummy --play-and-exit --noaudio --novideo --sout '#std{access=file,mux=ts,dst=foobar_first.ts}'
vlc mux2.ts --program 2000 --demux=ts --intf dummy --play-and-exit --sout-file-append --noaudio --novideo --sout '#std{access=file,mux=ts,dst=foobar_first.ts}'
dd if=mux2.ts bs=1024 count=488281 | vlc - --program 2000 --demux=ts --intf dummy --play-and-exit --sout-file-append --noaudio --novideo --sout '#std{access=file,mux=ts,dst=foobar_first.ts}'
HandBrakeCLI -i foobar_first.ts -r 24 -e x264 -E faac --crop 0:0:0:0 --height 240 --vb 400 --optimize -o foobar.mp4

Note that it uses vlc as a demuxer and HandBrake as a transcoder. The bitrate (-r 24) video codec (-e x264) and audio codec (-E faac) are all necessary for successful streaming in Wowza. The test was with vlc 1.1.2 and HandBrakeCLI version svn3510 on Ubuntu Linux.

To speed up HandBrakeCLI one can pass additional x264 options: -x subq=1:nob_adapt:bframes=1:threads=auto:keyint=1000. This seems to give about a 50% total speedup compared with default values.

The Seamless Approach

The naive approach sometimes fails. It produces demuxed files which cause HandBrake to stall at the breaks between the original files. (One example is drhd_2009-11-13_21-15-00.xml.)

An alternative is to concatenate the raw transport stream files prior to demuxing. A command line example for the given program looks like

cat /bitarkiv/0244/files/mux2.1258142400-2009-11-13-21.00.00_1258146000-2009-11-13-22.00.00_dvb1-2.ts /bitarkiv/0244/files/mux2.1258146000-2009-11-13-22.00.00_1258149600-2009-11-13-23.00.00_dvb1-2.ts | dd bs=1880 skip=1191177 count=4367650 | vlc - --program=2030 --demux=ts --intf dummy --play-and-exit --noaudio --novideo --sout '#std{access=file,mux=ts,dst=seamless.ts}'

This seems to work much better.

Instantaneous Streaming

Some preliminary tests suggest we might be able to get near-instantaneous streaming with a chain like

cat  /bitarkiv/0260/files/mux2.1272772800-2010-05-02-06.00.00_1272776400-2010-05-02-07.00.00_dvb1-1.ts  | dd bs=1880 skip=1985295 count=794118 | vlc - --program=2005 --demux=ts --intf dummy --play-and-exit --noaudio --novideo --sout '#duplicate{dst=std{access=file,mux=ts,dst=-},dst=std{access=file,mux=ts,dst=./foobar_first.ts}}'| ffmpeg -i - -b 200 -s 320x240 -ar 44100 /usr/local/WowzaMediaServer/content/foobar.flv

This writes a viewable flash video simultaneously with a demuxed transport stream. There are some presentation challenges with this approach:

  1. The flash video is of inferior quality so we need to show the user clearly that this is a preview.
  2. The video is not seekable while encoding and, worse, any attempt to seek will reset to the start, so it would be smart if we could disable seeking in preview mode.
  3. Playback is not 100% stable but this requires much more testing. In one case the video froze just when writing finished.

In almost all cases, the user would be much better off if we killed the preview as soon as the final view was availaible, but can we automatically reload the player with the final h264 video as substitute for the low-quality preview video?

It would help if we could add a watermark with a big "Preview" text to the flash video. In ffmpeg this exists as an experimental feature which requires recompiling with various added sources and options, which will enable a command line option like -vf 'movie=0:png:preview.png [wm];[in][wm] overlay=10:mainH-overlayH-10:1 [out]'. However it is probably smarter to do this client-side in Flowplayer.

Aspect Ratio Detection

One can detect aspect ratio by piping a short section of the demuxed program into ffmpeg, e.g.

dd if=/bitarkiv/0260/files/mux2.1272772800-2010-05-02-06.00.00_1272776400-2010-05-02-07.00.00_dvb1-1.ts bs=1024 count=100000 | vlc - --program 2005 --stop-time=0 --noaudio --novideo --demux=ts --intf dummy --play-and-exit  --sout='#std{access=file,mux=ts,dst=-}'| ffmpeg -i - -format avi /dev/null

and looking for a line like

    Stream #0.1[0x45]: Video: h264, yuv420p, 704x576 [PAR 16:11 DAR 16:9], 26.28 fps, 50 tbr, 90k tbn, 50 tbc

in the output. Then the transcoding can proceed by setting the horizontal pixels to DAR*(vertical pixels) for the right aspect ratio with square pixels.

ClipAndGlue (last edited 2010-11-01 11:37:20 by csr)