Skip to content

Commit bd012ba

Browse files
bug fixes
1 parent 4c970b3 commit bd012ba

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $video = $ffmpeg->open('/var/www/media/videos/test.mp4');
8181
#### 2. From Clouds
8282
You can open a file from a cloud by passing an array of cloud configuration to the `openFromCloud` method. There are some options to open a file from **[Amazon Web Services (AWS)](https://aws.amazon.com/)**, **[Google Cloud Storage](https://console.cloud.google.com/storage)**, **[Microsoft Azure Storage](https://azure.microsoft.com/en-us/features/storage-explorer/)**, and a custom cloud.
8383

84-
Please **[visit the 'open a file from a cloud' page](https://video.aminyazdanpanah.com/start/open-clouds)** to see more examples and usage of these clouds.
84+
Please visit **[this page](https://video.aminyazdanpanah.com/start/open-clouds)** to see more examples and usage of these clouds.
8585
``` php
8686
$video = $ffmpeg->openFromCloud($from_google_cloud);
8787
```
@@ -179,7 +179,7 @@ $current_percentage = 0;
179179
$format->on('progress', function ($video, $format, $percentage) use (&$current_percentage) {
180180
$percentage = intval($percentage);
181181
if ($current_percentage !== $percentage) {
182-
// You can update a field in your database or log it into a file
182+
// You can update a field in your database or log it to a file
183183
// You can also create a socket connection and show the progress to users
184184
echo sprintf("\r Transcoding... (%s%%)[%s%s]", $percentage, str_repeat('#', $percentage), str_repeat('-', (99 - $percentage)));
185185
$current_percentage = $percentage;
@@ -222,7 +222,7 @@ $hls->save();
222222
#### 2. To Clouds
223223
You can save your files to a cloud by passing an array of cloud configuration to the `save` method. There are some options to save files to **[Amazon Web Services (AWS)](https://aws.amazon.com/)**, **[Google Cloud Storage](https://console.cloud.google.com/storage)**, **[Microsoft Azure Storage](https://azure.microsoft.com/en-us/features/storage-explorer/)**, and a custom cloud.
224224

225-
Please **[visit the 'save files to clouds' page](https://video.aminyazdanpanah.com/start/save-clouds)** to see more examples and usage of these clouds.
225+
Please visit **[this page](https://video.aminyazdanpanah.com/start/save-clouds)** to see more examples and usage of these clouds.
226226
``` php
227227
$dash->save(null, [$to_aws_cloud, $to_google_cloud, $to_microsoft_azure, $to_custom_cloud]);
228228
```
@@ -231,9 +231,10 @@ A path can also be passed to save a copy of files on your local machine.
231231
$hls->save('/var/www/media/videos/hls/test.m3u8', [$to_google_cloud, $to_custom_cloud]);
232232
```
233233

234-
**NOTE:** You can open a file from your local machine(or a cloud) and save files to a local path or a cloud(or multiple clouds).
234+
**NOTE:** You can open a file from your local machine(or a cloud) and save files to a local path or a cloud(or multiple clouds) or both.
235+
236+
<p align="center"><img src="https://github.com/aminyazdanpanah/aminyazdanpanah.github.io/blob/master/video-streaming/video-streaming.gif?raw=true" width="100%"></p>
235237

236-
![schema](/docs/schema.gif?raw=true "schema" )
237238

238239
### Metadata Extraction
239240
After saving files(wherever you saved them), you can extract the metadata from the video and streams. You can save these metadata to your database.

src/Export.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private function moveTmpFolder(?string $path)
166166
if ($this->tmp_dir && $path) {
167167
FileManager::moveDir($this->tmp_dir, pathinfo($path, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR);
168168
$this->path_info = pathinfo($path);
169+
$this->tmp_dir = '';
169170
}
170171
}
171172

@@ -203,6 +204,14 @@ public function getStrict(): string
203204
return $this->strict;
204205
}
205206

207+
/**
208+
* @return bool
209+
*/
210+
public function isTmpDir(): bool
211+
{
212+
return (bool)$this->tmp_dir;
213+
}
214+
206215
/**
207216
* clear tmp files
208217
*/

src/Metadata.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public function extract()
3737
$metadata["video"] = $this->getVideoMetadata();
3838
$metadata["streams"] = $this->getStreamsMetadata();
3939

40-
$name = $this->export->getPathInfo()["filename"] . "-" . bin2hex(openssl_random_pseudo_bytes(6)) . ".json";
41-
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . $name;
42-
file_put_contents($filename, json_encode($metadata, JSON_PRETTY_PRINT));
40+
$filename = 'It is not possible to save metadata to clouds.';
41+
if(!$this->export->isTmpDir()){
42+
$filename = $this->saveAsJson($metadata);
43+
}
4344

4445
return [
4546
'filename' => $filename,
@@ -112,4 +113,13 @@ private function getResolutions()
112113

113114
return $resolutions;
114115
}
116+
117+
private function saveAsJson($metadata)
118+
{
119+
$name = $this->export->getPathInfo()["filename"] . "-" . bin2hex(openssl_random_pseudo_bytes(6)) . ".json";
120+
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . $name;
121+
file_put_contents($filename, json_encode($metadata, JSON_PRETTY_PRINT));
122+
123+
return $filename;
124+
}
115125
}

0 commit comments

Comments
 (0)