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#
- Getting the length of video using ffmpeg/ffprobe is not working
- Unity Video player not working on my android
- Video File streaming not working on Safari/ iOS device in asp.NET Core 2.0
- I am trying to add rewarded video to my game but rewarded video events are not working
- Not able to play mp4 video on Chrome Browser
- StringFormat for DateTime is not working with MultiBinding
- await this.ShowMessageAsync is not working in WPF C#
- Open File Dialog not working
- Async Task.Run Not Working
- Paging not working in MVC Webgrid
- Calling Resources.Load on a texture is not working
- AddressOf not working
- Task continuation not working after await
- MVC 3 DropDownFor and ViewModel not working
- Findcontrol property not working in createUserWizard
- DllImport Not Working
- Converting enum to enum not working when are not in same order
- StreamReader.ReadToEnd Not working in C#?
- linq to sql submit changes not working
- Custom model binding on derived property not working
- simple XML reading in C# is not working
- cmd Arguments not working
- Deserializing XML File using XmlSerializer.Deserialize from MemoryStream not working
- Power shell script SelectSingleNode not working
- ASP.NET Chart not working on server
- Inner Join in LINQ to SQL Not Working
- System wide Windows CBT hook not working properly
- Regex not working in .NET
- Transactionscope not working when two remote sql connections
- Vector3.Lerp inside a Coroutine is not working as it should on Unity3D
- How do I access a class module in Excel VBA from C#?
- Postman http request success, C# HttpWebRequest error trust relationship for the SSL/TLS secure channel
- Why is this expression working? (C# 6.0)
- reading an array column in C#
- Save file in Music folder windows phone
- Report form not showing in VS 2013
- Accessing shared folder over a network in windows service
- Check path case sensitivity
- Upload a project to github C# Visual Studio
- How Can I do c# dictionary for php but. Loop class
- Session lost after first Twitter OAuth request
- c# fixed region optimizations
- OPOS PosExplorer.GetDevice() returns null in .net 4.5 environment?
- C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App
- Why is this value zero after ajax call finishes (asp.net mvc 3 and jQuery)?
- How do you Infer the type of an Action<T> dynamically?
- How to deserialize json inside a json to a string property
- C# singleton between projects didn't work
- Match string of numbers in different capture groups
- Can ServiceStack.Text deserialize JSON to a custom generic type?