Skip to content

Commit 4669b24

Browse files
committed
feature: add webm support
1 parent 421f953 commit 4669b24

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

app/api/hooks/routes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ async def receive_hook(
3535
new_file = Path(f"{upload_id}/{sanitized_filename}")
3636

3737
if (settings.tusd_dir / new_file).exists():
38-
logger.warning("File already exists, deleting!: %s", new_file)
39-
new_file.unlink()
38+
logger.warning("File already exists, deleting!: %s", (settings.tusd_dir / new_file))
39+
(settings.tusd_dir / new_file).unlink()
4040

4141
return HookResponse(ChangeFileInfo=FileInfoChanges(ID=upload_id, Storage={"Path": str(new_file)}))
4242

4343
if hook_request.type == "post-finish":
4444
ingest = Ingester(archive_base_path=settings.archive_dir, django_api=django_api)
4545
upload_meta = get_upload_metadata(hook_request)
46-
upload_file = Path(hook_request.event.upload.storage["Path"])
46+
upload_file = Path(hook_request.event.upload.storage["Path"]).relative_to(Path("/"))
4747

4848
try:
4949
metadata = await metadata_extractor.assert_compliance(upload_file)

app/django_client/service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FormatEnum(str, Enum):
2626
SRT = "srt"
2727
THEORA = "theora"
2828
VC1 = "vc1"
29+
WEBM_MED = "webm_med"
2930

3031
def __str__(self) -> str:
3132
return str(self.value)
@@ -41,6 +42,7 @@ class IntFormatEnum(int, Enum):
4142
THEORA = 7
4243
SRT = 8
4344
CLOUDFLARE_ID = 9
45+
WEBM_MED = 10
4446

4547

4648
class DjangoApiService:

app/ingest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from .media.ffprobe_schema import FfprobeOutput
1111
from .task_builder import TKB
1212

13-
DESIRED_FORMATS = (FormatEnum("large_thumb"),)
13+
DESIRED_FORMATS = (
14+
FormatEnum.LARGE_THUMB,
15+
FormatEnum.WEBM_MED,
16+
)
1417

1518

1619
class Ingester:
@@ -85,6 +88,8 @@ async def _process_format(
8588
)
8689

8790
command = template.render(template_args)
91+
self.logger.debug("Generated command: %s", command)
92+
8893
await TKB(command).execute()
8994

9095
self.logger.info("Creating video file entry for %s", output_file)

app/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Task:
1616
def __init__(self, proc: Coroutine[Any, Any, Process]):
1717
self.proc = proc
1818

19-
async def execute(self) -> str:
19+
async def execute(self) -> tuple[str, str]:
2020
proc = await self.proc
2121
stdout, stderr = await proc.communicate()
2222

app/task_builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import shlex
32

43
from app.runner import Task
54

@@ -16,8 +15,8 @@ def TKB(command: str) -> Task:
1615
1716
"""
1817
return Task(
19-
asyncio.create_subprocess_exec(
20-
*shlex.split(command),
18+
asyncio.create_subprocess_shell(
19+
command,
2120
stdout=asyncio.subprocess.PIPE,
2221
stderr=asyncio.subprocess.PIPE,
2322
)

templates/webm_med.j2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
output_file_extension: webm
3+
---
4+
ffmpeg -i "{{ input_file }}"
5+
-passlogfile "{{ output_file }}"
6+
-c:v libvpx-vp9 -crf 30 -b:v 10M
7+
-pass 1 -an -f null /dev/null &&
8+
ffmpeg -i "{{ input_file }}"
9+
-passlogfile "{{ output_file }}"
10+
-c:v libvpx-vp9 -crf 30 -b:v 10M
11+
-pass 2 -cpu-used 3 -row-mt 1 -tile-rows 2 -threads 8
12+
-c:a libopus
13+
-vf "pad=ceil(max(iw\,ih*16/9)/2)*2:ceil(max(ih\,iw*9/16)/2)*2:(ow-iw)/2:(oh-ih)/2,setsar=1"
14+
"{{ output_file }}"

0 commit comments

Comments
 (0)