Right now I’m working on web application and my requirement is that I have to show a video gallery on my website so that I have converted all video format files into Mp4 using FFMPEG. As we know that mp4 video format is supported by all the browsers.
I have a section on Web Application from where user can upload any types of videos of any format. After successfully upload we have displayed the same video to the user. For that, I am using a jquery plug-in for playing this video which uses a html5 video tag for playing this video.
But after the converting video to mp4 using FFmpeg, it does not play in firefox and chrome browser.
I tried a lot of encoding options, server configurations, FFMPEG versions, other video encoders library but I’m not able to solve this error.
I google and search many websites for the solution and then finally get right for FFMPEG EXE.
HTML5 uses MPEG 4 files with H264 video codec (and AAC audio codec) in Internet Explorer, chrome. So that your converted video should use this codec. So That your command should be.
For mp4 (H.264 / ACC):
" -i " + input + " -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -f mp4 -crf 22 -s 640x360 " + output
Sample C# Code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ConvertVideoMp4("MyFiles/TestMkv.mkv", ".mp4");
}
public static string ConvertVideoMp4(string file, string convertedExtension)
{
string result = string.Empty;
string input = string.Empty;
string output = string.Empty;
try
{
// path of ffmpeg.exe -replace it for your.
string ffmpegFilePath = HttpContext.Current.Server.MapPath("Video/ffmpeg.exe");
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(file));
string filename = Path.GetFileNameWithoutExtension(fi.Name) + "output";
//output video name
string extension = Path.GetExtension(fi.Name);
input = HttpContext.Current.Server.MapPath(file);
output = HttpContext.Current.Server.MapPath("Video/" + filename + convertedExtension);
//path where you want to save your converted video
string cmd = " -i " + input + " -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -f mp4 -crf 22 -s 640x360 " + output;
var processInfo = new ProcessStartInfo(ffmpegFilePath, cmd)
{
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;
}
}
The post [Solved]-FFMPEG Converted Mp4 Video Not Working In HTML5-C# appeared first on Software Development | Programming Tutorials.
Read More Articles
- Write a value which contain comma to a CSV file in c#?
- Reading CSV File with cells containing commas c#
- Split CSV with columns may contain ‘,’ Comma C#
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- [Simple Way]-ASP.NET Core Upload Multiple File Web API model
- [Simple Way]- Image Upload in .NET Core Web API
- [Easy Way]-Receive File and other form data together in ASP.NET Core Web API
- Replace image in word document using C#
- How to add new rows to an existing word document table in C#
- Parsing libvlcsharp video loaded from stream not working
- Android Unity3D VideoPlayer Playing video "from URL" not working properly
- string split into array not working
- Checking if valid date in C# not working properly
- SQL Query not working -- operator missing
- 'SearchIndex="All"' not working in Amazon Product API
- passing a object[] to a params object[] not working
- CancellationTokenSource not working as expected on a TaskCompletionSource
- GestureRecognizer not working on CollectionView with DataTemplate
- RabbitMQ connection working on localhost but not trough network
- Breakpoints can't be set on certain lines in the method. Quickwatch not working for some variables
- ASP.NET Core get user not working when deployed to IIS and launch in browser
- Unity Highscore using PlayerPrefs not working
- DateTime.TryParseExact() not recognizing the PM designator, AM working as expected
- Validate Anti forgery key not working with ajax post
- Star sizing not working in WPF Grid
- Converting unicode not working in c#
- ListBox.Items.Contains is not working
- How to work with Expression Trees not working using WCF since they are not serializable?
- C# Casting Not Working
- WPF ScrollViewer is not working
- File.Exists not working on network drive
- Random is not working good
- Equal to or less than not working
- 3D Graphics - Matrix math is not working
- Google cloud storage upload not working with C# API
- Extension Method Not Working on Inhierited Type
- MVC 5 Not working in IIS 7
- Change DB from local to azure not working
- sql update is not working
- Multiple extension in opne file dialog?
- ASP MVC Controller post same html input name with different values
- strange behavior with response from code behind css rounded corner dissapears in IE9
- ASP.NET GridView update Source but not commands
- X,Y coordinates for WriteableBitmap and GestureListener_Tap do not match - Windows Phone 8
- Constructor parameters and value object implementation choices
- Implementing Audit trails in asp.net Web Forms based on the observer pattern
- Refresh start menu icons in Windows 8
- How to associate user account to a domain user
- Why is my MVC Action not model binding my collection?
- Twilio call usage paging
- Is there any way to run Nunit test using test adapter in command prompt?
- Possible way to make the page session expired in ASP MVC 3? ("Press Back Button after Logout issue"
- How to measure characteristics of file (hard-disk) I/O?
- get text of linklabel created at runtime
- Calendar Extender date picking and converting into correct format
- C# DataGridTextColumn line break
- c# Mongodb 2.0 driver get UpdateManyAsync result
- Ugly class interface definition
- Does userControl1.Dispose() take care of all its disposable objects?