Skip to content

Issue with Subtitles Not Embedding in Exported Video Using FFmpeg #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iyashjayesh opened this issue Mar 22, 2025 · 0 comments
Open

Comments

@iyashjayesh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant