Gurudev Kumar
Gurudev Kumar

Reputation: 199

how to convert video in multiple bitrate using asp.net

I want to play one video in different bitrates. Like i uploaded one video in 1080P resolution i want play that video in 720P, 480P, 360P, 240P, 144P etc. I want this solution in asp.net using C#.

Like youtube provide the facility to watch video in different resolutions.

Please help me regarding this.

I tried the following code but not working:

using Softpae.Media;
namespace ConsoleTest
{
class Program
{
    static void Main(string[] args)
    {
        Job2Convert myJob = new Job2Convert();
        MediaServer ms = new MediaServer();
        myJob.pszSrcFile = "E:\\EhabVideoLibrary\\videos\\sinbad.mkv";
        myJob.pszDstFile = "E:\\EhabVideoLibrary\\videos\\sinbad.mp4";

        myJob.pszDstFormat = "mp4";
        myJob.pszAudioCodec = "aac";

        myJob.nAudioChannels = 2;
        myJob.nAudioBitrate = -1;
        myJob.nAudioRate = -1;

        myJob.pszVideoCodec = "h264";

        myJob.nVideoBitrate = -1;
        myJob.nVideoFrameRate = -1;
        myJob.nVideoFrameWidth = -1;
        myJob.nVideoFrameHeight = -1;   

        bool ret = ms.ConvertFile(myJob);            
    }
}

}

Upvotes: 0

Views: 1721

Answers (1)

Thomas Devoogdt
Thomas Devoogdt

Reputation: 896

You can use FFplay of the FFmpeg project. (ffmpeg.org) With FFmpeg it's possible to encode and transcode almost every codec in the resolution you want. In this thread is the use of a command line application using C# described.

I've never tried it, but there are also libraries provided for .NET using FFmpeg like this:

  • ffmpegdotnet.codeplex.com
  • intuitive.sk/fflib

Success with it!

Here is an example code using ffmpeg (I tested it under Win7 VM):

using System;

    namespace ConsoleApplication_FFmpegDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                string inputVideo = @"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv";
                string outputVideo = @"C:\Users\Public\Videos\Sample Videos\Wildlife.mp4";

                string ffmpegArg = string.Format("-i \"{0}\" -vf scale=320:240 \"{1}\"", inputVideo, outputVideo);
                string ffmpegPath = @"C:\Portable\ffmpeg-win32-static\bin\ffmpeg.exe";
                FFmpegTask ffmpegTask = new FFmpegTask(ffmpegPath, ffmpegArg);
                ffmpegTask.Start();

                Console.ReadLine();
            }
        }
    }

And the FFmpegTask.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;

namespace ConsoleApplication_FFmpegDemo
{
    public class FFmpegTask
    {
        public Process process = new Process();

        public FFmpegTask(string ffmpegPath, string arguments)
        {
            process.StartInfo.FileName = ffmpegPath;
            process.StartInfo.Arguments = arguments;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow = false;
            process.StartInfo.UseShellExecute = false;
        }

        public bool Start()
        {
            return process.Start();
        }
    }
}

Upvotes: 3

Related Questions