Program to change video resolution using node.js / CURSOR AI Coding Review


 I kept putting off the cursor...

I was using Shana Encoder, but I was too lazy to touch the UI,

There was a condition that anything larger than 720p should be converted to 720p, and anything smaller than 720p should be converted to 480p, so I thought it was possible with a program,

so I asked them to do it using CURSOR.

And I succeeded. It works well (shock)


If I were to find this myself and go through trial and error, it would take hours or days, but it was done in 10 minutes.


It's amazing that I didn't have to learn anything.


MODULE INSTALL

npm i fluent-ffmpeg


index.js CODE

const ffmpeg = require('fluent-ffmpeg');

const path = require('path');


// input params

const inputFile = process.argv[2] || 'input.mp4';

const outputFile = path.join('output', `resized_${path.basename(inputFile)}`);

const targetWidth = process.argv[3] || 1280; // 기본 해상도 1280x720

const targetHeight = process.argv[4] || 720;


// create output dir

const fs = require('fs');

if (!fs.existsSync('output')) {

    fs.mkdirSync('output');

}


console.log('converter start');

console.log(`input: ${inputFile}`);

console.log(`target resolution:: ${targetWidth}x${targetHeight}`);


ffmpeg(inputFile)

    .size(`${targetWidth}x${targetHeight}`)

    .on('progress', (progress) => {

        // progress

        const percent = Math.round(progress.percent);

        process.stdout.write(`\r prgress: ${percent}% | done: {progress.frames} | time: ${progress.timemark}`);

    })

    .on('end', () => {

        console.log('\n complete!');

        console.log(`output file: ${outputFile}`);

    })

    .on('error', (err) => {

        console.error('\n error', err);

    })

    .save(outputFile); 


execute command:

node index.js source_file width height

ex) node index.js source.mp4 1280 720


ffmpeg  install

goto here: https://www.gyan.dev/ffmpeg/builds/

windows: find file: ffmpeg-release-full.7z 


You need to add the bin folder to the environment variable.

youtube: 


After registering the environment variable PATH


You can use the [ ffmpeg ] command from any folder.




Cursor AI Coding Review

When I requested a program for a field I knew nothing about,

It was much easier to proceed than searching for and understanding sample code.

It saved me a lot of time.




Comments

Popular posts from this blog

Let's deploy express with vercel / Let's create a page that supports unity webgl compression