0

I know questions like this are all over the internet but I believe my case is different, I have a ASP.NET Webpage (Razor C#) and I have a whole video sharing website ready BUT I still don't understand, How can I convert videos to mp4 and webm using ffmpeg on the upload page and instead of having the original saved and added to the database i want the converted version added. heres my upload page code:

    @{
WebSecurity.RequireAuthenticatedUser();
var db = Database.Open("PhotoGallery");
var fileName = "";
var uploader = WebSecurity.CurrentUserId;
var date = DateTime.Now.Date;
var extention = "";
if(IsPost){
 var numFiles = Request.Files.Count;
 if(numFiles <= 0){
     ModelState.AddError("fileUpload", "Please specify at least one photo to upload.");
 }
 else{
     var fileSavePath = "";
        var uploadedFile = Request.Files[0];
    fileName = Path.GetFileNameWithoutExtension(uploadedFile.FileName).Trim();
    extention = Path.GetExtension(uploadedFile.FileName).Trim();
    string ndom = Path.GetRandomFileName();
    var none = ndom.Remove(ndom.Length - 4);
    fileSavePath = Server.MapPath("~/Images/userpics/" +
      none + extention);
    uploadedFile.SaveAs(fileSavePath);
    var insertCommand = "INSERT INTO Videos (FileTitle, UploadDate, UserId, ext, Name) Values(@0, @1, @2, @3, @4)";
     db.Execute(insertCommand, fileName, date, uploader, extention, none + extention);
     Response.Redirect(Href("~/Photo/View", db.GetLastInsertId()));
     }
    }
    }
<h1>Upload Video</h1>

<form method="post" enctype="multipart/form-data">
@Html.ValidationSummary("Unable to upload:")
<fieldset class="no-legend">
    <legend>Upload Photo</legend>
    @FileUpload.GetHtml(addText: "Add more files", uploadText: "Upload", includeFormTag: false)
    <p class="form-actions">
        <input type="submit" value="Upload" title="Upload photo" />
    </p>
</fieldset>
</form>

<p class="message info">
The maximum file size is 50MB.
</p>
DividedByZero
  • 4,333
  • 2
  • 19
  • 33

1 Answers1

0

I think your best bet will be to take the upload as-is, and have an offline application or service poll your table for new records and convert them then. When finished, it would update the table with the new file name and a flag indicating it was converted. I had a similar project and this is what I did.

It's probably not a good idea to try converting these on the fly. If you a fair amount of simultaneous uploads/conversions, you could end up cratering your server.

InbetweenWeekends
  • 1,405
  • 3
  • 23
  • 28
  • do you know any applications I could use? – DividedByZero Apr 18 '14 at 18:25
  • If you go with a non-web executible, you can either loop through your 'queued' videos and shell out the command line to convert, or use one of the several wrappers that are available. http://stackoverflow.com/questions/2163036/solid-ffmpeg-wrapper-for-c-net I've been trying to locate where I got mine. unfortunately, I'm not able to publicly post it. – InbetweenWeekends Apr 18 '14 at 19:09