I have some videos that are hosted on S3 (.mp4 and .mov) some of which are rather large (1.2GB+).
I want to get the first frame from each video using the PHP wrapper for FFmpeg but I don't want to have to download the full file first.
What I really want to do is download a certain percentage of the file, something like 2%, so that I can guarantee that I will get the first frame.
I found a way to download 1mb of the file here: https://code.i-harness.com/en/q/c09357
However, it is the following chunk of this code that I don't really understand how it is only downloading 1mb.
function myfunction($ch, $data) {
$length = fwrite($this->fh, $data);
$size=&$this->size;
if($length === FALSE) {
return 0;
} else {
$size += $length;
}
// Downloads 1MB.
return $size < 1024 * 1024 * 1 ? $length : 0;
}
To me that says set the size to be the size of the file and then if the size is less than 1mb return the length, else return 0.
Now, I know it does work because I have run it, but I don't know how it works so that I can convert this into getting the percentage of the file.
Downloading 1 or 2 MB of the file is fine for the smaller files and the mp4 files, however the .mov files fail to get the first frame if it is less than about 20mb and some frames throw a division by zero
error when getting the frame, I guess from the above function returning 0.
Could anyone shed some light on how all of this is working please, or even better if you could suggest an improvement?