Skip to content

Commit 1265258

Browse files
[Task] Small fixes (#14)
* fix drawtext test * rename BaseFilter to Filter * fix types, add make method, make Tween class final * improve DrawText class * new VideoFilter class * delete CHANGELOG * delete changelog workflow
1 parent e680dad commit 1265258

File tree

7 files changed

+56
-115
lines changed

7 files changed

+56
-115
lines changed

.github/workflows/update-changelog.yml

-31
This file was deleted.

CHANGELOG.md

-7
This file was deleted.

src/Filters/BaseFilter.php src/Filters/Filter.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ProjektGopher\FFMpegTools\Filters;
44

5-
abstract class BaseFilter
5+
abstract class Filter
66
{
77
protected string $filter_name;
88

@@ -22,9 +22,13 @@ public function build(): string
2222
$properties = [];
2323

2424
foreach ($this->properties as $key => $value) {
25-
strpos($value, ' ') !== false
26-
? $properties[] = "{$key}='{$value}'"
27-
: $properties[] = "{$key}={$value}";
25+
$key = strtolower($key);
26+
27+
if (str_contains($value, ' ')) {
28+
$value = "'{$value}'";
29+
}
30+
31+
$properties[] = "{$key}={$value}";
2832
}
2933

3034
$properties = implode(':', $properties);

src/Filters/Video/DrawText.php

+25-66
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,36 @@
22

33
namespace ProjektGopher\FFMpegTools\Filters\Video;
44

5-
use ProjektGopher\FFMpegTools\Filters\BaseFilter;
5+
use ProjektGopher\FFMpegTools\Filters\Filter;
66
use ProjektGopher\FFMpegTools\Filters\Traits\SupportsTimelineEditing;
77

88
/**
99
* DrawText
1010
*
1111
* The parameters for x and y are expressions containing the following constants and functions:
1212
*
13-
* dar
14-
* input display aspect ratio, it is the same as (w / h) * sar
15-
*
16-
* hsub
17-
* vsub
18-
* horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.
19-
*
20-
* line_h, lh
21-
* the height of each text line
22-
*
23-
* main_h, h, H
24-
* the input height
25-
*
26-
* main_w, w, W
27-
* the input width
28-
*
29-
* max_glyph_a, ascent
30-
* the maximum distance from the baseline to the highest/upper grid coordinate used to place a glyph outline point, for all the rendered glyphs. It is a positive value, due to the grid’s orientation with the Y axis upwards.
31-
*
32-
* max_glyph_d, descent
33-
* the maximum distance from the baseline to the lowest grid coordinate used to place a glyph outline point, for all the rendered glyphs. This is a negative value, due to the grid’s orientation, with the Y axis upwards.
34-
*
35-
* max_glyph_h
36-
* maximum glyph height, that is the maximum height for all the glyphs contained in the rendered text, it is equivalent to ascent - descent.
37-
*
38-
* max_glyph_w
39-
* maximum glyph width, that is the maximum width for all the glyphs contained in the rendered text
40-
*
41-
* n
42-
* the number of input frame, starting from 0
43-
*
44-
* rand(min, max)
45-
* return a random number included between min and max
46-
*
47-
* sar
48-
* The input sample aspect ratio.
49-
*
50-
* t
51-
* timestamp expressed in seconds, NAN if the input timestamp is unknown
52-
*
53-
* text_h, th
54-
* the height of the rendered text
55-
*
56-
* text_w, tw
57-
* the width of the rendered text
58-
*
59-
* x
60-
* y
61-
* the x and y offset coordinates where the text is drawn.
62-
*
63-
* These parameters allow the x and y expressions to refer to each other, so you can for example specify y=x/dar.
64-
*
65-
* pict_type
66-
* A one character description of the current frame’s picture type.
67-
*
68-
* pkt_pos
69-
* The current packet’s position in the input file or stream (in bytes, from the start of the input). A value of -1 indicates this info is not available.
70-
*
71-
* duration
72-
* The current packet’s duration, in seconds.
73-
*
74-
* pkt_size
75-
* The current packet’s size (in bytes).
13+
* dar - input display aspect ratio, it is the same as (w / h) * sar
14+
* hsub - horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.
15+
* vsub - horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.
16+
* line_h, lh - the height of each text line
17+
* main_h, h, H - the input height
18+
* main_w, w, W - the input width
19+
* max_glyph_a, ascent - the maximum distance from the baseline to the highest/upper grid coordinate used to place a glyph outline point, for all the rendered glyphs. It is a positive value, due to the grid’s orientation with the Y axis upwards.
20+
* max_glyph_d, descent - the maximum distance from the baseline to the lowest grid coordinate used to place a glyph outline point, for all the rendered glyphs. This is a negative value, due to the grid’s orientation, with the Y axis upwards.
21+
* max_glyph_h - maximum glyph height, that is the maximum height for all the glyphs contained in the rendered text, it is equivalent to ascent - descent.
22+
* max_glyph_w - maximum glyph width, that is the maximum width for all the glyphs contained in the rendered text
23+
* n - the number of input frame, starting from 0
24+
* rand(min, max) - return a random number included between min and max
25+
* sar - The input sample aspect ratio.
26+
* t - timestamp expressed in seconds, NAN if the input timestamp is unknown
27+
* text_h, th - the height of the rendered text
28+
* text_w, tw - the width of the rendered text
29+
* x - the x and y offset coordinates where the text is drawn. These parameters allow the x and y expressions to refer to each other, so you can for example specify y=x/dar.
30+
* y - the x and y offset coordinates where the text is drawn. These parameters allow the x and y expressions to refer to each other, so you can for example specify y=x/dar.
31+
* pict_type - A one character description of the current frame’s picture type.
32+
* pkt_pos - The current packet’s position in the input file or stream (in bytes, from the start of the input). A value of -1 indicates this info is not available.
33+
* duration - The current packet’s duration, in seconds.
34+
* pkt_size - The current packet’s size (in bytes).
7635
*
7736
* @see https://ffmpeg.org/ffmpeg-filters.html#drawtext-1
7837
*
@@ -92,7 +51,7 @@
9251
* @method self font(string $value) Set the font family to be used for drawing text. By default Sans.
9352
* @method self fontfile(string $value) Set the font file to be used for drawing text. The path must be included. This parameter is mandatory if the fontconfig support is disabled.
9453
* @method self alpha(string $value) Draw the text applying alpha blending. The value can be a number between 0.0 and 1.0. The expression accepts the same variables x, y as well. The default value is 1. Please see fontcolor_expr.
95-
* @method self fontsize(int $value) Set the font size to be used for drawing text. The default value of fontsize is 16.
54+
* @method self fontsize(string $value) Set the font size to be used for drawing text. The default value of fontsize is 16.
9655
* @method self text_shaping(int $value) If set to 1, attempt to shape the text (for example, reverse the order of right-to-left text and join Arabic characters) before drawing it. Otherwise, just draw the text exactly as given. By default 1 (if supported).
9756
* @method self ft_load_flags(int $value) The flags to be used for loading the fonts. The flags map the corresponding flags supported by libfreetype, and are a combination of the following values: default no_scale no_hinting render no_bitmap vertical_layout force_autohint crop_bitmap pedantic ignore_global_advance_width no_recurse ignore_transform monochrome linear_design no_autohint Default value is "default". For more information consult the documentation for the FT_LOAD_* libfreetype flags.
9857
* @method self shadowcolor(string $value) The color to be used for drawing a shadow behind the drawn text. For the syntax of this option, check the (ffmpeg-utils)"Color" section in the ffmpeg-utils manual. The default value of shadowcolor is "black".
@@ -112,7 +71,7 @@
11271
* @method self x(string $value) The expressions which specify the offsets where text will be drawn within the video frame. They are relative to the top/left border of the output image. The default value of x and y is "0".
11372
* @method self y(string $value) The expressions which specify the offsets where text will be drawn within the video frame. They are relative to the top/left border of the output image. The default value of x and y is "0".
11473
*/
115-
final class DrawText extends BaseFilter
74+
final class DrawText extends Filter
11675
{
11776
use SupportsTimelineEditing;
11877

src/Filters/Video/VideoFilter.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace ProjektGopher\FFMpegTools\Filters\Video;
4+
5+
class VideoFilter
6+
{
7+
public static function drawtext(): DrawText
8+
{
9+
return new DrawText();
10+
}
11+
}

src/Tween.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use ProjektGopher\FFMpegTools\Utils\Expr;
66

7-
class Tween
7+
final class Tween
88
{
99
protected string $from;
1010

@@ -16,14 +16,14 @@ class Tween
1616

1717
protected string $ease;
1818

19-
public function from(string $from): self
19+
public function from(string|int|float $from): self
2020
{
2121
$this->from = "({$from})";
2222

2323
return $this;
2424
}
2525

26-
public function to(string $to): self
26+
public function to(string|int|float $to): self
2727
{
2828
$this->to = "({$to})";
2929

@@ -95,4 +95,9 @@ public static function __callStatic(string $name, array $arguments): self
9595
{
9696
return (new self)->$name(...$arguments);
9797
}
98+
99+
public static function make(): self
100+
{
101+
return new self;
102+
}
98103
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
use ProjektGopher\FFMpegTools\Filters\Video\DrawText;
3+
use ProjektGopher\FFMpegTools\Filters\Video\VideoFilter;
44

55
it('works', function () {
66
expect(
7-
(string) DrawText::make()
7+
(string) VideoFilter::drawtext()
88
->text('Hello World')
99
->x(10)
1010
->y(10)
11-
->fontSize(20)
12-
->fontColor('white')
11+
->fontsize(20)
12+
->fontcolor('white')
1313
->box(1)
1414
)->toEqual("drawtext=text='Hello World':x=10:y=10:fontsize=20:fontcolor=white:box=1");
1515
});

0 commit comments

Comments
 (0)