Priyanshu Tiwari
Priyanshu Tiwari

Reputation: 11

Ffmpeg Error: Error opening output file .output_withsrt.mp4

I'm building a video caption writer web app, for embedding subtitle in a video I'm using ffmpeg.

But there is a error opening output file, everything is working fine in a cmd, but in VS Code it's not working.

My code:

import ffmpeg from "fluent-ffmpeg";
import { NextRequest } from "next/server";

ffmpeg.setFfmpegPath('C:\\ffmpeg\\bin\\ffmpeg.exe')

export async function POST(req: NextRequest) {
  try {
    const videoWithSubtitlesPath = path.join(
      process.cwd(),
      "public",
      "subtitle_video.mp4"
    );

    console.log(videoWithSubtitlesPath)
    console.log("yaha tak");

    await embedSubtitle(
      "http://res.cloudinary.com/dptgkunzk/video/upload/v1717785028/w8ezkazwhsqbyx7f34rw.mp4",
      "@/public/srtfile/output.srt",
      "./public/srtfile/giveme.mp4"
    );

    console.log("calling")
  } catch (error) {
    console.log("Something went wrong while adding subtitle");
  }

  return Response.json({ message: "done" });
}

async function embedSubtitle(videopath: string, srtFilePath: string, outputPath: string): Promise<any>{
  if(!videopath || !srtFilePath || !outputPath) return false

  try {
    await new Promise<void>((resolve, reject) => {
      ffmpeg()
      .input(videopath)
      .videoFilters(`subtitles = ${srtFilePath} : force_style='Fontsize=24'`)
      .output("./output_withsrt.mp4")

      .on("end", () => {
        console.log("Subtitle added successfully");
        resolve()
      })

      .on("error", (err, stderr) => {
        console.error("Error during conversion and subtitle adding", err)
        console.error("stderr", stderr)
        reject(err);
      })
      .run()
    })
    return true
  } catch (error) {
    console.log("error while embedding subtile in a vidoe")
    }
}

Error:

ffmpeg exited with code 4294967294: Error opening output file ./output_withsrt.mp4.
Error opening output files: No such file or directory

Kindly help

Upvotes: 1

Views: 757

Answers (0)

Related Questions