How to show video with media player in codeigniter - php

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

Related

PHP read MP4 file with another extension

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" );

How to load one image if sopported or another if not in HTML

I have been reworking a web site to optimize for SEO. One thing I did is to optimize Images using Googles Webp Format. But Webp is not supported on any version of Safari.
My question is: What can I do to load one image (Webp) if supported or load another like JPG if not supported.
It could be great if it is something like the Audio or Video TAG
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
Add your code like as below and it should most probably work.
<picture>
<source srcset="image.webp" type="image/webp">
<source srcset="image.jpg" type="image/jpeg">
<img src="image.jpg">
</picture>
More details are mentioned here in this link.
I assume you are using only 1 image in src (in img tag) if that fails to load then you are trying to loan any other image. So, You can use
<img src="invalid_link" onerror="this.onerror=null;this.src='other_image_url';">
Hope this helps.

Masking/redirecting a video URL via PHP

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

mp4 video doesn't play in video tag in html 5

Hi iam still struggling play mp4 format in video tag in html 5 here is my code
<?php
?>
<video width="560" height="340" controls>
<source src="http://ifliptips.com/admin/abc.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
<?PHP
?>
here is link http://ifliptips.com/admin/VueGuides/video.php
can any one guide me what i wrong in this code.i try to play this link in chrome as well as IE9.
Thanks for advance.
There's a problem with the way you encoded your video. If you open your current video in VLC and go to Codec Information you'll see under video it says: Codec: mp4v but you're specifying the video codec is avc1.42E01E in your type attribute.
I don't know what codecs the browsers are restricted to playing, but if you convert your video
to avc1 (you can download a converted version here: http://www.online-convert.com/result/d1bb21daf90f8b77377d4c9f81398eff -- see it's codec info in VLC has changed to avc1) the browsers will play it.
Wayne

Video formats for html5 video players

I am creating a website, where users can upload their videos. I'm using the HTML5 video player from http://videojs.com/. How can I make HTML5 player play only MP4 on all browsers? If that is impossible, are there any ways to maybe convert MP4 to other formats?
Please read this blog post for the updated info: http://blog.zencoder.com/2013/09/13/what-formats-do-i-need-for-html5-video/
[Old Answer: Outdated]
If you provide both Ogg Theora & MP4 format then, you can cover almost all modern browsers (ref). And, with some small effort you can find a lots of PHP implementation of the most popular & powerful open source video converter (ffmpeg). Or, you can make a small class for it too. Then use as -
<video id="my_video_1" class="video-js vjs-default-skin" controls
preload="auto" width="640" height="264" poster="my_video_poster.png"
data-setup="{}">
<source src="my_video.mp4" type='video/mp4'>
<source src="my_video.ogv" type='video/ogg'>
</video>
PHP ffmpeg wrapper libs-
http://code.google.com/p/phpvideotoolkit/
http://ffmpeg-php.sourceforge.net/

Categories