ffmpegwasm / ffmpegwasm/ffmpeg.wasm

Issue with Subtitles Not Embedding in Exported Video Using FFmpeg

Open
#853 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
17.8k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I've been encountering an issue while attempting to embed subtitles into a video using FFmpeg. Despite following the process outlined below, the exported video does not include the subtitles:

```
export async function embedSubtitles(ffmpeg: FFmpeg, videoFile: File, srtContent: string) {
await ffmpeg.writeFile('input.mp4', await fetchFile(videoFile));
await ffmpeg.writeFile('./subtitles.srt', srtContent);

const ffmpeg_cmd = [
'-i',
'input.mp4',
'-vf',
'subtitles=./subtitles.srt:force_style=\'FontSize=24,FontName=Arial\'',
'-c:a',
'copy',
'output.mp4'
];

await ffmpeg.exec(ffmpeg_cmd);

const data = await ffmpeg.readFile('output.mp4') as Uint8Array;
const blob = new Blob([data], { type: 'video/mp4' });
const url = URL.createObjectURL(blob);

const a = document.createElement('a');
a.href = url;
a.download = 'output.mp4';
a.click();

return { url, output: 'output.mp4' };
}

```
I've reviewed this code extensively and cannot determine why the subtitles are not being embedded. I've ensured that srtContent is correctly formatted and that FFmpeg executes without errors. Could someone please review this approach and suggest any necessary changes or alternative methods to properly embed subtitles into the exported video? I've been stuck on this for the past two days and any help would be greatly appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.