Your best option might be to run ffprobe against the file once it has finished being ::put() to the remote server. I think mpeg streams have to be read as a whole (or rather the stream info can be anywhere in the file) to figure out what they contain - so I don't think you could just use a chunk or stream to get the info - I might be very wrong though! I have vague memories of trying to do this a few years ago by just storing the first few kb/mb of the file - but it never worked :-/
Get image/video metadata from stream
Hi, in the app I am currently building I need to download files from remote locations and store them on S3. In order to reduce memory usage I am currently making use of fopen to create a stream and pass that to Storage::put(). However I need to get information such as the size, width, height, duration and possibly an MD5 of those files. Do you know how to achieve this with streams or any other solution while staying efficient?
Get video Metadata
$ffprobe = FFProbe::create();
$videoStream = $ffprobe->streams($videoURL) // extracts streams informations
->videos() // filters video streams
->first(); // returns the first video stream
$info = [
'width' => $videoStream->get('width'),
'height' => $videoStream->get('height'),
'duration' => (float) $videoStream->get('duration'),
];
Get the size of the video (because it is often missing in the headers)
$format = $ffprobe->format($videoURL); // extracts streams informations
$info['size'] = $format->get('size');
And finally because the Guzzle Documentation lacking information on how to get the actual resource from a response
$client = new Guzzle\Client([
'stream' => true,
]);
$client->get($videoURL);
$stream = $response->getBody()->detach();// Get the stream resource from Guzzle response
Storage::putStream(
$destinationPath,
$stream);
Please or to participate in this conversation.