Transcode Videos with VLC

Pick up a video, any video and run it on VLC.

Go to Tools->Codec information and check the video and audio codecs.

If you want to change containers, for eaxmple from PS/VOD to TS, you will only need to demux and mux into a new container. But if there’s a weird audio codec for example, you might need to transcode the audio and can actually copy the video.

So Open VLC and then

  1. Multimedia->Convert/save
  2. Open the File you want to convert
  3. Click Convert/Save for next
  4. Select a TS profile
  5. Edit that profile
  6. Go to video and select “Keep the original video” to keep the original video content.
    • Beware that video codec needs to be compatible with TS containers in order to copy, instead of transcode
  7.  Go to audio and check if its configured for transcoding
  8. Save
  9. Select output file
  10. Press begin

And that’s all. VLC will start “Streaming” meaning, its remuxing, transcoding your file into the destination file.

How to use DiSEqC with DVBlast the right way

If you are here you probably know what DiSEqC. If you don’t lets take an overview.

What is DiSEqC? The word stands for Digital Satellite Equipment Control and with it you are able to select which satellite to lock when selecting a frequency. Using DVBlast and boards like TBS, you are able to expand your control through at least 8 satellites using the right equipment.

I normally use the EMP – Centauri brand, which are cheap and have a lot of options. Always go for the Professional line, they have support for both QUAD and QUATTRO LNBS. The options can go from DiSEqC 1.0 (4 satellites) and (DiSEqC 1.1) for 16 satellites, although I don’t know any brand that makes Multiswitches >8.

For example, this product enables 8 tuners, DTV, and 3 LNBs.

EMP Centauri 13/8

Now all you need to look for in DVBlast is the following:

~$ dvblast -h
 -S --diseqc satellite number for diseqc (0: no diseqc, 1-4, A or B) 
-k --uncommitted port number for uncommitted diseqc (0: no uncommitted diseqc, 1-4) 

By using these options you can work out which satellite you want to use.

Examples:

dvblast ... -S 1 -k 1 (select 1st LNB/SAT)
dvblast ... -S 2 -k 2 (select 6th LNB/SAT)
dvblast ... -S 4 -k 2 (select 8th LNB/SAT)
...
dvblast .... -S 4 -k 4 (select 16th LNB/SAT)

You will see logs like this:

 debug: configuring LNB to v=13 p=0 satnum=4 uncommitted=2

Hope it helps.

How to create a AllShare DLNA Server for a Samsung Smart TV

If you really want to stream all those torrents you download from the Internet and watch them on your TV set then you’re in the right place.

For this you will need at least a linux machine. A Raspberry PI using using a 4GB SD should be more than enough to have a few episodes. If not you can use any debian/redhat based linux system. Including the one and only Ubuntu.

So let’s start. First of all check that your distro has minidlna. A Raspberry will output the following.

pi@raspberrypi ~ $ apt-get update
pi@raspberrypi ~ $ apt-cache search minidlna
minidlna - lightweight DLNA/UPnP-AV server targeted at embedded systems

Well if you are lucky to have the following output on your OS then you are in for a treat. Just install it then

pi@raspberrypi ~ $ sudo apt-get -y install minidlna

Now you need to check an important detail regarding the placement of your videos. Edit /etc/minidlna.conf (vim /etc/minidlna.conf) and edit the following line to point to the place you want your files in.

media_dir=V,/var/lib/transmission-daemon/downloads

And that’s all you need for now. After editing the config file make sure you restart the minidlna server.

pi@raspberrypi ~ $ sudo service minidlna force-reload
[ ok ] Restarting DLNA/UPnP-AV media server: minidlna.
Samsung AllShare

Samsung AllShare

Stream from Blackmagic Decklink Recorder using VLC

This tutorial will assume you have VLC already installed with Decklink support. If you don’t you’ll have to download Decklink SDK and VLC source code, plus some other tools if you want to stream directly from VLC. Check the tutorial here.

mpgv & mpga

cvlc -vvv -I dummy decklink:// --decklink-video-connection=hdmi --decklink-mode=Hi50 --decklink-aspect-ratio=16:9 --rt-priority --swscale-mode=0 --live-caching=750 --sout-mux-caching=750 --sout '#transcode{vcodec=mpgv,vb=2000,fps=25,vfilter={deinterlace},scale=1,acodec=mpga,ab=98,threads=4}:std{access=udp,mux=ts,dst=10.0.0.4:5010}' --no-sout-transcode-hurry-up --sout-all

This was by far the best results I’ve achieved. MPEG video is very light (cpu wise) and probably the most reliable.

h264 & mpga

