📝 Document listeners

And other stuff
This commit is contained in:
Dan Jones 2022-09-06 12:44:56 -05:00
commit e07743625c

View file

@ -88,11 +88,62 @@ ffmpeg -y -i video.mp4 -i audio.opus -i sub.srt -map 0:0 -c:0 libvp9 -map 1:0 -c
This will result in two files. The first will be a webm file (suitable for play in a browser) with a `title` field on the file set to "The Greatest Story Ever Hulaed". The second file will copy the first stream from each file directly, and set the language of the subtitle stream to English.
## What's not yet done?
### Using FormatInterface
Mostly documentation. There are a lot more ways to use this, including using the `Format` objects from PHP-FFMpeg to set the codecs, and the ability to use callbacks to set additional data on both maps and individual streams.
It is also possible to set the codec from a stream using the [Formats](https://github.com/PHP-FFMpeg/PHP-FFMpeg/#formats) from PHP-FFMPEG.
I also need to figure out how to set the listeners on the codecs to get realtime progress updates (see [Formats](https://github.com/PHP-FFMpeg/PHP-FFMpeg/#formats)). Once that's figured out, I need to document it properly here.
```php
use FFMpeg\Format\Video\X264;
MappableMedia::make($ffmpeg)
->addInput('input.mkv')
->map()
->saveAs('output.mk')
->stream()->setCodec(new X264())->saveStream()
->saveMap()
->save()
```
### Using callbacks
The `map` and `stream` methods can take an optional callback, allowing you to set the properties on those individual objects. When a callback is passed the object itself is returned, allowing you to continue the chain.
```php
MappableMedia::make($ffmpeg)
->addInput('input.mkv')
->map(function (Map $map) {
$map->saveAs('output.mk')
->stream(function (Stream $stream) {
$stream->copy()->setInput('0:0');
});
})->save()
```
Note that when using callbacks, you also don't need to call `saveMap()` or `saveStream()`.
### Getting progress updates
It is possible to set a listener on the individual streams, using the Format class. However, this don't reliably report the progress of a particular stream. So, this package adds a listener on the `MappableMedia` object itself, which represents the progress of the entire job.
```php
MappableMedia::make($ffmpeg)
->addInput('input.mkv')
->map()
->saveAs('output.mk')
->stream()->copy()->saveStream()
->saveMap()
->on('progress', function (MappableMedia $media, int $percent, int $remaining, int $rate) {
echo "Finished {$percent}% of ", $media->getPathfile(), "\n";
})
->save()
```
## Future Plans
- [ ] Add listeners that return all the stdin/stderr
- [ ] Support itsoffset for inputs
- [ ] Support -t and -ss
+ I need to figure out how this will affect the progress listener.
## Contributing