fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.85k stars 874 forks source link

How to access an srt file in another directry , while applying video filters subtitles #1213

Open ahmersaud opened 1 year ago

ahmersaud commented 1 year ago

I am trying to access the subtitle (.srt) file from the temp directory , here is my code

     ffmpeg(inputFilePath)
            .videoFilters([`subtitles=${subtitleFilePath}`])
            .output(outputFilePath)
            .on("log", (log) => {
              console.log(log);
            })
            .on("error", (error) => {
              console.error(error); 
            })
            .on("end", async () => {
            })
            .run();

This code gives this error: ffmpeg exited with code 1: Error reinitializing filters!\nFailed to inject frame into filter network: Invalid argument\nError while processing the decoded data for stream #0:0\nConversion failed!

However when i placed the subtitle file in the same directory in which the code is running and changed this line: .videoFilters([subtitles=${subtitleFilePath}]) to this: .videoFilters([subtitles=${"./subtitle.srt"}])

Then the code ran successfully. P.S : I am using the temp directory (os.tmpdir()) to place all my input and output files feeded to ffmpeg. The paths are set correctly. I even tried to convert the subtitleFilePath from C:\\Users\\User1\\AppData\\Local\\Temp\\sample.srt to this file:///C:/Users/User1/AppData/Local/Temp/sample.srt but still the same error pops up.