Verification: a143cc29221c9be0

Open video file in php

PHP video transformation overview

After uploading videos to Cloudinary, they can be transformed in many ways.

The syntax for transforming and delivering videos is generally the same as that for images, and you can apply the majority of available image transformations to video as well. For example, you can resize, crop, rotate, set video quality and format or use auto quality and/or auto_format, add text or image overlays to your videos, and more.

There are also a number of special options you can use for transforming and delivering video content. For example, you can adjust their size, shape, speed, duration, quality, and appearance. There are also some features that are specific to audio.

This section introduces you to the basics of PHP video streaming and transformation. For complete details on all video transformation functionality, see Video transformations and the Transformation URL API Reference.

PHP video transformation functionality

In addition to transformation features that are equally relevant for images and video, such as resizing, cropping, rotating, adding text or image overlays, and setting video quality or format, there are a variety of special transformations you can use for video. For example, you can:

  • Transcode videos from one format to another
  • Apply video effects such as fade-in/out, accelerating or decelerating, adjusting volume, playing in reverse
  • Play video-in-video, trim videos, or concatenate multiple videos
  • Set video and audio quality options such as bitrate, video codec, audio sampling frequency, or audio codec
  • Adjust the visual tone of your video with 3D LUTs
  • Generate thumbnails or animated images from video
  • Deliver your video using adaptive bitrate streaming in HLS or MPEG-DASH

You can optionally specify all of the above transformations within a VideoTag method, which automatically generates an HTML5 video tag including the transformation URL sources for the main formats supported by web browsers, as well as a poster thumbnail image. This enables the browser to automatically select and play the video format it supports. The video files are created dynamically when first accessed by your users.

For details, see the video tag documentation.


Evening Everyone, Been working on this problem for a couple of days and I am stumped.  I have a single php file to handle download and streaming of files.  It works great with music files, I can download and stream to an

/path/to/music/124 - Mouth Techno -1.mp3
size: 1508731
ctype: audio/mpeg
range: 0-1508730/1508731
write chunk: 8192-1508731
write chunk: 16384-1508731
write chunk: 1507328-1508731
write chunk: 1515520-1508731

log when streaming movie - this is the complete output, it just stops:

Log Started
size: 889628920
ctype: video/mp4
range: 0-889628919/889628920
write chunk: 8192-889628920
write chunk: 16384-889628920
write chunk: 24576-889628920
write chunk: 32768-889628920
write chunk: 40960-889628920
write chunk: 49152-889628920
write chunk: 57344-889628920
write chunk: 65536-889628920

Here is how I am downloading and streaming the files.  Music files work just fine with

      "mpg" => "/path/to/movies/",
      "avi" => "/path/to/movies/",
      "mp4" => "/path/to/movies/",
$path = isset($path_types[$file_ext]) ? $path_types[$file_ext] : $path_default;
$file_path  = "$path"."$filename";


// allow a file to be streamed instead of sent as an attachment
$is_attachment = isset($_GET["play"]) ? false : true;

// make sure the file exists
if (is_file("$file_path")){
	$file_size  = filesize($file_path);
	$file = @fopen($file_path,"rb");

	writeLog("size: $file_size\n");
	if ($file){
 		header("Expires: -1");
		header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
     	// set appropriate headers for attachment or streamed file
     	if ($is_attachment){
                header("Content-Disposition: attachment; filename=\"$file_name\"");
                header('Content-Disposition: inline;');
 		// set the mime type based on extension.
          $ctype_default = "application/octet-stream";
          $content_types = array(
                "exe" => "application/octet-stream",
                "zip" => "application/zip",
                "mp3" => "audio/mpeg",
                "mpg" => "video/mpeg",
                "avi" => "video/x-msvideo",
                "mp4" => "video/mp4",
          $ctype = isset($content_types[$file_ext]) ? $content_types[$file_ext] : $ctype_default;
          header("Content-Type: " . $ctype);
          writeLog("ctype: $ctype\n");
		$end   = ($file_size - 1);
		$start = 0;
	 	header("Content-Length: $file_size");
		header('Accept-Ranges: bytes');
		header("Content-Range: bytes $start-$end/$file_size");
		writeLog("range: $start-$end/$file_size\n");
		while(!feof($file)) {
			$chunk = (1024*8);
			echo fread($file, $chunk);
			writeLog("write chunk: $a-$file_size\n");

			if (connection_status()!=0){

		// file save was a success

		// file couldn't be opened
		header("HTTP/1.0 500 Internal Server Error");
	// file does not exist
	header("HTTP/1.0 404 Not Found");

function startLog(){
	$myfile = fopen("newfile.txt", "w");
	fwrite($myfile, "Log Started\n");
function writeLog($pstr) {
	$myfile = fopen("newfile.txt", "a");
	fwrite($myfile, $pstr);
function clearLog() {


incase it helps, code calling download.php

    "; //title echo "
    "; echo "
    $size MB
    "; echo "
    "; if ($size
    "; } echo "
"; $a++; } ?>

Thanks for any help!
Edited by AdrianHoffman, 27 September 2014 - 11:51 PM.