75lb / handbrake-js

Video encoding / transcoding / converting for node.js
Other
568 stars 69 forks source link

How to burn subtitle? #58

Closed brightchip closed 4 years ago

brightchip commented 4 years ago

How to hard-encode the subtitle to the video from format mkv => mp4 ?

export async function encodeVideo(videoToEncode) {

    if (!checkFileExists(videoToEncode.path)) {
        console.error('encodeVideo but file does not exist', videoToEncode.path);
        return
    }
    // const fileStream = fs.createReadStream(videoToUpload.path);
    return new Promise(resolve => {
        if (videoToEncode.path.match(/\.mkv$/)) {
            let encodedPath = videoToEncode.path.replace(/\.mkv$/, '.mp4')
            hbjs.spawn({ input: getAbsoluteFilePath(absDownloadPath, videoToEncode.path), output: getAbsoluteFilePath(absDownloadPath, encodedPath), 'subtitle-burned': "native" })
                .on('error', err => {
                    // invalid user input, no video found etc
                    resolve({ encodeError: err })
                })
                .on('progress', progress => {
                    console.log(
                        'Percent complete: %s, ETA: %s',
                        progress.percentComplete,
                        progress.eta
                    )
                })
                .on('complete', _ => {
                    // change path into encoded one
                    resolve({ encodedPath: encodedPath })
                        // invalid user input, no video found etc
                })
        }
    })
}

same issue : https://github.com/HandBrake/HandBrake/issues/2923

brightchip commented 4 years ago

I have figured out

       hbjs.spawn({
                    input: getAbsoluteFilePath(absDownloadPath, videoToEncode.path),
                    output: getAbsoluteFilePath(absDownloadPath, encodedPath),
                    subtitle: "1",
                    "subtitle-burned": 1,
                    preset: 'Fast 720p30',

                })
75lb commented 4 years ago

Hi, did you resolve this issue?