|
| 1 | +# Transcoder plugin for Craft CMS |
| 2 | + |
| 3 | +Transcode videos to various formats, and provide thumbnails of the video |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +To install Transcoder, follow these steps: |
| 8 | + |
| 9 | +1. Download & unzip the file and place the `transcoder` directory into your `craft/plugins` directory |
| 10 | +2. -OR- do a `git clone https://github.com/nystudio107/transcoder.git` directly into your `craft/plugins` folder. You can then update it with `git pull` |
| 11 | +3. -OR- install with Composer via `composer require nystudio107/transcoder` |
| 12 | +4. Install plugin in the Craft Control Panel under Settings > Plugins |
| 13 | +5. The plugin folder should be named `transcoder` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads. |
| 14 | + |
| 15 | +Transcoder works on Craft 2.4.x, Craft 2.5.x and Craft 2.6.x. `ffmpeg` **must** be installed for it to function. |
| 16 | + |
| 17 | +## Transcoder Overview |
| 18 | + |
| 19 | +The Transcoder video allows you to take any locally stored video, and transcode it into any bitrate/framerate, and save it out as a web-ready `.mp4` file. |
| 20 | + |
| 21 | +It also allows you to get a thumbnail of the video in any size and at any timecode. |
| 22 | + |
| 23 | +Finally, it lets you download an arbitrary file (such as the transcoded video) via a special download link. |
| 24 | + |
| 25 | +If the source file has changed since the last time the video was encoded, it will re-encode the video and replace it. |
| 26 | + |
| 27 | +## Configuring Transcoder |
| 28 | + |
| 29 | +The only configuration for Transcoder is in the `config.php` file, which is a multi-environment friendly way to store the default settings. Don't edit this file, instead copy it to `craft/config` as `transcoder.php` and make your changes there. Here's the default `config.php` file: |
| 30 | + |
| 31 | + <?php |
| 32 | + /** |
| 33 | + * Transcoder Configuration |
| 34 | + * |
| 35 | + * Completely optional configuration settings for Transcoder if you want to customize some |
| 36 | + * of its more esoteric behavior, or just want specific control over things. |
| 37 | + * |
| 38 | + * Don't edit this file, instead copy it to 'craft/config' as 'transcoder.php' and make |
| 39 | + * your changes there. |
| 40 | + */ |
| 41 | + |
| 42 | + return array( |
| 43 | + |
| 44 | + /** |
| 45 | + * The path to the ffmpeg binary |
| 46 | + */ |
| 47 | + "ffmpegPath" => "/usr/bin/ffmpeg", |
| 48 | + |
| 49 | + /** |
| 50 | + * The path where the transcoded videos are stored |
| 51 | + */ |
| 52 | + |
| 53 | + "transcoderPath" => $_SERVER['DOCUMENT_ROOT'] . "/transcoder/", |
| 54 | + |
| 55 | + /** |
| 56 | + * The URL where the transcoded videos are stored |
| 57 | + */ |
| 58 | + |
| 59 | + "transcoderUrl" => "/transcoder/", |
| 60 | + ); |
| 61 | + |
| 62 | +## Using Transcoder |
| 63 | + |
| 64 | +### Generating a Transcoded Video |
| 65 | + |
| 66 | +To generate a transcoded video, do the following: |
| 67 | + |
| 68 | + {% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', { |
| 69 | + "frameRate": 20, |
| 70 | + "bitRate": "500k" |
| 71 | + }) %} |
| 72 | + |
| 73 | +You can also pass in an `AssetFileModel`: |
| 74 | + |
| 75 | + {% set myAsset = entry.someAsset.first() %} |
| 76 | + {% set transVideoUrl = craft.transcoder.getVideoUrl(myAsset, { |
| 77 | + "frameRate": 20, |
| 78 | + "bitRate": "500k" |
| 79 | + }) %} |
| 80 | + |
| 81 | +It will return to you a URL to the transcoded video if it already exists, or if it doesn't exist, it will return `""` and kick off the transcoding process (which can be quite lengthy for long videos). |
| 82 | + |
| 83 | +In the array you pass in, the default values are used if the key/value pair does not exist: |
| 84 | + |
| 85 | + { |
| 86 | + "bitRate" => "800k", |
| 87 | + "frameRate" => 15, |
| 88 | + } |
| 89 | + |
| 90 | +If you want to have the Transcoder not change a parameter, pass in an empty value in the key/value pair, e.g.: |
| 91 | + |
| 92 | + {% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', { |
| 93 | + "frameRate": "", |
| 94 | + "bitRate": "" |
| 95 | + }) %} |
| 96 | + |
| 97 | +The above example would cause it to not change the frameRate or bitRate of the source movie (not recommended for client-proofing purposes). |
| 98 | + |
| 99 | +### Generating a Video Thumbnail |
| 100 | + |
| 101 | +To generate a thumbnail from a video, do the following: |
| 102 | + |
| 103 | + {% set transVideoThumbUrl = craft.transcoder.getVideoThumbnailUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', { |
| 104 | + "width": 300, |
| 105 | + "height": 200, |
| 106 | + "timeInSecs": 20, |
| 107 | + }) %} |
| 108 | + |
| 109 | +It will return to you a URL to the thumbnail of the video, in the size you specify, from the timecode `timeInSecs` in the video. It creates this thumbnail immediately if it doesn't already exist. |
| 110 | + |
| 111 | +In the array you pass in, the default values are used if the key/value pair does not exist: |
| 112 | + |
| 113 | + { |
| 114 | + "width" => 200, |
| 115 | + "height" => 100, |
| 116 | + "timeInSecs" => 10, |
| 117 | + } |
| 118 | + |
| 119 | +If you want to have the Transcoder not change a parameter, pass in an empty value in the key/value pair, e.g.: |
| 120 | + |
| 121 | + {% set transVideoThumbUrl = craft.transcoder.getVideoThumbnailUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', { |
| 122 | + "width": "", |
| 123 | + "height": "", |
| 124 | + "timeInSecs": 20, |
| 125 | + }) %} |
| 126 | + |
| 127 | +The above example would cause it to generate a thumbnail at whatever size the video is (not recommended for client-proofing purposes). |
| 128 | + |
| 129 | +### Generating a Download URL |
| 130 | + |
| 131 | +To generate a download URL for a file, do the following: |
| 132 | + |
| 133 | + {% set downloadUrl = craft.transcoder.getDownloadUrl('/some/url') %} |
| 134 | + |
| 135 | +When the user clicks on the URL, it will download the file to their local computer. If the file doesn't exist, `""` is returned. |
| 136 | + |
| 137 | +The file must reside in the webroot (thus a URL or URI must be passed in as a parameter, not a path), for security reasons. |
| 138 | + |
| 139 | +## Transcoder Roadmap |
| 140 | + |
| 141 | +Some things to do, and ideas for potential features: |
| 142 | + |
| 143 | +* The videos could potentially be saved in different formats (though `.mp4` really is "the" standard for video) |
| 144 | +* The videos could potentially be resized, either to an aspect ratio or an absolute size or what have you |
| 145 | +* Accessors could be written to get information about a video (height, width, duration, and so on) |
| 146 | + |
| 147 | +## Transcoder Changelog |
| 148 | + |
| 149 | +### 1.1.0 -- 2016.09.12 |
| 150 | + |
| 151 | +* Initial release |
| 152 | + |
| 153 | +Brought to you by [nystudio107](https://nystudio107.com) |
0 commit comments