Skip to content

Instantly share code, notes, and snippets.

@kad1r
Last active April 23, 2022 05:09
Show Gist options
  • Select an option

  • Save kad1r/7921263 to your computer and use it in GitHub Desktop.

Select an option

Save kad1r/7921263 to your computer and use it in GitHub Desktop.
Converting video with FFMPEG with ASP.Net
public static string ConvertVideo(string file, string convertedExtension)
{
string result = string.Empty;
string input = string.Empty;
string output = string.Empty;
try
{
string ffmpegFilePath = "~/video/ffmpeg/ffmpeg.exe"; // path of ffmpeg.exe - please replace it for your options.
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(file));
string filename = Path.GetFileNameWithoutExtension(fi.Name);
string extension = Path.GetExtension(fi.Name);
input = HttpContext.Current.Server.MapPath(file);
output = HttpContext.Current.Server.MapPath("/video/" + filename + convertedExtension);
var processInfo = new ProcessStartInfo(HttpContext.Current.Server.MapPath(ffmpegFilePath), " -i \"" + input + "\" -ar 22050 \"" + output + "\"")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
try
{
Process process = System.Diagnostics.Process.Start(processInfo);
result = process.StandardError.ReadToEnd();
process.WaitForExit();
process.Close();
}
catch (Exception)
{
result = string.Empty;
}
}
catch (Exception ex)
{
string error = ex.Message;
}
return result;
}
@zohaibrehman
Copy link
Copy Markdown

man whats "ApplicationPath" i am getting error on this???

@kad1r
Copy link
Copy Markdown
Author

kad1r commented Jun 14, 2016

@zohaibrehman
I'm so sorry I saw your comment just now. I removed applicationpath from code and put comment there.

@Ameen642
Copy link
Copy Markdown

iam using file upload service can i use thius to compress or resize video

@kad1r
Copy link
Copy Markdown
Author

kad1r commented Apr 22, 2022

iam using file upload service can i use thius to compress or resize video

Yea sure. No problem.

@Ameen642
Copy link
Copy Markdown

public IEnumerable UploadImgFile()
{
List success = new List();
try
{

        success.Add("false");
           if (HttpContext.Current.Request.Files.AllKeys.Any())
           {
             // Get the uploaded image from the Files collection
           var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];

                if (httpPostedFile != null)
            {
                   // Validate the uploaded image(optional)

                 // Get the complete file path
                string Exten = Path.GetExtension(httpPostedFile.FileName);
                  string name = "SVFILE_" + DateTime.Now.ToString("ddMMyyyyHHmmss");
                  string finalfilename = name + Exten;

                    var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/tempfold/facilityimage"), finalfilename);

                   // Save the uploaded file to "UploadedFiles" folder
                    httpPostedFile.SaveAs(fileSavePath);
                    success.Clear();
                    success.Add(finalfilename);
                }
               else
                {
                    success.Clear();
                    success.Add("Could not get the uploaded file.");
                }
            }
            else
            {
              success.Clear();
                success.Add("No file found to upload.");
            }

@Ameen642
Copy link
Copy Markdown

above code in that how can i use video conversion iam not able to get compress file while refering your code please guide me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment