Skip to content

Commit 64c3554

Browse files
author
Bash06
committed
sob
1 parent 5aeda4e commit 64c3554

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

backend/Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM debian:bookworm-slim as builder
22

3+
WORKDIR /build
4+
35
# Install required packages to compile
46
RUN apt-get update && \
57
apt-get install -y gcc g++ ca-certificates git make wget tar xz-utils && \
@@ -32,11 +34,6 @@ RUN apt-get update && \
3234
rm -rf /var/lib/apt/lists/* /usr/share/doc/* /usr/share/man/* /usr/share/info/*
3335

3436
# Copy the UPX-compressed Go binary from the builder
35-
COPY --from=builder /vidsh /app/
36-
37-
RUN useradd -m vidsh-runner
38-
USER vidsh-runner
39-
40-
EXPOSE 8888
37+
COPY --from=builder /build/vidsh /app/vidsh
4138

4239
ENTRYPOINT ["./vidsh"]

backend/app/ffmpeg/process.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func FFmpegProcess(c *gin.Context, d *internal.Deps) {
105105
done := make(chan error, 1)
106106
// Enqueue can only error if the queue is full
107107
err = d.JobQueue.Enqueue(&service.FFmpegJob{
108-
ID: util.RandStr(5),
108+
ID: jobID,
109109
UserID: userID,
110110
FilePath: tempFile.Name(),
111111
Output: c.Writer,
@@ -166,7 +166,7 @@ func FFmpegProcess(c *gin.Context, d *internal.Deps) {
166166
done := make(chan error, 1)
167167
// Enqueue can only error if the queue is full
168168
err = d.JobQueue.Enqueue(&service.FFmpegJob{
169-
ID: util.RandStr(5),
169+
ID: jobID,
170170
UserID: userID,
171171
FilePath: tempFile.Name(),
172172
Output: tempProcessed,

backend/app/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ func NewRouter() (*gin.Engine, error) {
126126
f.GET("/start", ffmpeg.FFMpegStart)
127127

128128
// GET /api/ffmpeg/progress -> Returns the progress of a job
129-
f.GET("/progress", func(c *gin.Context) { ffmpeg.FFmpegProcess(c, d) })
129+
f.POST("/process", func(c *gin.Context) { ffmpeg.FFmpegProcess(c, d) })
130130

131131
// POST /api/ffmpeg/process -> Processes a file provided in a multipart form
132-
f.POST("/process", turnstile, ffmpeg.FFMpegStart)
132+
f.GET("/progress", turnstile, ffmpeg.FFmpegProgress)
133133
}
134134

135135
d.Argon = security.New()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<script lang="ts">
2+
import { FFmpeg } from '@ffmpeg/ffmpeg'
3+
import { fetchFile } from '@ffmpeg/util'
4+
5+
const baseURL = "https://cdn.jsdelivr.net/npm/@ffmpeg/core@0.12.10/dist/esm"
6+
7+
let { file }: { file: File } = $props()
8+
9+
let ffmpeg: FFmpeg | null = null
10+
let appState: 'idle' | 'loading' | 'ready' = $state('idle')
11+
let isFFmpegLoaded = $state(false)
12+
13+
async function loadFFmpeg() {
14+
if (!ffmpeg) {
15+
appState = 'loading'
16+
ffmpeg = new FFmpeg()
17+
18+
await ffmpeg.load({
19+
coreURL: `${baseURL}/ffmpeg-core.js`,
20+
wasmURL: `${baseURL}/ffmpeg-core.wasm`,
21+
workerURL: `${baseURL}/ffmpeg-core.worker.js`
22+
})
23+
appState = 'ready'
24+
console.log("FFmpeg loaded")
25+
}
26+
}
27+
28+
async function processAudio() {
29+
if (!ffmpeg) return
30+
31+
const url = URL.createObjectURL(file)
32+
await ffmpeg.writeFile("input.mp4", await fetchFile(url))
33+
await ffmpeg.exec(["-i", "input.mp4", "-map", "0:a:0", "track.mp3"])
34+
const data = await ffmpeg.readFile('track.mp3')
35+
URL.revokeObjectURL(url)
36+
37+
const exp = URL.createObjectURL(new Blob([(data as any).buffer], {
38+
type: "audio/mp3"
39+
}))
40+
const a = document.createElement('a')
41+
a.href = exp
42+
a.download = "track.mp3"
43+
a.click()
44+
}
45+
</script>
46+
47+
{#if appState === 'idle'}
48+
<div>
49+
<p>This tab allows for advanced video editing, but requires you to load a pretty big bundle. Click on the button below to load it.</p>
50+
<button class="btn btn-outline-danger" onclick={loadFFmpeg}>Load ffmpeg.wasm (~31MB)</button>
51+
</div>
52+
{:else if appState === 'loading'}
53+
<div class="spinner-border" role="status">
54+
<span class="sr-only">Loading ffmpeg.wasm</span>
55+
</div>
56+
<p>Loading ffmpeg...</p>
57+
{:else if appState === 'ready'}
58+
<p>Loaded :)</p>
59+
{/if}
60+
61+
<!--
62+
<button on:click={processAudio} disabled={state === 'loading'}>
63+
{#if state === 'idle'} Extract Audio 🎵 {/if}
64+
{#if state === 'loading'} Loading FFmpeg... {/if}
65+
{#if state === 'ready'} Extract Again 🎵 {/if}
66+
</button> -->

0 commit comments

Comments
 (0)