We watch torrents on smart TV without SMS and registration

Good day, Habr.

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

Immediately make a reservation, I in no way urge 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 their smart TV, without waiting for download, below is an interesting way.

I have a Samsung smart TV, on which I tried to watch a movie in different ways.

I tried to install minidlna on Ubuntu. Until some time this worked quite conveniently, but one day dlna the application on the TV began to fly out periodically. I still have not figured out what this is connected with, some unsuccessful update may have arrived. In any case, you could watch only fully downloaded content, which was not very interesting.

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

As a result, for a long time I just looked through the browser built into the TV. After some time, this method got terribly too.

I wanted something convenient and simple, and so that I did not immediately wait until all the content was loaded.

You say there is a Chromecast. But I wanted to do everything without extra devices at my place.

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

And so let's go.

1. We put a 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 list for download and limit the download speed. It is very important. But it’s minimalistic, picks up feasts very quickly and shakes it perfectly in sequential mode, which is what we need.

I had to rummage in the guts and add the necessary functionality. And so we put torrent from a fork

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

Download a torrent file or a magnet link.

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

torrent info some.torrent | less

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 download statistics, 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 smart TV. The main thing is that the speed be higher than the bitrate of the stream, otherwise there will be loads and buffering.

Making HLS Stream

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

apt install ffmpeg

We create a public directory where our stream will go.

Further, several options are possible. If in the source file the video is in h264 format and the audio is AAC, then you can try not to transcode 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 transcode on the fly. On my laptop, ffmpeg kept up with the stream.

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 options -map 0: 0 and -map 0: 1, we vibrate the desired channels. Video and Russian track. The -map_chapters -1 option removes all garbage just in case in the form of chapter information, etc.

You can watch the available channels with 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 content


Install a simple http server.

npm i http-server -g

We start the server

http-server -a -c-1

Watching a movie

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

Thank you all for your attention.

Also popular now: