I work in a museum, our website has many .MP4 videos. I changed their extensions to .MUS to make them more difficult to download (most people don't know how to right click the webpage, click the <video> tag to download it and then rename it). Videos show fine. It looks like this :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='dinos.mus'> ◄█■■■
</video>
Now I moved the videos to a protected directory outside WWW, then I use PHP to read them, like this :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=dinos.mp4'> ◄█■■■
</video>
And this is open_file.php :
header( "Content-Type: video/mp4" );
readfile( "/home/" . $_GET["file"] );
It works fine... until I change the extensions from .MP4 to .MUS, then the videos are no longer shown :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=dinos.mus'> ◄█■■■
</video>
I don't understand why : it's the same file, I send the proper header with PHP, the <video> tag has the proper type. Actually, without PHP the <video> tag works fine with the .MUS files, so the problem seems to be PHP.
My question is : how can I read the .MUS files and send them to be interpreted as MP4?
I have tested your code, the Content-Type: video/mp4 and readfile should work (it should not be related to the file extensions, imagine if you get the file data from a BLOB, it should also work)
But just if the home directory is relative ,then please use "./home/" instead of "/home/"
and
make sure that the directory / file permissions are set properly. Say make sure the home directory is EXECUTABLE (chmod a+x for home directory) and the mus files are READ-PERMITTED (chmod a+r for the MUS files)
So this open_file.php works:
<?php
header("Content-Type: video/mp4");
readfile("./home/" . $_GET["file"]);
?>
See a working example here:
http://www.createchhk.com/SO/testSO20Nov2021b.php
code as follows:
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=test2.mus'>
</video>
This wouldn't really protect the file. You could protect the file by hosting it on another server, buffering the video, and then renaming the file for the next user, effectively deleting the file until it gets reloaded. This would take a while to code though.
A different way to do this though, would be to use blob urls. These are what YouTube uses and it stops people from easily finding the video URL.
You can use the PHP code below to do this:
<?php // php at top of page
$video = file_get_contents('./location/to/file/from/page.mp4');
$video_code = base64_encode($video);
?>
Then, where you have the video file, you can do this:
<video width='640px' height='480px' controls='controls' controlslist='nodownload' />
<source type='video/mp4' src='<?php echo $video_code; ?>'>
</video>
If anyone tries to grab the video URL and open it, it will tell them that the file has been moved. They also cannot download the file. I would also recommend adding oncontextmenu='return false;' to the video for a bit more security.
I think the MIME type for .MUS files is application/octet-streamheader( "Content-Type: application/octet-stream" );
Related
The content of my site is loaded through a PHP include, based of off the options a user selects from the menu at the top of the page-- the menu option reloads the index.php page and points it to the content to include.
This works fine for just about anything, except on pages that have embedded video via the HTML <video> tag. On those pages, the embedded video still appears to be clickable (i.e., clicking on parts of it will take me to the YouTube page hosting the video) but I can't actually see the video or video player.
Is this something to do with using a PHP include, or is there something else I'm missing? I'd been previously using iframes for my site content, but wanted to get away from that as much as possible.
EDIT: To clarify, this is the behavior I'm seeing when I load the page:
The video is definitely there; I can save it, and if I right click on it, I get the context menu for the video player. I just can't actually see the video. This is the block on the index.php file that actually loads the page content:
<div id="frame">
<?php
$url = '';
if (!empty($_GET['menu'])) {
$url .= $_GET['menu'] . '/';
}
if (!empty($_GET['customer'])) {
$url .= $_GET['customer'] . '/';
}
if (!empty($_GET['product'])) {
$url .= $_GET['product'] . '/index.';
}
if (!empty($_GET['pagetype'])) {
$url .= $_GET['pagetype'];
}
if (empty($url)) {
$url = 'intro.html';
}
include $url;
?>
</div>
All of the $GET values are supplied by the link the user selects from the main menu, like so:
<li><a class="mainMenuLink" href="index.php?menu=products&customer=customer2&product=product5&pagetype=html">Example</a></li>
EDIT 2: Here's the HTML markup generated by the page for the section surrounding the videos:
<div id="tabs-5"><!-- start tab 5-->
<p>Access videos detailing operations and maintenance.</p>
<div class="accordion">
<h3>Video 1</h3>
<div>
<video src="./products/coffee/sinf/video/video1.mp4" controls></video>
</div>
<h3>Video 2</h3>
<div>
<video src="./products/coffee/sinf/video/video2.mp4" controls></video>
</div>
</div>
</div><!-- end tab 5-->
If you check your console log, and don't see an error for a 404 Not Found, then you are likely not doing anything wrong on the PHP end.
It looks like you are using Chrome, so Inspect Element should let you know if there is any issue loading your include and it not calling the right file path to your video or something.
This could be browser dependent, and it is also recommended (the last I checked) to include multiple file types for HTML5 videos to be cross browser compatible.
This has almost always worked for me -
<video preload="auto" autoplay="" controls>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
<source src="video.ogv" type="video/ogv">
</video>
Adding these lines to your .htaccess file will help, too -
AddType video/mp4 .mp4 .m4v
AddType video/webm .webm
AddType video/ogv .ogv
VLC has a great open-source player that can convert to the additional file types - http://www.videolan.org/vlc/index.html
How can I add media player in codeigniter,
I use below code, but still can't show the video :
<video width="205" height="180" controls>
<source src="application/views/web/videostreaming/video2.mp4" type="video/mp4" />
<source src="application/views/web/videostreaming/video2.ogv" type="video/ogg" />
<source src="application/views/web/videostreaming/video2.flv" type="video/flv" />
</video>
I added video sources in application/config/mimes.php like this:
'mp4' => 'video/mp4',
'flv' => 'video/flv',
'ogv' => 'video/ogv',
output error is:
No video with supported format and MIME type found
please help me to resolve this problem, thank you
Your error No video with supported format and MIME type found is a client-side issue, meaning that the browser cannot play any of your provided video files. Changing the CodeIgniter mime types isn't going to help you (unless perhaps you are processing all requests including those for static files through PHP). Check that your MP4 file is using H.264/AAC codices, and you OGV file is the Theora/Vorbis codicies and that these file paths are correct (you may want to dynamically create absolute paths using CodeIgniter's base_url() function).
The video tag is something new in html5 and doesn't support by browsers well.
i recommend you :
Flash (.swf) media player for html
Embed Tag
before i get burried in trying to create the code, I was hoping to get some advice before moving forward.
I am creating a video sharing app for a client.
The videos are highly confidential, so i want to store them outside the root and stream them when a user enters a link into a browser, which triggers a php script to access the file and play it.
Is this possible?
I can seem to find any info on any forums or Google.
Can I stream it direct to the browser?
I had this working when the files were inside the root.
I am holding the url of the file in a var:
$file_url = "../users/$u_id/$folder_name/$file_name";
And trying to stream the video using html5 player video.js using this:
<div id="video_box">
<video id="example_video_1" class="video-js vjs-default-skin"
controls preload="auto" width="500" height="350"
poster="images/img_name.png"
data-setup='{"example_option":true}'>
<source src="$file_url" type='$file_type' />
</video>
</div>
Many thanks
Alan
I'm desperately (hours of research and no luck so far) trying to create a PHP page which can be used as a path for video embedding. I'm doing this so that I can give out a path to 3rd parties, that they can use for embedding, which won't change, even if I have to host the video elsewhere.
I've tried using the code referenced here...
Reading mp4 files with PHP
... but it doesn't work at all for me.
The video files will be hosted on a CDN and 3rd parties will need fixed links that they can embed on their own sites like:
<div data-swf="$resourcePath/resources/flowplayer.commercial-5.4.3/flowplayer.swf" class="flowplayer is-splash play-button" data-ratio="0.5625">
<video>
<source type="video/mp4" src="http://www.mycdndomain.com/embed/loader.php?v=1"/>
</video>
</div>
Thanks in advance.
-Josh
i am currently trying to build a html5 video page with restrictive access to the videos. Therefor i want to put the videos out of web root and have some kind of script check the user account and deliver the video.
If i put a .ogv (theora) and a .mp4 (h264) file just into webroot and use a video tag with multiple source tags, they work on all tested browsers: Firefox (ogg), Chrome (ogg), IE9 (mp4), Safari (mp4), Opera (ogg)
<video id="currentVideo" controls width=640>
<source type='video/ogg; codecs="theora, vorbis"' src="http://mysite/1.ogv" />
<source type='video/mp4; codecs="avc1.64001E, mp4a.40.2"' src="http://mysite/2.mp4" />
</video>
Now the first question that comes up is: Why is chrome using the ogg format? It scrubs much faster through the timeline with mp4 videos and it does support mp4 videos... Is there a way to mark a format as 'preferred format'?
Now if i put the files out of my webroot and use a php script like this to deliver them:
download.php:
$path=explode('/',$_SERVER['PATH_INFO']);
if (sizeof($path)>1) {
$inf=explode('.',$path[1]);
$id=intval($inf[0]);
$type=$inf[1];
$ctype='';
if ($type=='ogv') {
$ctype='video/ogg';
} elseif ($type=='mp4') {
$ctype='video/mp4';
}
$fname=sprintf('/var/outsidewebroot/videos/test.%s',$type);
http_send_content_type($ctype);
http_throttle(0.1);
http_send_file($fname);
}
which should put out the file including support for http range queries.
HTML:
<video id="currentVideo" controls width=640>
<source type='video/ogg; codecs="theora, vorbis"' src="http://mysite/download.php/1.ogv" />
<source type='video/mp4; codecs="avc1.64001E, mp4a.40.2"' src="http://mysite/download.php/2.mp4" />
</video>
Opera is not able anymore to determine playing length of the video, and even worse: google chrome (and its free clone iron) hang (mac and windows) - chrome itself remains running, but the tab loading the site is locked
Is there a way to mark a format as 'preferred format'?
List them in order of preference. You have ogg first, so it is taken as preferred.
<video id="currentVideo" controls width=640>
<source type='video/mp4; codecs="avc1.64001E, mp4a.40.2"' src="http://mysite/2.mp4" />
<source type='video/ogg; codecs="theora, vorbis"' src="http://mysite/1.ogv" />
</video>