Skip to content

Commit 9860942

Browse files
author
Andrew Welch
committed
[Added] Initial commit
0 parents  commit 9860942

11 files changed

+715
-0
lines changed

LICENSE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The Transcoder License
2+
Copyright (c) 2016 nystudio107
3+
4+
Permission is hereby granted, free of charge, to any person or entity obtaining a copy of this software and associated documentation files (the "Software"), to use the software in any capacity, including commercial and for-profit use. Permission is also granted to alter, modify, or extend the Software for your own use, or commission a third-party to perform modifications for you.
5+
6+
Permission is NOT granted to create derivative works, sublicense, and/or sell copies of the Software. This is not FOSS software.
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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)

TranscoderPlugin.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* Transcoder plugin for Craft CMS
4+
*
5+
* Transcode videos to various formats, and provide thumbnails of the video
6+
*
7+
* @author nystudio107
8+
* @copyright Copyright (c) 2016 nystudio107
9+
* @link http://nystudio107.com
10+
* @package Transcoder
11+
* @since 1.0.0
12+
*/
13+
14+
namespace Craft;
15+
16+
class TranscoderPlugin extends BasePlugin
17+
{
18+
/**
19+
* @return mixed
20+
*/
21+
public function init()
22+
{
23+
}
24+
25+
/**
26+
* @return mixed
27+
*/
28+
public function getName()
29+
{
30+
return Craft::t('Transcoder');
31+
}
32+
33+
/**
34+
* @return mixed
35+
*/
36+
public function getDescription()
37+
{
38+
return Craft::t('Transcode videos to various formats, and provide thumbnails of the video');
39+
}
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getVersion()
45+
{
46+
return '1.1.0';
47+
}
48+
49+
/**
50+
* @return string
51+
*/
52+
public function getSchemaVersion()
53+
{
54+
return '1.0.0';
55+
}
56+
57+
/**
58+
* @return string
59+
*/
60+
public function getDeveloper()
61+
{
62+
return 'nystudio107';
63+
}
64+
65+
/**
66+
* @return string
67+
*/
68+
public function getDeveloperUrl()
69+
{
70+
return 'https://nystudio107.com';
71+
}
72+
73+
/**
74+
* @return string
75+
*/
76+
public function getReleaseFeedUrl()
77+
{
78+
return 'https://raw.githubusercontent.com/nystudio107/transcoder/master/releases.json';
79+
}
80+
81+
/**
82+
* @return string
83+
*/
84+
public function getDocumentationUrl()
85+
{
86+
return 'https://github.com/nystudio107/transcoder/blob/master/README.md';
87+
}
88+
89+
/**
90+
* @return bool
91+
*/
92+
public function hasCpSection()
93+
{
94+
return false;
95+
}
96+
97+
/**
98+
*/
99+
public function onBeforeInstall()
100+
{
101+
}
102+
103+
/**
104+
*/
105+
public function onAfterInstall()
106+
{
107+
}
108+
109+
/**
110+
*/
111+
public function onBeforeUninstall()
112+
{
113+
}
114+
115+
/**
116+
*/
117+
public function onAfterUninstall()
118+
{
119+
}
120+
121+
}

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "nystudio107/transcoder",
3+
"description": "Transcode videos to various formats, and provide thumbnails of the video",
4+
"require": {
5+
"composer/installers": "~1.0"
6+
},
7+
"type": "craft-plugin"
8+
}

config.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Transcoder Configuration
4+
*
5+
* Completely optional configuration settings for Transcoder if you want to customize some
6+
* of its more esoteric behavior, or just want specific control over things.
7+
*
8+
* Don't edit this file, instead copy it to 'craft/config' as 'transcoder.php' and make
9+
* your changes there.
10+
*/
11+
12+
return array(
13+
14+
/**
15+
* The path to the ffmpeg binary
16+
*/
17+
"ffmpegPath" => "/usr/bin/ffmpeg",
18+
19+
/**
20+
* The path where the transcoded videos are stored
21+
*/
22+
23+
"transcoderPath" => $_SERVER['DOCUMENT_ROOT'] . "/transcoder/",
24+
25+
/**
26+
* The URL where the transcoded videos are stored
27+
*/
28+
29+
"transcoderUrl" => "/transcoder/",
30+
);

controllers/TranscoderController.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Transcoder plugin for Craft CMS
4+
*
5+
* Transcode videos to various formats, and provide thumbnails of the video
6+
*
7+
* @author nystudio107
8+
* @copyright Copyright (c) 2016 nystudio107
9+
* @link http://nystudio107.com
10+
* @package Transcoder
11+
* @since 1.0.0
12+
*/
13+
14+
namespace Craft;
15+
16+
class TranscoderController extends BaseController
17+
{
18+
19+
/**
20+
* @var bool|array Allows anonymous access to this controller's actions.
21+
* @access protected
22+
*/
23+
protected $allowAnonymous = array('actionDownloadFile',
24+
);
25+
26+
/**
27+
* Force the download of a given $url. We do it this way to prevent people from downloading
28+
* things that are outside of the server root.
29+
*/
30+
public function actionDownloadFile()
31+
{
32+
$url = urldecode(craft()->request->getParam('url'));
33+
$filepath = parse_url($url, PHP_URL_PATH);
34+
$filepath = $_SERVER['DOCUMENT_ROOT'] . $filepath;
35+
$content = IOHelper::getFileContents($path);
36+
craft()->request->sendFile($path, $content, array('forceDownload' => true), true);
37+
} /* -- actionDownloadFile */
38+
39+
}

releases.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"version": "1.0.0",
4+
"downloadUrl": "???",
5+
"date": "2016-07-05T14:52:56.996Z",
6+
"notes": [
7+
"[Added] Initial release"
8+
]
9+
}
10+
]

0 commit comments

Comments
 (0)