@@ -21,7 +21,7 @@ Clone the repository and install the dependencies:
21
21
``` bash
22
22
git clone https://github.com/heristop/ffmpeg-template-assembly.git
23
23
cd ffmpeg-template-assembly
24
- pnpm install
24
+ pnpm i
25
25
```
26
26
27
27
### Configuration
@@ -30,90 +30,103 @@ Create a JSON file (e.g., `sample.json`) in the `src/shared/templates` directory
30
30
31
31
### Usage
32
32
33
- 1 . To use the ` ffmpeg-template-assembly ` , you can run the compile command with the path to your template JSON file as an argument:
33
+ #### Command Line Interface
34
+
35
+ To use the ` ffmpeg-template-assembly ` , you can run the compile command with the path to your template JSON file as an argument:
34
36
35
37
``` bash
36
- pnpm compile your-template .json
38
+ pnpm compile src/shared/templates/sample .json
37
39
```
38
40
39
- This will compile the video based on the specified template.
41
+ This will generate a video named ` sample_output.mp4 ` in the ` build ` directory.
42
+
43
+ #### Compilation Function
40
44
41
- 2 . You might provide a configuration object and the path to your template JSON file :
45
+ Import the ` compile ` function from the package and provide a project configuration object :
42
46
43
47
``` javascript
44
48
import { compile } from ' ffmpeg-template-assembly' ;
45
49
46
- async function buildVideo () {
47
- const templateDescriptor = {
48
- " global" : {
49
- " variables" : {
50
- " videoDemo" : " https://file-examples.com/storage/fee4e04377657b56c9a6785/2017/04/file_example_MP4_1280_10MG.mp4" ,
51
- " colorsList" : [" #FFFFFF" ," #000000" ]
52
- },
53
- " orientation" : " landscape" ,
54
- " musicEnabled" : true ,
55
- " transitionDuration" : 0.5
50
+ // Project Configuration
51
+ const projectConfig: ProjectConfig = {
52
+ assetsDir: ' ./src/shared/assets' ,
53
+ currentLocale: ' en' ,
54
+ fields: {
55
+ form_1_firstname: ' Firsname' ,
56
+ form_1_lastname: ' Lastname' ,
57
+ form_1_job: ' Developer' ,
58
+ form_2_keyword1: ' One' ,
59
+ form_2_keyword2: ' Two' ,
60
+ form_2_keyword3: ' Three' ,
61
+ },
62
+ };
63
+ ```
64
+
65
+ You might provide a template descriptor to the ` compile ` function to generate a video:
66
+
67
+ ``` javascript
68
+ const templateDescriptor = {
69
+ " global" : {
70
+ " variables" : {
71
+ " videoDemo" : " https://github.com/heristop/ffmpeg-template-assembly/raw/develop/src/shared/assets/videos/earth.mp4" ,
72
+ " colorsList" : [" #FFFFFF" ," #000000" ]
56
73
},
57
- " sections" : [
58
- {
59
- " name" : " readme_video" ,
60
- " type" : " video" ,
61
- " visibility" : [" video_segment" ],
62
- " options" : {
63
- " backgroundColor" : " {{ color1 }}@0.1" ,
64
- " videoUrl" : " {{ videoDemo }}" ,
65
- " duration" : 0.5 ,
66
- " music_volume_level" : 0.4
74
+ " orientation" : " landscape" ,
75
+ " musicEnabled" : true ,
76
+ " transitionDuration" : 0.5
77
+ },
78
+ " sections" : [
79
+ {
80
+ " name" : " readme_video" ,
81
+ " type" : " project_video" ,
82
+ " visibility" : [" video_segment" ],
83
+ " options" : {
84
+ " backgroundColor" : " {{ color1 }}@0.1" ,
85
+ " videoUrl" : " {{ videoDemo }}" ,
86
+ " duration" : 0.5 ,
87
+ " musicVolumeLevel" : 0.4
88
+ },
89
+ " filters" : [
90
+ {
91
+ " type" : " drawbox" ,
92
+ " values" : {
93
+ " x" : 0 ,
94
+ " y" : 0 ,
95
+ " w" : 1280 ,
96
+ " h" : 360 ,
97
+ " c" : " {{ color2 }}@1" ,
98
+ " t" : " fill"
99
+ }
67
100
},
68
- " filters" : [
69
- {
70
- " type" : " drawbox" ,
71
- " values" : {
72
- " x" : 0 ,
73
- " y" : 0 ,
74
- " w" : 1280 ,
75
- " h" : 360 ,
76
- " c" : " {{ color2 }}@1" ,
77
- " t" : " fill"
78
- }
79
- },
80
- {
81
- " type" : " drawtext" ,
82
- " values" : {
83
- " text" : {
84
- " en" : " {{ form_1_firstname }} {{ form_1_lastname }}"
85
- },
86
- " fontcolor" : " #FFFFFF" ,
87
- " fontsize" : 40 ,
88
- " x" : " (w-text_w)/2" ,
89
- " y" : " (h-text_h)/1.4" ,
90
- " fontfile" : " Quicksand.ttf" ,
91
- " alpha" : " 'if(lt(t,0.5),0,if(lt(t,1.5),(t-0.5)/1,if(lt(t,5),1,if(lt(t,7),(1-(t-6))/1,0))))'"
92
- }
93
- },
94
- ]
95
- }
96
- ]
97
- };
98
-
99
- // Project Configuration
100
- const projectConfig: ProjectConfig = {
101
- assetsDir: ' ./src/shared/assets' ,
102
- currentLocale: ' en' ,
103
- fields: {
104
- form_1_firstname: ' Firsname' ,
105
- form_1_lastname: ' Lastname' ,
106
- form_1_job: ' Tech Lead' ,
107
- form_2_keyword1: ' One' ,
108
- form_2_keyword2: ' Two' ,
109
- form_2_keyword3: ' Three' ,
110
- },
111
- };
101
+ {
102
+ " type" : " drawtext" ,
103
+ " values" : {
104
+ " text" : {
105
+ " en" : " {{ form_1_firstname }} {{ form_1_lastname }}"
106
+ },
107
+ " fontcolor" : " #FFFFFF" ,
108
+ " fontsize" : 40 ,
109
+ " x" : " (w-text_w)/2" ,
110
+ " y" : " (h-text_h)/1.4" ,
111
+ " fontfile" : " Quicksand.ttf" ,
112
+ " alpha" : " 'if(lt(t,0.5),0,if(lt(t,1.5),(t-0.5)/1,if(lt(t,5),1,if(lt(t,7),(1-(t-6))/1,0))))'"
113
+ }
114
+ },
115
+ ]
116
+ }
117
+ ]
118
+ };
119
+
120
+
121
+ await compile (projectConfig, templateDescriptor);
122
+ ```
112
123
113
- await compile (projectConfig, templateDescriptor);
114
- }
124
+ Or you might provide a path to the template descriptor JSON file:
115
125
116
- buildVideo ();
126
+ ``` javascript
127
+ const templatePath = ' ./src/shared/templates/sample.json' ;
128
+
129
+ await compile (projectConfig, templatePath);
117
130
```
118
131
119
132
## Running Tests
@@ -124,6 +137,10 @@ To run tests, use the following command:
124
137
pnpm test
125
138
```
126
139
140
+ ## Architecture
141
+
142
+ [ ![ Architecture] ( graph.svg )] ( graph.svg )
143
+
127
144
## Contributing
128
145
129
146
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Ensure to update tests as appropriate.
0 commit comments