I'm trying to create a web application using PHP (Laravel 5.8) where user can past link of any video found on the Internet (like Youtube, Dailymotion ... etc), then cut the video.
Cutting the video the video both in front-end and back-end is easy to do, I'm using PHP-FFMPeg to do it in server side.
My problem is that I couldn't find a solution to open a remote video from my PHP script, i.e if user past this link "https://www.dailymotion.com/video/x6rh0" I would open it then make a clip.
This my code :
$ffmpeg = FFMpeg\FFMpeg::create();
$url = "https://www.dailymotion.com/video/x6rh0";
$video = $ffmpeg->open($url);
$clip = $video->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(15));
$clip->save(new FFMpeg\Format\Video\X264('libmp3lame', 'libx264'), public_path().'/videos/video2.avi');
I'm using PHP Laravel framework.
Please, how can I open a video from URL using PHP-FFMpeg, this is my question.
Related
I'm trying to download files from a Google Drive link from Google server to my web server, to avoid the 100 max size in PHP POST.
<?php
$link = $_POST["linkToUpload"];
$upload = file_put_contents("uploads/test".rand().".txt", fopen($link, 'r'));
header("Location: index.php");
?>
Inserting a normal link like http://example.com/text.txt it works fine. The problem comes linking google drive https://drive.google.com/uc?authuser=0&id=000&export=download. This is a direct link from Google Drive, but it doesn't work. So I tried to insert the link that I obtained downloading the file locally https://doc-08-bo-docs.googleusercontent.com/docs/securesc/000/000/000/000/000/000?e=download and it's still not working. Do you think Google is trying to avoid the server-to-server copies? Or there is another method to do it?
If you want to fetch files with your own application you should use the API (Application Programming Interface) to get these.
Have a look at the file download documentation for Google Drive
Example download snippet in PHP:
$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$response = $driveService->files->get($fileId, array(
'alt' => 'media'));
$content = $response->getBody()->getContents();
I have tried to upload any video and convert the video file to mp4 at the time of upload using ffmpeg. The shell command I tried:
$input = base_url().'video_upload/'.$file_name;
$output = video_upload/video_'.$video_data['username'].'_'.$dtd.'_'.$random_number.'.mp4';
$convt = shell_exec('ffmpeg -i '.$input.' '.$output);
But i am unable to play those converted video in the web browser.
I am currently making a website where I simply want users to be able to screenshot a webpage and then download the image. So what I need help with is: how do I screenshot a webpage using PHP then save the image on my server.
I have read a few other tutorials on how to screenshot a page, but I can't get it to work.
I am using a Linux server (Debian 7.0).
You can use grabz.it
Take Website Screenshots with PHP
Get your free Application Key and Secret.
Download the free PHP Demo and Library and try it out.
Then use it like this:
include("GrabzItClient.class.php");
$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
$grabzIt->SetImageOptions("http://www.google.com");
$grabzIt->SaveTo("google.jpg");
If you don't want to depend on 3rd parties, you can use phantomjs, i.e.:
phantomjs responsive-screenshot.js http://google.com
Notes:
1- Download responsive-screenshot.js. Check the source code for available options.
2- You can install phantomjs by cloning the github repo:
git clone https://github.com/ariya/phantomjs.git
I recently published a project that gives PHP access to a browser. Get it here: https://github.com/merlinthemagic/MTS
Like previous answers the project relies on PhantomJS.
After downloading and setup you would simply use the following code:
$myUrl = "http://www.google.com";
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl);
//now do a screenshot, valid formats are png, jpeg, gif.
$imageData = $windowObj->screenshot("png");
file_put_contents("/path/to/your/file.png", $imageData);
I've an IP-associated ftp access to an host, say ftp.host.com and I need to show in php pages (hosted somewhere else) some images hosted on the ftp site
The website php pages are the only ones allowed to access ftp.host.com because of the IP policies.
Of course, if I call images with " the call is done by the client, not the server, so it fails because of IP policies.
How can I call the images from server side? I can't use CURL nor FTP_GET because of the well known ftp over NAT php bug described here:
http://www.elitehosts.com/blog/php-ftp-passive-ftp-server-behind-nat-nightmare/
And I can't patch php because it's on an hosted server so I'm out of ideas
Any idea would be greatly appreciated!
These might work for you getimagesize() and readfile()
$remoteImage = "http://www.example.com/gifs/logo.gif";
$imginfo = getimagesize($remoteImage);
header("Content-type: $imginfo['mime']");
readfile($remoteImage);
I have one question.
Imagine, that video files are in the server named A.
using php script (which is in the server named "B") we can get stream of the video (from the server "A" to the server "B"). The important thing is that only B server cant get video stream. It is forbidden for the other servers.
PROBLEM:
There are many client and they want to download videos from the server named "A".
There is only one solution:
video files must be downloaded through the server "B". can you tell me, how can I do that?
For instance lets get youtube video. I upload his script to my server "B". this script downloads videos to the server, but how to send video stream to the clients via the server (through the server B)? I need to send video byte to byte to the client , I don't want to save video to the server, I want to sent byte to byte to the client. When the server downloads 100 byte , it should save it in the memory , and sent to client, then again download and save to the server memory and send to the client... something like this...
for "sending to client" I mean - to open "save as dialog" of browser of the client
<?php
$id = "BZP1rYjoBgI";
$format = "video/mp4";
...
$videoStream = .....;
...
}
?>