Click here to Skip to main content
14,265,748 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to upload video files in an ASP.NET website using C#.

I have downloaded ffmpeg library files from www.afterdawn.com/software/audio_video/convert_video/ffmpeg.cfm"
and pasted it in a folder ffmpeg.

my ffmpeg has a subfolder also named ffmpeg contaiing files ffmpeg.exe, ffplay.exe and ffprobe.exe. (the files that are in bin folder of downloaded ffmpeg files. Thus, ffmpeg.exe file is at location /ffmpeg/ffmpeg/ffmpeg.exe.

In aspx file I have a fileupload, a button to upload. The code is.aspx file is:

<div style="removed:relative; removed50px; width:700px;">
    
        <br />
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" />
    
    </div>


The code in my code behind file is
using System;
using System.IO;
using System.Diagnostics;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string inputfilename = FileUpload1.FileName;
        string inputfile = "C://"+inputfilename;
        
        string outputfile = "/Videos/" + FileUpload1.FileName;
        string fileargs = "-i" + inputfile + "-ar 22050" + outputfile;
        Process proc;
        proc = new Process();
        proc.StartInfo.FileName = Server.MapPath("~" + outputfile) + "\\ffmpeg\\ffmpeg\\ffmpeg.exe";
        proc.StartInfo.Arguments = fileargs;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.CreateNoWindow = false;
        proc.StartInfo.RedirectStandardInput = false;
        
        try
        {
            proc.Start();
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
                    }

        
    }
}


When i run this application and try to upload a video, I get the exception error message "The system cannot find the file specified."

I need help to find whether i am misisng any using directive or assembly reference or what mistake i am making in use of ffmpeg code.

Many thanks for help.
Posted
Comments
Wes Aday 24-Aug-14 10:40am
   
You debug your code and find out which file cannot be found. And since it's web code, your user account might not have permission to access files and directories. The root directory of your C drive for example.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This approach can work, but you are not doing all appropriate steps. First of all, you need to formulate the question accurately. FFMpeg has nothing to deal with "uploading" (however, it can be very helpful for downloading files delivered through some streaming protocol, a tool which is hard to find). You merely trying to transcode some media which is already uploaded.

Secondly, you need to learn better how FFMpeg is used off-line. It typically uses a lot more parameters. One concern is: you don't specify output codec and codec parameters. In this case, FFMpeg uses the "filename extension" of the output file to create some default parameters. Do you take care about this file name? If you did, did you make sure that those defaults are good for your purpose? And did you make sure that the input file format is adequate for your purpose?

Now, here is what happened: some of the files involved is not found. You just need to sort out this simple issue and make sure all files are in place. From your MapPath, it is apparent that you put "ffmpeg.exe" in the "Video" sun-directory as ".ffmpeg\ffmpeg\ffmpeg.exe" and that "Video" sub-directory is the immediate sub-directory of the root directory configured for your site. Is it really so? Why not putting "ffmpeg.exe" in a separate read-only directory? Just make sure you understand the paths correctly and put all in place.

—SA
   
Comments
Member 10235977 24-Aug-14 15:55pm
   
Thanks for making me understand that i had gone wrong on the fundamentals of ffmpeg. I wil try to work again on right track and hopefuly get through the problem. Thanks again for correcting me.
Sergey Alexandrovich Kryukov 24-Aug-14 20:36pm
   
You are very welcome. You can use the editor and check up the presence of the files before they are used.
Good luck, call again.
—SA
Member 10235977 25-Aug-14 16:05pm
   
Thanks Sir. I have been able to get video files converted by using ffmpeg as per your advice. The files are saved in the output directory prescribed. For playing these files on the webpage, I am use the normal code for displaying video files. The role of ffmpeg for me is limited to converting the format of video files. I wanted to be sure that I am on right track and not making any mistake on fundamentals or there is a better method which can give the comfort like display of videos on Youtube. A line of confirmation from you that i am doing it right, will add to my confidence and I shall be highly obliged. Thanks.
Sergey Alexandrovich Kryukov 25-Aug-14 16:30pm
   
It all sounds reasonable.
You are very welcome.
Good luck, call again.
—SA
Niraj Sanghani 8-May-17 6:46am
   
Hello!

Please help me ASAP

Here is My Code

private void processVideo() {

//string inputfilename = FileUpload1.FileName;
string inputfile = "/Videos/" + "input.avi";

string outputfile = "/Videos/" + "output.avi";
string fileargs = "-i " + inputfile + " -vf scale=320:240 " + outputfile;
Process proc;
proc = new Process();
proc.StartInfo.FileName = Server.MapPath("~" + outputfile) + "\\mpeg\\FFmpeg.exe";
proc.StartInfo.Arguments = fileargs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardInput = false;

try
{
proc.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

givving me error That Not Found

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100