@@ -49,10 +49,7 @@ public function getVideoUrl($filePath, $videoOptions): string
4949 $ destVideoPath = Craft::$ app ->config ->get ("transcoderPath " , "transcoder " );
5050
5151 // Default options for transcoded videos
52- $ defaultOptions = [
53- "bitRate " => "800k " ,
54- "frameRate " => 15 ,
55- ];
52+ $ defaultOptions = Craft::$ app ->config ->get ("defaultVideoOptions " , "transcoder " );
5653
5754 // Coalesce the passed in $videoOptions with the $defaultOptions
5855 $ videoOptions = array_merge ($ defaultOptions , $ videoOptions );
@@ -69,13 +66,13 @@ public function getVideoUrl($filePath, $videoOptions): string
6966 .' -threads 0 ' ;
7067
7168 // Set the framerate if desired
72- if ($ videoOptions ['frameRate ' ]) {
69+ if (! empty ( $ videoOptions ['frameRate ' ]) ) {
7370 $ ffmpegCmd .= ' -r ' .$ videoOptions ['frameRate ' ];
7471 $ destVideoFile .= '_ ' .$ videoOptions ['frameRate ' ].'fps ' ;
7572 }
7673
7774 // Set the bitrate if desired
78- if ($ videoOptions ['bitRate ' ]) {
75+ if (! empty ( $ videoOptions ['bitRate ' ]) ) {
7976 $ ffmpegCmd .= ' -b:v ' .$ videoOptions ['bitRate ' ].' -maxrate ' .$ videoOptions ['bitRate ' ];
8077 $ destVideoFile .= '_ ' .$ videoOptions ['bitRate ' ].'bps ' ;
8178 }
@@ -105,7 +102,6 @@ public function getVideoUrl($filePath, $videoOptions): string
105102 if (file_exists ($ destVideoPath ) && (filemtime ($ destVideoPath ) >= filemtime ($ filePath ))) {
106103 $ result = Craft::$ app ->config ->get ("transcoderUrl " , "transcoder " ).$ destVideoFile ;
107104 } else {
108-
109105 // Kick off the transcoding
110106 $ pid = shell_exec ($ ffmpegCmd );
111107 Craft::info ($ ffmpegCmd , __METHOD__ );
@@ -138,11 +134,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
138134 $ destThumbnailPath = Craft::$ app ->config ->get ("transcoderPath " , "transcoder " );
139135
140136 // Default options for video thumbnails
141- $ defaultOptions = [
142- "width " => 200 ,
143- "height " => 100 ,
144- "timeInSecs " => 10 ,
145- ];
137+ $ defaultOptions = Craft::$ app ->config ->get ("defaultThumbnailOptions " , "transcoder " );
146138
147139 // Coalesce the passed in $thumbnailOptions with the $defaultOptions
148140 $ thumbnailOptions = array_merge ($ defaultOptions , $ thumbnailOptions );
@@ -154,15 +146,15 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
154146 .' -vframes 1 ' ;
155147
156148 // Set the width & height if desired
157- if ($ thumbnailOptions ['width ' ] && $ thumbnailOptions ['height ' ]) {
149+ if (! empty ( $ thumbnailOptions ['width ' ]) && ! empty ( $ thumbnailOptions ['height ' ]) ) {
158150 $ ffmpegCmd .= ' -vf "scale= '
159151 .$ thumbnailOptions ['width ' ].': ' .$ thumbnailOptions ['height ' ]
160152 .', unsharp=5:5:1.0:5:5:0.0" ' ;
161153 $ destThumbnailFile .= '_ ' .$ thumbnailOptions ['width ' ].'x ' .$ thumbnailOptions ['height ' ];
162154 }
163155
164156 // Set the timecode to get the thumbnail from if desired
165- if ($ thumbnailOptions ['timeInSecs ' ]) {
157+ if (! empty ( $ thumbnailOptions ['timeInSecs ' ]) ) {
166158 $ timeCode = gmdate ("H:i:s " , $ thumbnailOptions ['timeInSecs ' ]);
167159 $ ffmpegCmd .= ' -ss ' .$ timeCode .'.00 ' ;
168160 $ destThumbnailFile .= '_ ' .$ thumbnailOptions ['timeInSecs ' ].'s ' ;
0 commit comments