cvlc -vvv --live-caching 2000 --sout-x264-profile main --decklink-video-connection hdmi --decklink-card-index 0 decklink:// --decklink-audio-connection embedded --decklink-aspect-ratio 16:9 --decklink-mode hp50 --sout-x264-preset superfast --sout-x264-tune film --sout-transcode-threads 4 --no-sout-x264-interlaced --sout-x264-keyint 50 --sout-x264-lookahead 100 --sout-x264-vbv-maxrate 4000 --sout-x264-vbv-bufsize 6000 --sout '#transcode{vcodec=h264,vb=5000,acodec=aac,ab=256}:std{access=udp,mux=ts,dst=10.0.0.4:5010}'

Note that, x264 encoding takes its toll on your CPU. Using an Intel i3 core CPU the maximum it could take was superfast. Ultrafast is even better but its quality is a bit worse. I think using 64 bits CPU is a bit better.

The output results are quite acceptable although i’m still having some issues with the transport stream muxing, i.e. libdvbpsi. All I see is a bunch of pictures that might be displayed late (missing x ms).

Any notes that might help reduce this input problem in the client are always welcome.

Compile x264 and VLC with Decklink SDK

Quick notes on how to compile all of these tools to make VLC work decklink tools.

x264

First go to x264 and download it.

user@testbed:/home/user# cd ~/
user@testbed:/home/user# wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
user@testbed:/home/user# tar -jxvf last_x264.tar.bz2
user@testbed:/home/user# cd x264*
user@testbed:/home/user/x264*# ./configure --enable-shared --disable-asm
user@testbed:/home/user/x264*# make -j $(grep -c processor /proc/cpuinfo)
user@testbed:/home/user/x264*# sudo make install

FAAC

user@testbed:/home/user# cd ~/
user@testbed:/home/user# wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
user@testbed:/home/user# tar -jxvf faac-1.28.tar.gz
user@testbed:/home/user# cd faac*
user@testbed:/home/user/faac*# ./configure
user@testbed:/home/user/faac*# make -j $(grep -c processor /proc/cpuinfo)
user@testbed:/home/user/faac*# make install

FFMpeg

user@testbed:/home/user# cd ~/
user@testbed:/home/user# wget http://www.ffmpeg.org/releases/ffmpeg-2.1.4.tar.gz
user@testbed:/home/user# tar -zxvf ffmpeg-2.1.4.tar.gz
user@testbed:/home/user# cd ffmpeg*
user@testbed:/home/user/ffmpeg*# ./configure --disable-yasm --disable-ffserver --disable-ffprobe --disable-ffplay --enable-libfaac --enable-nonfree --enable-libx264 --enable-gpl
user@testbed:/home/user/ffmpeg# make -j $(grep -c processor /proc/cpuinfo)
user@testbed:/home/user/ffmpeg# make install

Decklink SDK

Download Decklink SDK and extract it.

VLC

On this step you need to make sure that you point the SDK path to the right place. You can check it using the pwd command inside the SDK folder.


user@testbed:/home/user# cd ~/
user@testbed:/home/user# wget http://download.videolan.org/pub/videolan/vlc/2.1.4/vlc-2.1.4.tar.xz
user@testbed:/home/user# tar -xvf vlc-2.1.4.tar.xz
user@testbed:/home/user# cd vlc*
user@testbed:/home/user/vlc*# ./configure --disable-qt4 --disable-skins2 --disable-xcb --enable-twolame --enable-dvbpsi --disable-dbus --enable-lua --disable-mad --disable-postproc --disable-a52 --disable-libgcrypt --disable-dbus --enable-run-as-root --enable-x264 --disable-nls --enable-httpd --disable-dvdnav --disable-dshow --disable-bluray --disable-smb --disable-live555 --disable-vcd --disable-libcddb --disable-ogg --disable-mux_ogg --disable-shout --disable-mkv --disable-dvdread --disable-samplerate --disable-udev --disable-upnp --disable-mtp --disable-flac --disable-notify --disable-bonjour --disable-caca --disable-libass --disable-schroedinger --disable-theora --disable-opus --disable-speex --disable-vorbis --disable-dirac --disable-telx --disable-fluidsynth --disable-dca --disable-libmpeg2 --disable-goom --disable-dv --disable-svg --disable-kate --disable-sftp --disable-sid --disable-dc1394 --disable-opencv --disable-gnomevfs --disable-sdl --disable-taglib --disable-libxml2 --disable-portaudio --disable-telx --disable-libva --disable-jack --disable-mod --disable-projectm --disable-faad --with-decklink-sdk=/home/user/DecklinkSDK/Linux
user@testbed:/home/user/vlc*# make -j $(grep -c processor /proc/cpuinfo)
user@testbed:/home/user/vlc*# make install

How to sync different HLS bitrates with FFMpeg

HLS is an awesome streaming protocol. Forget Dash, forget HDS, HLS is probably the most supported among many vendors. Android 4.X fully supports this protocol, even though there are some minor issues when changing from different bitrates.

The following scripts were tested using an iPhone 4 with iOS 7, and an Android 4.1. They both work fine, but iPhone is way better in terms of its adaptive algorithm.

