Skip to content
    Back to all Bounties

    Earn 900 ($9.00)

    Time Remainingdue 10 months ago
    Canceled

    next js api route read file - dynamically or stored as stream

    LucasW4
    LucasW4
    Posted 10 months ago

    Bounty Description

    Problem Description

    • i have a next js api route
    • you upload a video file
    • api route uses videoshow (wrapper of fluent-ffmpeg) to turn an image into a 5 video of the static image
    • api route then uses fluent-ffmpeg (javascript adapted ffmpeg) to concatenates video uploaded + static video image
    • returns the concatenated video
    • problems:
    1. you can't access dynamically created files except with fs (Only assets that are in the public directory at build time will be served by Next.js. Files added at request time won't be available https://nextjs.org/docs/pages/building-your-application/optimizing/static-assets). in order to use fluent-ffmpeg to concat the video, you input the path of a txt file formatted like this:

    so

    const concatFileContent = `
    file '${vid1}'
    file '${vid2}'
    `;
     
    fs.writeFileSync(txtName, concatFileContent);
     
    return new Promise(async (resolve, reject) => {
    ffmpeg()
    .input(txtName)
    // ...more code
    .save(vidName)
    // ...more code
    • but that txt file is dynamically created (vid names are uuid's)
    • also the outputted video would be dynamically created at a path and you would have to be read also
    1. i'm not sure if fluent-ffmpeg can accept input as streams or non-files, i can't figure out how to

    Acceptance Criteria

    api route does what the process above says and works

    from what i see these are the 2 ways (corresponding to 1. and 2. above in description):

    1. read files that are dynamically created on the api route (server side node js)
    2. feed/output as non-files

    Technical Details

    next js, ffmpegg, videoshow

    Link to Project

    full code will be given on assignment

    p.s. i'm sure that it's the fact next js can't read dynamically created files because i tried it running node and it worked but when i have it on a next js api route it doesn't (and i also linked the docs above that say it).