Skip to content

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

Open
@iyashjayesh

Description

@iyashjayesh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions