Skip to content

Commit 58de6e9

Browse files
committed
### Added
- Added support for multiple video encoding formats - Added the ability to transcode audio files - Transcoder caches can be cleared via the ClearCaches utility
1 parent accc27d commit 58de6e9

File tree

6 files changed

+304
-28
lines changed

6 files changed

+304
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- The `ffmpeg` progress for video transcoding is now written out to a `.progress` file
1111
- Added a `progress` controller to return video transcoding progress
1212
- Moved all of the default settings out to the `config.php` file
13+
- Added support for multiple video encoding formats
14+
- Added the ability to transcode audio files
15+
- Transcoder caches can be cleared via the ClearCaches utility
1316

1417
### Fixed
1518
- Fixed some issues with the lockfile naming

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If you have managed hosting, contact your sysadmin to get `ffmpeg` installed.
2424

2525
## Transcoder Overview
2626

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` file.
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.
2828

2929
It also allows you to get a thumbnail of the video in any size and at any timecode.
3030

@@ -89,6 +89,10 @@ The only configuration for Transcoder is in the `config.php` file, which is a mu
8989
// Can be "none", "crop", or "letterbox"
9090
"aspectRatio" => "letterbox",
9191
"letterboxColor" => "",
92+
// File format settings
93+
"fileSuffix" => ".mp4",
94+
"videoFormat" => "mp4",
95+
"videoCodec" => "libx264",
9296
],
9397

9498
// Default options for video thumbnails
@@ -137,6 +141,9 @@ In the array you pass in, the default values are used if the key/value pair does
137141
"frameRate" => 15,
138142
"aspectRatio" => "letterbox",
139143
"sharpen" => true,
144+
"fileSuffix" => ".mp4",
145+
"videoFormat" => "mp4",
146+
"videoCodec" => "libx264",
140147
}
141148

142149
These default values come from the `config.php` file.
@@ -168,6 +175,8 @@ You can control the color of the letterboxed area (it's `black` by default) via
168175

169176
The `sharpen` option determines whether an unsharp mask filter should be applied to the scaled video.
170177

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.
179+
171180
### Getting Transcoding Progress
172181

173182
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:

src/Transcoder.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
use Craft;
1616
use craft\base\Plugin;
17-
use craft\services\Plugins;
18-
use craft\events\PluginEvent;
19-
use craft\web\UrlManager;
20-
use craft\events\RegisterUrlRulesEvent;
17+
use craft\events\RegisterCacheOptionsEvent;
18+
use craft\utilities\ClearCaches;
2119
use yii\base\Event;
2220

2321
/**
@@ -46,6 +44,19 @@ public function init()
4644
parent::init();
4745
self::$plugin = $this;
4846

47+
// Add the Transcoder path to the list of things the Clear Caches tool can delete.
48+
Event::on(
49+
ClearCaches::className(),
50+
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
51+
function (RegisterCacheOptionsEvent $event) {
52+
$event->options[] = [
53+
'key' => 'transcoder',
54+
'label' => Craft::t('transcoder', 'Transcoder caches'),
55+
'action' => Craft::$app->config->get("transcoderPath", "transcoder")
56+
];
57+
}
58+
);
59+
4960
Craft::info('Transcoder ' . Craft::t('transcoder', 'plugin loaded'), __METHOD__);
5061
}
5162

src/config.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,64 @@
3434
// The options to use for ffprobe
3535
"ffprobeOptions" => "-v quiet -print_format json -show_format -show_streams",
3636

37-
// The path where the transcoded videos are stored
37+
// The path where the transcoded videos are stored; must have a trailing /
3838
"transcoderPath" => $_SERVER['DOCUMENT_ROOT'] . "/transcoder/",
3939

40-
// The URL where the transcoded videos are stored
40+
// The URL where the transcoded videos are stored; must have a trailing /
4141
"transcoderUrl" => "/transcoder/",
4242

43+
// Use a md5 hash for the filenames instead of parameterized naming
44+
"useHashedNames" => false,
45+
46+
// Preset video encoders
47+
"videoEncoders" => [
48+
"mp4" => [
49+
"fileSuffix" => ".mp4",
50+
"videoCodec" => "libx264",
51+
"videoCodecOptions" => "-vprofile high -preset slow -crf 22",
52+
"audioCodec" => "libfdk_aac",
53+
"audioCodecOptions" => "-async 1000",
54+
],
55+
"webm" => [
56+
"fileSuffix" => ".webm",
57+
"videoCodec" => "libvpx",
58+
"videoCodecOptions" => "-quality good -cpu-used 0",
59+
"audioCodec" => "libvorbis",
60+
"audioCodecOptions" => "-async 1000",
61+
],
62+
],
63+
64+
// Preset audio encoders
65+
"audioEncoders" => [
66+
"mp3" => [
67+
"fileSuffix" => ".mp3",
68+
"audioCodec" => "libmp3lame",
69+
"audioCodecOptions" => "",
70+
],
71+
"m4a" => [
72+
"fileSuffix" => ".m4a",
73+
"audioCodec" => "libfdk_aac",
74+
"audioCodecOptions" => "",
75+
76+
],
77+
"ogg" => [
78+
"fileSuffix" => ".ogg",
79+
"audioCodec" => "libvorbis",
80+
"audioCodecOptions" => "",
81+
],
82+
],
83+
4384
// Default options for encoded videos
4485
"defaultVideoOptions" => [
45-
"fileSuffix" => ".mp4",
46-
"bitRate" => "800k",
47-
"frameRate" => 15,
86+
// Video settings
87+
"videoFormat" => "mp4",
88+
"videoBitRate" => "800k",
89+
"videoFrameRate" => 15,
90+
// Audio settings
91+
"audioBitRate" => "",
92+
"audioSampleRate" => "",
93+
"audioChannels" => "",
94+
// Spatial settings
4895
"width" => "",
4996
"height" => "",
5097
"sharpen" => true,
@@ -65,4 +112,12 @@
65112
"letterboxColor" => "",
66113
],
67114

115+
// Default options for encoded videos
116+
"defaultAudioOptions" => [
117+
"audioFormat" => "mp3",
118+
"audioBitRate" => "128k",
119+
"audioSampleRate" => "44100",
120+
"audioChannels" => "2",
121+
],
122+
68123
];

0 commit comments

Comments
 (0)