0

I'm working on a project, essentially a social media app for the traveler community. In this application, users can upload videos in any format, but I need to save them in MP4 format so that any browser can play them.

I've downloaded various formats of videos from a website https://www.quickpickdeal.com/tag/download-sample-videos and installed FFmpeg to convert videos to MP4 format. For the backend, I'm using ASP.NET Core. Currently, I'm using the following code to convert MKV videos to MP4.

 //path where you want to save your converted video
            string cmd = " -i " + input + " -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -f mp4 -crf 22 -s 640x360 " + output;
            var processInfo = new ProcessStartInfo(ffmpegFilePath, cmd)
            {
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };

but I'm unsure how to write generic logic for the command so it can convert videos of any format to MP4 and only take the first minute of the video.

Could someone suggest how I can achieve these tasks?

1
  • You just ffprobe (ffmpeg.org/ffprobe.html) the uploaded file and see if its a format you will support conversion for. If yes, convert, if no say bad format or something.
    – Silbee
    Commented May 3 at 7:56

1 Answer 1

0

Add "-to 00:01:00" to the commmand. Something like :

string cmd = " -i " + input + "-to 00:01:00 -acodec aac ......

You can select the starting point by adding -ss :

string cmd = "-ss 00:03:00 -i " + input + "-to 00:01:00 -acodec aac ......

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .