maestro416
maestro416

Reputation: 924

.htaccess/php to stream a video?

Would it be possible to allow video to stream from the website directly, but prevent it from being downloaded using .htaccess and sending the request to a php file as such?

RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|flv|avi)$ [NC]
RewriteRule ^(.*)$ /stream-file.php?filename=$1 [L]

But for this I assume I'll need to write a script that would stream via php and I wouldn't be able to pass it through to a media player such as jwplayer.

Alternatively, I was curious of how doing something like this website here would be possible: http://www.statsdoesntsuck.com/york/2320.html

if you view the source, you'll find a part in the html that refers to the video on the main page

<div style="background-color:#404040; border-radius:5px;">                              
<div style="width:98%; height:auto; margin-right:auto; margin-left:auto; padding-top:6px">

<script type="text/javascript" src="http://content.bitsontherun.com/players/EwneWxTl-8JZHlp0n.js">
</script>

</div>
</div>

and the contents of EwneWxTl-8JZHlp0n.js can be found here http://content.bitsontherun.com/players/EwneWxTl-8JZHlp0n.js (script is too long to paste here).

Basically, I'm looking for a way to just make it a bit difficult to find the file name or location, but still be able to stream it. It doesn't have to be 100% secure (which I know isn't possible anyway) but at least it shouldn't be as easy as viewsource ---> url.com/file.mp4

Any ideas would be greatly appreciated. I am using joomla as well so if there are any modules/plugins that would be able to do this for me that'd be great too - though I don't mind writing it from scratch.

So to rephrase - What is the best way to protect files from being downloaded (without compromising streaming) and being able to be a DIY project rather than a paid service project.

EDIT: 1. looking for a solution via apache 2. I have found the following Flowplayer Secure Streaming with Apache

the problem with it is that the htaccess wont allow me to stream the file, and when i remove it it'll stream just fine. If someone could help me figure out what I can do to change it that'd be great

my .htaccess is as follows:

 RewriteEngine on
 RewriteRule ^(.*)/(.*)/(.*)$ http://localhost/joomla2/video/video.php?h=$1&t=$2&v=$3
 RewriteRule ^$ - [F]
 RewriteRule ^[^/]+\.(mov|mp4)$ - [F]

currently it comes up as "file not found".

Upvotes: 2

Views: 5059

Answers (2)

Tech Consultant
Tech Consultant

Reputation: 370

Yes, its easy to do. Heres a working script which I wrote for a video streaming proxy -

ob_start();

**// do any user checks here - authentication / ip restriction / max downloads / whatever**

**// if check fails, return back error message**

**// if check succeeds, proceed with code below**

if( isset($_SERVER['HTTP_RANGE']) )

$opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE'];

**// to add multiple headers to the final request, do something like

**// $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE']."\r\nHeader1: value1\r\nHeader2: value2";

$opts['http']['method']= "HEAD";

$conh=stream_context_create($opts);

$opts['http']['method']= "GET";

$cong= stream_context_create($opts);

$out[]= file_get_contents($real_file_location_path_or_url,false,$conh);

$out[]= $http_response_header;

ob_end_clean();

array_map("header",$http_response_header);

readfile($real_file_location_path_or_url,false,$cong);

Upvotes: 2

Homer6
Homer6

Reputation: 15159

If you're not bound by apache, I've heard that ffserver is the way to go.

You might also want to try nginx's nginx-rtmp-module.

With apache, there's a streaming module as well.

Lastly, you might just want to try one of the many CDN services. I know you said that you didn't want to use a service, but I felt that it was silly not to mention it. Many developers consider CDNs the default choice (including myself).

Upvotes: 0

Related Questions