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;
            // 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

                Process process = System.Diagnostics.Process.Start(processInfo);
                result = process.StandardError.ReadToEnd();

            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