1

I want to stream my desktop to Sony Bravia Tv in local area network.

There is no Linux way to stream desktop to smart tv on LAN.

However I found a workaround, If there is a stream on localhost like http://localhost:9000 I can play it on tv via vGet Cast chrome extension by copying link into it, but it only supports http not rtmp or udp

I found the command below, it runs okay but it is tcp://0.0.0.0:9000 so I can not send it to Tv.

ffmpeg -f x11grab -s 1280x720 -framerate 30 -i :0.0 -c:v mpeg2video -q:v 20 -pix_fmt yuv420p -g 1 -threads  -f mpegts - | nc -l -p 8090

I tried this

 ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -framerate 30 -video_size 600x400 -i :0.0+0,0 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 3000k -vf "scale=1280:-1,format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 -f flv "http://localhost:8090/live"

but this time I get the following error:

 Connection to tcp://localhost:8090 failed: Connection refused
 http://localhost:8090/live: Connection refused
kenn
  • 5,074
  • 12
  • 55
  • 94
  • Based on your rating, I feel silly to ask but is the port forwarded? (Sometimes we miss the simple things) – EODCraft Staff Dec 01 '17 at 11:45
  • @EODCraftStaff thank you for responding. What do you mean by port forwarding? That port is not in use. – kenn Dec 01 '17 at 12:08
  • Here is one possible solution: [Is it possible to forward NON-http connecting request to some other port in nginx?](https://stackoverflow.com/a/35521557/6543935) – pa4080 Dec 01 '17 at 12:51
  • Perhaps I misunderstand Local Network but does not the port need to be allowed (forwarded) in the router or is this not necessary on a local network? (See router security settings) – EODCraft Staff Dec 02 '17 at 00:55
  • @EODCraftStaff yes, there is a setting in the router but I already enabled router to reach Tv. So my problem has nothing to do with router. – kenn Dec 02 '17 at 16:02

2 Answers2

3

I've found a way to stream to localhost via VLC tool cvlc.

I just concocted it, maybe someone improves it or posts a different approach.

 cvlc screen:// :screen-fps=10 :scre-caching=100 --sout '#transcode{vcodec=mp4v,vb=4096,acodec=mpga,ab=256,scale=1,width=1280,height=800}:http{dst=0.0.0.0:1234,access=http,mux=ts}'

EDIT: I am sorry, though it answers my question, I tested it on gmediarender, it worked, but I just tested it on Tv, it won't work on Sony Bravia Tv. Maybe it's a video format issue or missing seek table in the video format which is stated here

kenn
  • 5,074
  • 12
  • 55
  • 94
1

With the help of ffserver a web server from ffmpeg and ffmpeg itself you simply can do it.

first ...

Config the ffserver which mostly is at /etc/ffmpeg, if it was not there, do this:

 dpkg -L ffmpeg | grep server.conf

and here is a simple configuration (mine) for webm format:

HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 40000
CustomLog -

UseDefaults

<Feed screen.ffm>               # This is the input feed where FFmpeg will send
   File screen.ffm            # video stream.
   FileMaxSize 1G              # Maximum file size for buffering video
   ACL allow 127.0.0.1
   ACL allow localhost
</Feed>

<Stream screen>              # Output stream URL definition
   Feed screen.ffm              # Feed from which to receive video
   Format webm

   # Audio settings
   AudioCodec vorbis
   AudioBitRate 64             # Audio bitrate

   # Video settings
   VideoCodec libvpx
   
   VideoSize 1600x800           # Video resolution
   # VideoSize 320x240           # Video resolution
   VideoFrameRate 15           # Video FPS

   AVOptionVideo cpu-used 10
   AVOptionVideo qmin 10
   AVOptionVideo qmax 42
   AVOptionVideo quality good
   AVOptionAudio flags +global_header
   PreRoll 15
   StartSendOnKey
   VideoBitRate 400            # Video bitrate
</Stream>


<Stream status.html>            # Server status URL
   Format status
   # Only allow local people to get the status
   ACL allow 192.168.1.0 192.168.1.255
</Stream>

If you open the original config file, you will see it has a lot of comments, mv that to other name and paste mine in place of `ffserver.conf'. Then run the command:

ffserver

After starting the server, it will listen for stream from ffmpeg on port 8090 while the feed to the server we named it screen.ffm.

Second ...

Then you can run any valid ffmepg command to send stream to the ffserver. Here is mine:

ffmpeg -f x11grab -r 25 -s 1600x800 -i :0.0 -c:v libvpx -f alsa -i pulse http://127.0.0.1:8090/screen.ffm 

screenshot of running ffserver and ffmpeg command

enter image description here

Then you can open your Web Browser and watch the result at : http://localhost:8090/screen

Notice that the input for ffserver was /screen.ffm and the output address was just /screen you can change those names accordingly. And here is a screenshot of where it is being played on my local machine:

enter image description here

Also you can embed the link to a HTML5 page the watch it on a page:

  <video id="screen"  controls> <source src="http://localhost:8090/screen" type="video/webm">
    Your browser does not support HTML video.
  </video>
Shakiba Moshiri
  • 340
  • 2
  • 12