The input stream was H264 Main with 720×576 resolution. Audio was aac_latm. I tried to remux into different chunks without reencoding but it did not work. I had to encode both Audio and Video to properly play in iOS.

I used an Ubuntu 11.10 64 bit version, with FFMpeg 2.1.3, along with a 4 core Intel Xeon E3-1220. Four bitrates (256, 512, 1024, 1436) with veryfast preset occupies roughly 2 cores. For better margins you can use superfast or ultrafast preset.

processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31220 @ 3.10GHz
stepping : 7
cpu MHz : 3092.956
cache size : 8192 KB

INPUT:

Input #0, mpegts, from ‘udp://239.192.1.1:1234’:
Duration: N/A, start: 52236.297844, bitrate: N/A
Program 1101
Stream #0:0[0x20](por): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Stream #0:1[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg), 720×576 [SAR 16:11 DAR 20:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:2[0x101](por): Audio: aac_latm ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
Stream #0:3[0x102](por): Audio: aac_latm ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp (visual impaired)

How to create the HLS streams

This is the source code for the hls daemon. This script launches the FFmpeg daemon with all the parameters required. This hls script is launched by an upstart job.

root@transcoder:/usr/src# cat hls.sh
#!/bin/bash

NAME=$1
CHANNEL=$2
BR=$3
MAXRATE=`expr $3 + 100`
BUFSIZE=`expr $3 + 500`
# Change this to superfast or veryfast for lower computational needs
PRESET="veryfast"

BRPLAYLIST="${BR}_${NAME}"

options="  -vbsf h264_mp4toannexb -flags -global_header -c:v libx264 -b:v ${BR}k -maxrate ${MAXRATE}k -bufsize ${BUFSIZE}k -threads 4 -preset ${PRESET} -profile:v main  -flags +cgop -c:a libfaac -b:a 64k -ac 2  "

segmentoptions=" -f segment -segment_list ${BRPLAYLIST}.m3u8 -segment_list_flags -cache+live -segment_time 10 -segment_list_size 5 -segment_format mpegts -copyts "

ffmpeg -y -i udp://${CHANNEL}:1234 -probesize 500000 -map 0:1 -map 0:2 $options $segmentoptions "${BRPLAYLIST}_%05d.ts"

I then placed four upstart files to match the bandwidths I was looking for.

root@transcoder:/home/nonius# ls /etc/init/*rtp*
/etc/init/rtp1024.conf /etc/init/rtp256.conf /etc/init/rtp1436.conf /etc/init/rtp512.conf

Example of one of these upstart jobs.

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022

chdir /var/run/www
exec /usr/src/hls.sh rtp 239.192.1.1 512

OUTPUTS:

Each of the outputs is close to the selected output but still a couple of kbs above. This is due to the maxrate being calculated with input+100, I think. This translates into higher bitrates at certain times. One can perhaps mitigate this by placing the maxrate equal to the bitrate required. But all in all in a long term run, the bitrates come down to the selected ones.

Input #0, mpegts, from ‘1436_rtp_00124.ts’:
Duration: 00:00:10.03, start: 51597.172356, bitrate: 1784 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 720×576 [SAR 16:11 DAR 20:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 56 kb/s

Input #0, mpegts, from ‘1024_rtp_00124.ts’:
Duration: 00:00:10.03, start: 51597.172356, bitrate: 1329 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 720×576 [SAR 16:11 DAR 20:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 57 kb/s

Input #0, mpegts, from ‘512_rtp_00124.ts’:
Duration: 00:00:10.03, start: 51597.172356, bitrate: 750 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 720×576 [SAR 16:11 DAR 20:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 56 kb/s

Input #0, mpegts, from ‘256_rtp_00124.ts’:
Duration: 00:00:10.03, start: 51597.172356, bitrate: 464 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 720×576 [SAR 16:11 DAR 20:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 57 kb/s

So how do we create several of these and have them in sync with each other? My trick was to simply use the -copyts. This translates into an almost perfect sync between different bitrates. Obviously all the daemons have to start mostly at the same time, with some ms between them. But for those of you who are more skeptic I’ve attached some of the results of the hole process.

256_rtp_00124.ts
512_rtp_00124.ts
1024_rtp_00124.ts
1436_rtp_00124.ts

The only thing missing is the main adaptive playlist:

root@transcoder:/run/www# cat rtp.m3u8

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=256000,RESOLUTION=720x576
256_rtp.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=512000,RESOLUTION=720x576
512_rtp.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1024000,RESOLUTION=720x576
1024_rtp.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1536000,RESOLUTION=720x576
1436_rtp.m3u8

Note:

VLC 2.1.3 seems to have some issues with Live event HLS playback. This is due to the fact that it downloads several chunks in a row, plays them and misses the next window in time. I’m not sure why this happens, but iPhone and Android have worked flawless for me expect for some Android glitches.