📜 ⬆️ ⬇️

We watch torrents on smart TV without SMS and registration

Good day, Habr.

I decided to share one of the ways to watch your favorite movie / series, in good quality, without visiting any dumb sites that want you to play in the casino.

Immediately make a reservation, I in no way encourage you to use pirated content. Piracy is evil. Always buy licensed content.
')
Well, for those who want to watch the torrent, which is not protected by copyright, on its smart TV, without waiting for downloading, the interesting way is lower.

I have a Samsung smart tv on which I tried to watch movies in various ways.

I tried to install on Ubuntu minidlna. Until some time it worked quite comfortably, but one fine day the dlna application on the TV began to fly out periodically. I did not understand what it is connected with, maybe some kind of unsuccessful update arrived. In any case, you could only watch the fully downloaded content, which was not very interesting.

I tried the old fashioned way to upload a movie to an external hdd, and hook up to the TV. After a couple of three times it bothered.

As a result, I watched for a long time simply through the browser built into the TV. After some time, and this method is terribly got.

I wanted something convenient and simple and not to wait for all the content to load right away.

You say there is a Chromecast. But I wanted to do everything without unnecessary devices in my home.

As it turned out, the built-in browser (as opposed to desktop chrome) supports HLS. Well, why don't we just pick up the hls laptop stream and look through the browser.

And so it went.

1. We put torrent client


There is a very cool npm package called torrent. Everything would be fine, but he does not know how to select one file and a list for downloading and limit the download speed. It is very important. But minimalistic, very quickly picks up peers and shakes perfectly in a sequential mode, which is what we need.

I had to dig in the inside and add the necessary functionality. And so we put the torrent from the fork

npm install 'https://github.com/zim32/torrent.git#master' -g 

Download torrent file or magnet link.

To get a list of files you need to run the info command.

 torrent info some.torrent | less 

We find the file name we need (not the path) and execute the command

 torrent some.torrent --select 'FILE_NAME' --downloadLimit 1000000 

If all is well, you will see the download statistics, the number of peers, etc. Files will be added to the current directory. Speed ​​limit in Byte / s.

The restriction is necessary, because in my case the torrent clogs the entire channel, the router becomes bad and further brakes occur between the laptop and the smart TV. The main thing is that the speed was higher than the bitrate of the stream, otherwise there will be loadings and buffering.

We do HLS stream


Install ffmpeg. In my case, everything worked with the usual ffmpeg from the repository.

 apt install ffmpeg 

Create a public directory where our stream will go.

Further, there are several options. If the source file is a video in h264 format and audio is AAC, then you can try not to re-encode the stream. In this case, run the stream in this way.

 ffmpeg -re -i 'torrent_dir/movie.mkv' -codec copy -map 0:0 -map 0:1 -map_chapters -1 -movflags default_base_moof+frag_keyframe -f hls -hls_playlist_type event ~/www/player/out.m3u8 

If the codecs are different, you will have to recode on the fly. On my laptop, ffmpeg kept up with the flow.

 ffmpeg -re -i 'torrent_dir/movie.avi' -c:v libx264 -preset slow -r 24 -x264opts fps=24:bitrate=2000:pass=1:vbv-maxrate=4000:vbv-bufsize=8000:keyint=24:min-keyint=24:scenecut=0:no-scenecut -c:a aac -b:a 256k -map 0:0 -map 0:1 -map_chapters -1 -movflags default_base_moof+frag_keyframe -f hls -hls_playlist_type event ~/www/player/out.m3u8 

With the -map 0: 0 and -map 0: 1 options, we vibrate the required channels. Video and Russian track. The option -map_chapters -1 removes, just in case, all garbage in the form of information about chapters, etc.

You can view the available channels using the ffprobe movie.mkv command.

Create a server


In the same folder where the stream goes, you need to put the index.html file with the following contents

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <video src="out.m3u8" controls></video> </body> </html> 

Install a simple http server.

 npm i http-server -g 

We start the server

 http-server -a 0.0.0.0 -c-1 

Watching movies


Now on TV it is enough to open a browser with the address of your laptop for example 192.168.1.200 : 8080 and enjoy.

Thank you all for your attention.

Source: https://habr.com/ru/post/451958/


All Articles