Skip to content

Commit c9b1d56

Browse files
authored
[Director] Allow custom path on compilation
1 parent c6bbec1 commit c9b1d56

File tree

12 files changed

+6125
-4931
lines changed

12 files changed

+6125
-4931
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[*.{js,ts}]
1+
[*.{js,ts,json,md}]
22
indent_style = space
33
indent_size = 2
44
trim_trailing_whitespace = true

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ module.exports = {
1111
rules: {
1212
'@typescript-eslint/dot-notation': 'error',
1313
'eol-last': 'error',
14+
'prettier/prettier': 'error',
1415
},
1516
};

.github/workflows/.ci.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Continuous Integration
22

3-
on: [push, pull_request]
3+
on: [push, pull_request, workflow_dispatch]
44

55
jobs:
66
build-and-test:
@@ -13,15 +13,15 @@ jobs:
1313

1414
- uses: pnpm/action-setup@v2
1515
with:
16-
version: 8
16+
version: 9
1717

1818
- uses: actions/setup-node@v3
1919
with:
2020
node-version: 18
2121
cache: 'pnpm'
2222

2323
- name: Install Dependencies
24-
run: pnpm install
24+
run: pnpm i
2525

2626
- name: Lint
2727
run: pnpm lint
@@ -31,3 +31,30 @@ jobs:
3131

3232
- name: Run Tests and Collect Coverage
3333
run: pnpm test:ci
34+
35+
# publish:
36+
# needs: build-and-test
37+
# runs-on: ubuntu-latest
38+
# steps:
39+
# - name: Checkout Repository
40+
# uses: actions/checkout@v3
41+
42+
# - uses: pnpm/action-setup@v2
43+
# with:
44+
# version: 9
45+
46+
# - uses: actions/setup-node@v3
47+
# with:
48+
# node-version: 18
49+
# registry-url: 'https://registry.npmjs.org'
50+
51+
# - name: Install Dependencies
52+
# run: pnpm i
53+
54+
# - name: Build
55+
# run: pnpm build
56+
57+
# - name: Publish
58+
# run: npm publish
59+
# env:
60+
# NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.husky/pre-commit

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx lint-staged
5-
pnpm lint
6-
pnpm format
4+
pnpm lint-staged

.lintstagedrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"*.{ts,json,md,yml}": ["prettier --write"],
3+
"*.{ts}": [
4+
"pnpm lint",
5+
"pnpm test"
6+
]
7+
}

README.md

Lines changed: 89 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Clone the repository and install the dependencies:
2121
```bash
2222
git clone https://github.com/heristop/ffmpeg-template-assembly.git
2323
cd ffmpeg-template-assembly
24-
pnpm install
24+
pnpm i
2525
```
2626

2727
### Configuration
@@ -30,90 +30,103 @@ Create a JSON file (e.g., `sample.json`) in the `src/shared/templates` directory
3030

3131
### Usage
3232

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:
3436

3537
```bash
36-
pnpm compile your-template.json
38+
pnpm compile src/shared/templates/sample.json
3739
```
3840

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
4044

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:
4246

4347
```javascript
4448
import { compile } from 'ffmpeg-template-assembly';
4549

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"]
5673
},
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+
}
67100
},
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+
```
112123

113-
await compile(projectConfig, templateDescriptor);
114-
}
124+
Or you might provide a path to the template descriptor JSON file:
115125

116-
buildVideo();
126+
```javascript
127+
const templatePath = './src/shared/templates/sample.json';
128+
129+
await compile(projectConfig, templatePath);
117130
```
118131

119132
## Running Tests
@@ -124,6 +137,10 @@ To run tests, use the following command:
124137
pnpm test
125138
```
126139

140+
## Architecture
141+
142+
[![Architecture](graph.svg)](graph.svg)
143+
127144
## Contributing
128145

129146
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

Comments
 (0)