You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-99Lines changed: 70 additions & 99 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Transcoder plugin for Craft CMS 3.x
2
2
3
-
Transcode videos to various formats, and provide thumbnails of the video
3
+
Transcode video & audio files to various formats, and provide video thumbnails
4
4
5
5
Related: [Transcoder for Craft 2.x](https://github.com/nystudio107/transcoder)
6
6
@@ -24,90 +24,19 @@ If you have managed hosting, contact your sysadmin to get `ffmpeg` installed.
24
24
25
25
## Transcoder Overview
26
26
27
-
The Transcoder video allows you to take any locally stored video, and transcode it into any size, bitrate, framerate, and save it out as a web-ready `.mp4`video file.
27
+
The Transcoder allows you to take any locally stored video, and transcode it into any size, bitrate, framerate, and save it out as a web-ready video in a variety of file formats.
28
28
29
-
It also allows you to get a thumbnail of the video in any size and at any timecode.
29
+
It can also transcode audio files to any bitrate & sample rate, to a variety of file formats. It can even extract audio tracks from video files.
30
+
31
+
It also allows you to get a thumbnail of a video in any size and at any timecode, and can extract information about audio/video files such.
30
32
31
33
Finally, it lets you download an arbitrary file (such as the transcoded video) via a special download link.
32
34
33
-
If the source file has changed since the last time the video was encoded, it will re-encode the video and replace it.
35
+
If the source file has changed since the last time the video/audio was transcoded, it will re-encode the file and replace it.
34
36
35
37
## Configuring Transcoder
36
38
37
-
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:
38
-
39
-
<?php
40
-
/**
41
-
* Transcoder plugin for Craft CMS 3.x
42
-
*
43
-
* Transcode videos to various formats, and provide thumbnails of the video
44
-
*
45
-
* @link https://nystudio107.com
46
-
* @copyright Copyright (c) 2017 nystudio107
47
-
*/
48
-
49
-
/**
50
-
* Transcoder config.php
51
-
*
52
-
* Completely optional configuration settings for Transcoder if you want to
53
-
* customize some of its more esoteric behavior, or just want specific control
54
-
* over things.
55
-
*
56
-
* Don't edit this file, instead copy it to 'craft/config' as 'transcoder.php'
57
-
* and make your changes there.
58
-
*
59
-
* Once copied to 'craft/config', this file will be multi-environment aware as
60
-
* well, so you can have different settings groups for each environment, just as
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.
111
40
112
41
## Using Transcoder
113
42
@@ -116,8 +45,8 @@ The only configuration for Transcoder is in the `config.php` file, which is a mu
116
45
To generate a transcoded video, do the following:
117
46
118
47
{% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/oceans.mp4', {
119
-
"frameRate": 20,
120
-
"bitRate": "500k",
48
+
"videoFrameRate": 20,
49
+
"videoBitRate": "500k",
121
50
"width": 720,
122
51
"height": 480
123
52
}) %}
@@ -126,8 +55,8 @@ You can also pass in an `Asset`:
126
55
127
56
{% set myAsset = entry.someAsset.first() %}
128
57
{% set transVideoUrl = craft.transcoder.getVideoUrl(myAsset, {
129
-
"frameRate": 20,
130
-
"bitRate": "500k",
58
+
"videoFrameRate": 20,
59
+
"videoBitRate": "500k",
131
60
"width": 720,
132
61
"height": 480
133
62
}) %}
@@ -137,25 +66,23 @@ It will return to you a URL to the transcoded video if it already exists, or if
137
66
In the array you pass in, the default values are used if the key/value pair does not exist:
138
67
139
68
{
140
-
"bitRate" => "800k",
141
-
"frameRate" => 15,
69
+
"videoFormat" => "mp4",
70
+
"videoBitRate" => "800k",
71
+
"videoFrameRate" => 15,
142
72
"aspectRatio" => "letterbox",
143
73
"sharpen" => true,
144
-
"fileSuffix" => ".mp4",
145
-
"videoFormat" => "mp4",
146
-
"videoCodec" => "libx264",
147
74
}
148
75
149
76
These default values come from the `config.php` file.
150
77
151
78
If you want to have the Transcoder not change a parameter, pass in an empty value in the key/value pair, e.g.:
152
79
153
-
{% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', {
80
+
{% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/oceans.mp4', {
154
81
"frameRate": "",
155
82
"bitRate": ""
156
83
}) %}
157
84
158
-
The above example would cause it to not change the frameRate or bitRate of the source movie (not recommended for client-proofing purposes).
85
+
The above example would cause it to not change the frameRate or bitRate of the source video (not recommended for client-proofing purposes).
159
86
160
87
The `aspectRatio` parameter lets you control how the video aspect ratio is maintained when it is scaled:
161
88
@@ -175,16 +102,60 @@ You can control the color of the letterboxed area (it's `black` by default) via
175
102
176
103
The `sharpen` option determines whether an unsharp mask filter should be applied to the scaled video.
177
104
178
-
The file format settings `fileSuffix`, `videoFormat`, and `videoCodec` are all preset to what you'll need to generate `.mp4` videos. Change these only if you know what you're doing.
105
+
The file format setting `videoFormat` is preset to what you'll need to generate `mp4` videos, but it can also generate `webm` videos, or any other format that `ffmpeg` supports. See the `config.php` file for details
106
+
107
+
### Generating a Transcoded Audio File
108
+
109
+
To generate a transcoded audio File, do the following:
110
+
111
+
{% set transAudioUrl = craft.transcoder.getAudioUrl('/home/vagrant/sites/nystudio107/public/podcast.mp3', {
112
+
"audioBitRate": "64k",
113
+
"audioSampleRate": 22050,
114
+
"audioChannels": 1
115
+
}) %}
116
+
117
+
You can also pass in an `Asset`:
118
+
119
+
{% set myAsset = entry.someAsset.first() %}
120
+
{% set transAudioUrl = craft.transcoder.getAudioUrl(myAsset, {
121
+
"audioBitRate": "64k",
122
+
"audioSampleRate": 22050,
123
+
"audioChannels": 1
124
+
}) %}
125
+
126
+
It will return to you a URL to the transcoded audio file if it already exists, or if it doesn't exist, it will return `""` and kick off the transcoding process (which can be somewhat lengthy for long audio files).
127
+
128
+
In the array you pass in, the default values are used if the key/value pair does not exist:
129
+
130
+
{
131
+
"audioFormat" => "mp3",
132
+
"audioBitRate" => "128k",
133
+
"audioSampleRate" => "44100",
134
+
"audioChannels" => "2",
135
+
}
136
+
137
+
These default values come from the `config.php` file.
138
+
139
+
If you want to have the Transcoder not change a parameter, pass in an empty value in the key/value pair, e.g.:
140
+
141
+
{% set transVideoUrl = craft.transcoder.getVideoUrl('/home/vagrant/sites/nystudio107/public/trimurti.mp4', {
142
+
"audioBitRate": "",
143
+
"audioSampleRate": "",
144
+
"audioChannels": ""
145
+
}) %}
146
+
147
+
The above example would cause it to not change the audio of the source audio file at all (not recommended for client-proofing purposes).
148
+
149
+
The file format setting `audioFormat` is preset to what you'll need to generate `mp3` audio files, but it can also generate `m4a`, `ogg`, or any other format that `ffmpeg` supports. See the `config.php` file for details
179
150
180
151
### Getting Transcoding Progress
181
152
182
-
Transcoding of videos can take quite a bit of time, so Transcoder provides you with a way to get the status of any currently running transcoding operation via `craft.transcoder.getVideoProgressUrl()`. For example:
153
+
Transcoding of video/audio files can take quite a bit of time, so Transcoder provides you with a way to get the status of any currently running transcoding operation via `craft.transcoder.getVideoProgressUrl()` or `craft.transcoder.getAudioProgressUrl()`. For example:
183
154
184
155
{% set myAsset = entry.someAsset.first() %}
185
156
{% set videoOptions = {
186
-
"frameRate": 60,
187
-
"bitRate": "1000k",
157
+
"videoFrameRate": 60,
158
+
"videoBitRate": "1000k",
188
159
"width": 1000,
189
160
"height": 800,
190
161
"aspectRatio": "none",
@@ -267,23 +238,23 @@ You can control the color of the letterboxed area (it's `black` by default) via
267
238
268
239
The `sharpen` option determines whether an unsharp mask filter should be applied to the scaled thumbnail image.
269
240
270
-
### Getting Information About a Video
241
+
### Getting Information About a Video/Audio File
271
242
272
-
To get information about an existing video, you can use `craft.transcoder.getFileInfo()`:
243
+
To get information about an existing video/audio file, you can use `craft.transcoder.getFileInfo()`:
273
244
274
-
{% set transVideoUrl = craft.transcoder.getFileInfo('/home/vagrant/sites/nystudio107/public/oceans.mp4') %}
245
+
{% set fileInfo = craft.transcoder.getFileInfo('/home/vagrant/sites/nystudio107/public/oceans.mp4') %}
275
246
276
247
You can also pass in an `Asset`:
277
248
278
249
{% set myAsset = entry.someAsset.first() %}
279
-
{% set transVideoUrl = craft.transcoder.getFileInfo(myAsset) %}
250
+
{% set fileInfo = craft.transcoder.getFileInfo(myAsset) %}
280
251
281
252
This returns an array with two top-level keys:
282
253
283
254
*`format` - information about the container file format
284
255
*`streams` - information about each stream in the container; many videos have multiple streams, for instance, one for the video streams, and another for the audio stream. There can even be multiple video or audio streams in a container.
285
256
286
-
Here's example output from `craft.transcoder.getFileInfo`:
257
+
Here's example output from `craft.transcoder.getFileInfo()`:
287
258
288
259
[
289
260
'streams' => [
@@ -416,6 +387,6 @@ The file must reside in the webroot (thus a URL or URI must be passed in as a pa
416
387
417
388
Some things to do, and ideas for potential features:
418
389
419
-
*The videos could potentially be saved in different formats (though `.mp4` really is "the" standard for video)
390
+
*Add a simpler way to extract the most common video/audio info from a file
420
391
421
392
Brought to you by [nystudio107](https://nystudio107.com)
0 commit comments