Log in

View Full Version : How can I stream a video while make seeking possible?


konstantin1
11th June 2016, 16:08
I have a VPS with fast connection, and reasonable processing power. Sometimes I would like to watch movies from direct links I found on the internet without downloading them. So I simply open the link with an appropriate player, VLC, SMPlayer, FFplay, etc. as I a am Linux user. Unfortunately my internet connection is pretty slow, at least for watching videos online. CPU power is also low, thus decoding 720p videos is demanding for my 2.4 GHz P4.
I found out that I could stream those videos from my VPS applying an on-the-fly encoding to make the videos smaller bitrate, and resolution eg. 720p -> 480p or even 240p. I tried ffmpeg to achieve this task, it can transcode realtime, scaling down, applying some brightness filters, but the resulting stream isn't seekable :(
I also tried AviSynth TCPsource and TCPserver to send the video with a lower resolution, but the bitrate still reamins high, because the compression can be only lossless (Huffman, Gzip, etc). On the top of that Linux players don't support playing .avs files.
I have AviSynth and Apache installed on my VPS, maybe I could use some CGI app to deliver the video and make it somehow react to the seeking at server side. I think when seeking is clicked in the player, then the player makes a HTTP1.1 byte range request, so my wanna be CGI app should be aware of this and continue transcoding from the calculated time position, which would be calculated form the byte position and the average bitrate.
What other method should I consider to make an on-the-fly transcoding which react to the seeking? Maybe there is a handy app / script which I don't know.

mariush
11th June 2016, 19:01
Find a media player that supports hardware decoding of your content. If you had Windows, Media Player Classic Home Cinema (mpc-hc) is quite capable of using the video card to decode the video without using the processor to do it.

Your processor may not be powerful enough to play 720p content encoded in h264 but it's probably powerful enough to play 720x576 or 640x480 or 640x360 content encoded in h264 - I have a T40 laptop with an Intel Centrino processor (1.5 Ghz) and a Radeon 9000 video card and this old laptop can still play h264 content in full screen mode, as long as it's SD.
On older computers, I found that some older versions of CoreAVC codec use less resources to decode h264 content compared to the built-in codec of the player (mpc-hc)

But if you want something that will definitely play on your computer, configure your vps to convert your videos to mpeg2 or mpeg1 , these are codecs that are easy to decode on p4 and you may even be able to keep the resolution as is, provided you give it enough bitrate (6-10mbps for mpeg2 SD should be enough)

As for seeking, hinted mp4 files should be seekable even if you download them directly through http ... see this page for details how to make one : http://superuser.com/questions/438390/creating-mp4-videos-ready-for-http-streaming

konstantin1
11th June 2016, 19:29
Thx, my video card also low grade: NVidia FX5200

I meant such a solution, when for example I query the real location of a youtube video with the youtube-dl Python utility:
youtube-dl -g https://www.youtube.com/watch?v=RvWRhU8j0bg


I get something like this:
https://r6---sn-hpa7zned.googlevideo.com/videoplayback?id=46f591854f23d1b8&itag=135&source=youtube&requiressl=yes&pl=51&ms=au&mv=u&mm=31&mn=sn-hpa7zned&nh=IgpwcjAyLm1pbDAxKgkxMjcuMC4wLjE&ratebypass=yes&mime=video/mp4&gir=yes&clen=179966857&lmt=1465555641180791&dur=2987.600&mt=1465669375&upn=ZmpmrOdstuw&sver=3&fexp=9408086,9414875,9416126,9416891,9422556,9422596,9428398,9431012,9433096,9433380,9433634,9433946,9435527,9435876,9436101,9436835,9436921,9437028,9437066,9437552,9437664,9437988,9438244,9438377,9438482,9438558,9438595,9438804&key=dg_yt0&signature=83FC4B548FE39A80726F4AEE42162CDBD4B3B92F.441A864CC8DEA226289AEEAFA690B2411EA4E52B&ip=2a00:dcc0:eda:3754:2376:9f66:470e:304f&ipbits=0&expire=1465691127&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,ms,mv,mm,mn,nh,ratebypass,mime,gir,clen,lmt,dur

Which is not a real video location, but a CGI application, which write the video content of its STDOUT, so players can play it, and in this case it remains seekable, if I paste this URL in VLC, it plays, and I can seek too.