Last active
April 23, 2022 05:09
-
-
Save kad1r/7921263 to your computer and use it in GitHub Desktop.
Converting video with FFMPEG with ASP.Net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Author
@zohaibrehman
I'm so sorry I saw your comment just now. I removed applicationpath from code and put comment there.
iam using file upload service can i use thius to compress or resize video
Author
iam using file upload service can i use thius to compress or resize video
Yea sure. No problem.
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.");
}
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
man whats "ApplicationPath" i am getting error on this???