Streaming your Desktop to a DLNA compatible Smart TV

I have always desired to stream my linux desktop to my DLNA Smart TV.

This might not be very interesting for you, since lots of people today own a laptop with HDMI output which could be easily moved relatively close to your TV. However, if you are like me, and own an old desktop which is not physically in the same room of your Smart TV this post could interesting.

I know all Apple junkies can do it as well in their closed and expensive ecosystem (Apple TV + iMac/iPhone/iPad/…). I also know that it might be possible to achieve similar results using a ~39€ expensive device (i.e. Google Chromecast)… This post is the story of a personal challenge.

What Do you need?

  • Linux Computer (i.e Linux Mint 17.1 64bit, old Intel Q6600 processor) with network connection to the same network where your Smart TV is connected
  • VLC
  • ffmpeg
  • Serviio
  • Smart TV (i.e. Samsung UE40D6500)

Starting the stream capture (only video)

To capture your desktop screen (no audio) and provide it via HTTP, open a command line client and type:

$ cvlc -vv screen:// --live-caching=300 [--screen-left=<CAPTURE_OFFSET_LEFT>] [--screen-top=<CAPTURE_OFFSET_TOP>] [--screen-width=<CAPTURE_WIDTH>] [--screen-height=<CAPTURE_HEIGHT>] --screen-fps=25 --sout='#transcode{venc=ffmpeg,vcodec=<VIDEO_CODEC>,vb=<VIDEO_BITRATE>,scale=0.5,width=<STREAM_WIDTH>,height=<STREAM_HEIGHT>,acodec=<AUDIO_CODEC>,ab=<AUDIO_BITRATE>}:std{access=http,mux=<STREAM_MUX>,dst=:<STREAM_PORT>/desktop}" --no-sout-display --no-sout-rtp-sap --no-sout-standard-sap --ttl=1 --sout-keep --rt-priority

Where…

Stream Video settings

  • CAPTURE_OFFSET_LEFT is the offset in pixels from the left of your screen where you want the capture to start. Use 0 (or ignore the “–screen-left” parameter) if you want to capture the complete screen.
  • CAPTURE_OFFSET_TOP is the offset in pixels from the top of your screen where you want the capture to start. Use 0 (or ignore the “–screen-top” parameter) if you want to capture the complete screen.
  • CAPTURE_HEIGHT is the height in pixels of your capture. Use the resolution of your monitor (you might also ignore the “–screen-height” parameter) if you want to capture the complete screen.
  • CAPTURE_WIDTH is the width in pixels of your capture. Use the resolution of your monitor (you might also ignore the “–screen-width” parameter) if you want to capture the complete screen.
  • STREAM_HEIGHT is the height in pixels of your stream. Use the same value of CAPTURE_HEIGHT for better quality
  • STREAM_WIDTH is the width in pixels of your stream. Use the same value of CAPTURE_WIDTH for better quality
  • STREAM_PORT is the TCP port where your stream will be available. Use any value larger than 1024 (i.e. 8081) Depending on the value you choose, there might be some conflicts
  • STREAM_MUX is the muxer of your stream. Some possible values for this parameter are: mpeg1, ts, mp4, avi, …
  • VIDEO_BITRATE is the bitrate of the video stream in Kbps. Within your home nework, use values starting from: 2000 until 10000 … (higher values offer better video quality and require more bandwidth)
  • VIDEO_CODEC is the video codec used to compress your audio source. Some possible values for this parameter are: mp2v, mp4v, h264, flv1, … Depending on the value you choose, you might need to install some additional codecs

I have underlined the settings I tested and work fine in my Samsung Smart TV. Use a VIDEO_CODEC, VIDEO_BITRATE and STREAM_MUX compatible with your Smart TV or DLNA compatible video player.

It might be possible that your Smart TV is worried about streams without audio and displays a warning.

Testing the Stream

(TBC)

Adding audio to the stream capture

Determining the Audio Source

If you additionally want to add audio to your stream, first you need to determine the audio source you want to mux into your stream.

Use the following command to list the available pulse audio sources in your computer:

$ pacmd list-sources

the command shall list all available audio sources and its properties. What you need is the “name” of the device therefore I recommend to pipe the command to grep. Where you shall see something like…

$ pacmd list-sources | grep "name:"
    name: <alsa_output.pci-0000_00_1b.0.analog-stereo.monitor>
    name: <alsa_input.pci-0000_00_1b.0.analog-stereo>

Usually you are interested in capturing the microphone or your speaker-out. Your speaker-out has the same name as the audio sink (use pacmd list-sinks) but ends with “.monitor”

Adding audio to the stream capture

To capture your desktop screen and an audio source and provide it via HTTP in a single stream, open a command line client and type:

 $ cvlc -vv screen:// --live-caching=300 [--screen-left=<CAPTURE_OFFSET_LEFT>] [--screen-top=<CAPTURE_OFFSET_TOP>] [--screen-width=<CAPTURE_WIDTH>] [--screen-height=<CAPTURE_HEIGHT>] --screen-fps=25 --input-slave <AUDIO_DEVICE> --sout='#transcode{venc=ffmpeg,vcodec=<VIDEO_CODEC>,vb=<VIDEO_BITRATE>,scale=0.5,width=<STREAM_WIDTH>,height=<STREAM_HEIGHT>,acodec=<AUDIO_CODEC>,ab=<AUDIO_BITRATE>}:std{access=http,mux=<STREAM_MUX>,dst=:<STREAM_PORT>/desktop}" --no-sout-display --sout-audio --no-sout-rtp-sap --no-sout-standard-sap --ttl=1 --sout-keep --rt-priority

Where…

Stream Audio settings

  • AUDIO_BITRATE is the bitrate of the audio stream in Kbps. Some possible values for this parameter are: 64, 128, 192, … (higher values offer better audio quality and require more bandwidth)
  • AUDIO_CODEC is the Audio codec used to compress your audio source. Some possible values for this parameter are: mpga (recommended for portability), mp3, mp4a, none (if you are not interested in audio) … Depending on the value you choose, you might need to install some additional codecs
  • AUDIO_DEVICE is the pulseaudio source you want to capture. In my case alsa_output.pci-0000_00_1b.0.analog-stereo.monitor

I have underlined the settings I tested and work fine in my Samsung Smart TV. Use an AUDIO_CODEC and AUDIO_BITRATE compatible with your Smart TV or DLNA compatible video player.

Testing the Stream

(TBC)

Making your stream visible for DLNA devices

In the previous lines, you learned how to capture your desktop screen (complete or partially) and make it available via an HTTP stream

(TBC)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: