6

I am trying to stream Telegram video files and play them on a web page.

I am using this script to stream Telegram videos to a web server. It uses Telethon and AIOhttp to stream the file. The streaming part can be seen here.

I am currently serving it on a server to serve media files. The videos can be downloaded using the link the script provides and can be streamed on any media player. But when I try to stream them on a web page, it has problems.

For mp4 videos, Chrome does not play them while Firefox does. Example When playing the video in Chrome(the extensions are not causing any issue, disabled on this page)

This is the DEBUG log of the script when I opened the above script in Chrome

INFO:tl.web_routes:Serving file in 723 (chat 550559022) to ::1
DEBUG:tl.paralleltransfer:Starting parallel download: chunks 0-663 of 663 InputDocumentFileLocation(id=4981324115240550559, access_hash=7389576518823114674, file_reference=b'\x01\x00\x00\x02\xd3^*\xe3\xe5\xca;oLS\xe7k\xe1i\xae\xf0\xaf#Z_\xd5', thumb_size='')
INFO:tl.paralleltransfer.dc1.conn1:Connecting...
INFO:telethon.network.mtprotosender:Connecting to 149.154.175.51:443/TcpFull...
INFO:telethon.network.mtprotosender:Connection to 149.154.175.51:443/TcpFull complete!
INFO:tl.paralleltransfer.dc1:Exporting auth to DC 1 (main client is in 5)
INFO:aiohttp.access:::1 [24/Jan/2020:12:32:40 +0000] "GET /favicon.ico HTTP/1.1" 404 172 "http://localhost:8080/watch/12423247656120/Little.America.S01E03.WEB-DL.x264-ION10.mp4" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
DEBUG:tl.paralleltransfer.dc1.conn1:Part 0/663 (total 663) downloaded
DEBUG:tl.paralleltransfer.dc1.conn1:Parallel download interrupted
INFO:tl.web_routes:Serving file in 723 (chat 550559022) to ::1
DEBUG:tl.paralleltransfer:Starting parallel download: chunks 659-663 of 663 InputDocumentFileLocation(id=4981324115240550559, access_hash=7389576518823114674, file_reference=b'\x01\x00\x00\x02\xd3^*\xe3\xec\xbb\xd2vinG\xa3Q\xb1\xf4\x033;\xa0$?', thumb_size='')
DEBUG:tl.paralleltransfer.dc1.conn1:Parallel download interrupted

For mkv videos, none of them plays it. Firefox shows the error matroska files can't be played For one or two mp4 videos, I got Chrome to play them as well. Example

I am using here Fluidplayer which uses dash.js which might be incompatible with mp4 files. I have tried to play the video with barebones HTML using the video tag but that didn't work as well.

For the web page part, I have added a route in the web_routes file that contains all AIOhttp server routes.

What can I do to play the videos on a web page? (I have also tried using Flask to add routes. So, the server on one side and a playing website in another place).

Prashant Sengar
  • 506
  • 1
  • 7
  • 24
  • The request in your example is coming out when I look at it. If you can capture an share any browser console message you are seeing that may help understand the issue – Mick Jan 24 '20 at 12:16
  • @Mick I have added screenshot and debug log data – Prashant Sengar Jan 24 '20 at 12:36
  • Is it still running ? I couldn't play anthing. – painor Jan 24 '20 at 12:48
  • @painor it is still running. I have connected it to run with http://t.me/PublicDownloadLinkBot if you want to get another link to your file – Prashant Sengar Jan 24 '20 at 13:13
  • 2
    **(1)** Your Little America video has the metadata at the end of file, this means browsers must download complete file bytes (345 mb?) before playback can begin. Look up `MP4 fast start` to put the meta (called a `moov` atom) in front of a/v data then file will play immediately in browsers. **(2)** For Dash format you need to provide an `.mpd` file to the Dash player (not a single MP4 or MKV container file). **(3)** Also your [PublicDownloadLinkBot](http://t.me/PublicDownloadLinkBot) link doesn't do anything (buttons don't respond) maybe its only active if a user to be logged in? – VC.One Jan 24 '20 at 13:40
  • @VC.One thanks for your comment. I am using the script given in the post and I am not so sure about how to move the moov atom to the front. Can you tell me or point to a good resource? Also, I don't know what problem you are facing with the bot. You must be logged in to Telegram and then start it. – Prashant Sengar Jan 24 '20 at 14:01
  • You can download FFmpeg for your OS (Win? Linux?) and run it from the command line. See [this Answer](https://stackoverflow.com/a/50914703/2057709) for the commands. Replace that `in` and `out` with your own filenames. Upload the output `.mp4` to online and test playback. I don't use Telegram so cannot login, I'm here to try fix the "play video in browser" part. Maybe try first to get an MPD file working in video tag (Dash.js?)... Then (if working) move every to Telegram and test again under that system (eg: is video available to unlogged users? etc). – VC.One Jan 24 '20 at 16:57
  • What I am trying to do is to directly stream Telegram's file and play it in a browser. So I cannot use ffmpeg for conversion. I am able to stream the video from URL using any other media player though (on phone or PC). I tried searching for the format of the moov atom online so that I can add it to the streaming process if possible but couldn't find anything substantial. – Prashant Sengar Jan 24 '20 at 17:35

0 Answers0