45

I am trying to make a MKV video with a MPEG4 video codec and AC3 audio codec available to be played online using Mozilla or Chrome. I have tried multiple methods including native HTML5, which plays back the video but no audio and from what I've read AC3 is a proprietary codec so it is not included in the supported codecs. The code for that was as follows:

<video width='1024' height='768' controls autoplay> 
    <source src="path_to_src" type='video/x-matroska'>
</video>

I then tried to use the VLC web plugin (as I know VLC can play the files correctly) but have not yet gotten it to play any file, there doesn't seem to be a lot of consistency in the examples for using this method. Here is what I have tried so far using the VLC plugin:

<embed type="application/x-vlc-plugin" version="VideoLAN.VLCPlugin.2" 
width="1024" height="768" id="vlc" autoplay="yes" target="path_to_file"></embed>

The VLC page here says to add this:

<object classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"
 codebase="http://download.videolan.org/pub/videolan/vlc/last/win32/axvlc.cab">

But the codebase doesn't seem to exist anymore and adding that classid to the code above has no effect on the playing of the file. Both methods result in the VLC player box being made but nothing ever getting played and the developer console doesn't show any errors.

So my question is does anyone know a workaround to get AC3 audio to play in the native HTML5 player or what the correct syntax is for the VLC web plugin? Or does anyone have a different player altogether they would recommend? Any and all help appreciated!

ccpizza
  • 28,968
  • 18
  • 162
  • 169
Alex Meyer
  • 771
  • 1
  • 7
  • 17
  • 1
    mkv isn't a supported format for HTML5 video. you will need to transcode/transmux to a format (or formats) supported by the browsers you need to deliver to – Offbeatmammal Jan 17 '14 at 19:29
  • I found it easier to convert videos to .swf using ffmpeg and use it for streaming. – Step by Step Oct 08 '18 at 15:12

6 Answers6

32

HTML5 does not support .mkv / Matroska files but you can use this code...

<video>
    <source src="video.mkv" type="video/mp4">
</video>

But it depends on the browser as to whether it will play or not. This method is known to work with Chrome.

Kingsley
  • 14,398
  • 5
  • 31
  • 53
  • 5
    This did not work while testing in firefox. I just converted the mkv file to webm. – rhigdon Mar 13 '20 at 20:52
  • 3
    Works fine on Android and LG TV for view movies from pc serving the video storage using you html :) – e-info128 May 16 '20 at 08:11
  • It doesn't work for me, unfortunately! Chrome only displays a black video without any playback controls. – gignu Oct 17 '21 at 20:52
  • Ok, to add the playback controls you have to add them manually to the video tag! Like so: ``. But then there is still no audio. Does anyone know how to add the audio? – gignu Oct 17 '21 at 21:11
  • It's worked for me in the Chrome browser version: `Version 94.0.4606.81 (Official Build) (x86_64)` Here is the video tag: `` – hgsongra Oct 21 '21 at 09:27
16

You can use this following code. work just on chrome browser.

 function failed(e) {
   // video playback failed - show a message saying why
   switch (e.target.error.code) {
     case e.target.error.MEDIA_ERR_ABORTED:
       alert('You aborted the video playback.');
       break;
     case e.target.error.MEDIA_ERR_NETWORK:
       alert('A network error caused the video download to fail part-way.');
       break;
     case e.target.error.MEDIA_ERR_DECODE:
       alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
       break;
     case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
       alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
       break;
     default:
       alert('An unknown error occurred.');
       break;
   }
 }
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <meta name="author" content="Amin Developer!" />

 <title>Untitled 1</title>
</head>
<body>

<p><video src="http://jell.yfish.us/media/Jellyfish-3-Mbps.mkv" type='video/x-matroska; codecs="theora, vorbis"' autoplay controls onerror="failed(event)" ></video></p>
<p><a href="YOU mkv FILE LINK GOES HERE TO DOWNLOAD">Download the video file</a>.</p>

</body>
</html>
Amin
  • 414
  • 1
  • 11
  • 23
  • 1
    This works but I get no sound. Do I have to specify the audio codec as well? – Mini Fridge Sep 30 '16 at 18:45
  • 2
    Sound track encoded with AC3 audio codec can't be played in Chrome due to licensing restrictions, so basically this method doesn't work for .mkv files playback – edtech Feb 01 '18 at 11:43
11

To use video extensions that are MKV. You should use video, not source

For example :

  <!-- mkv -->
  <video width="320" height="240" controls src="assets/animation.mkv"></video>
<!-- mp4 -->
  <video width="320" height="240" controls>
    <source src="assets/animation.mp4" type="video/mp4" />
  </video>
My answer may be incomprehensible to you, so if you do not understand, click on this
Mm.Mirzaei.dev
  • 333
  • 3
  • 10
5

HTML5 and the VLC web plugin were a no go for me but I was able to get this work using the following setup:

DivX Web Player (NPAPI browsers only)

AC3 Audio Decoder

And here is the HTML:

<embed id="divxplayer" type="video/divx" width="1024" height="768" 
src ="path_to_file" autoPlay=\"true\" 
pluginspage=\"http://go.divx.com/plugin/download/\"></embed>

The DivX player seems to allow for a much wider array of video and audio options than the native HTML5, so far I am very impressed by it.

mirh
  • 514
  • 8
  • 14
Alex Meyer
  • 771
  • 1
  • 7
  • 17
4
<video controls width=800 autoplay>
    <source src="file path here">
</video>

This will display the video (.mkv) using Google Chrome browser only.

JohnC
  • 167
  • 9
1

There's a JavaScript project for that at https://github.com/ilian/mkv-web

Modern web browsers only support the WebM container format that is based on Matroska, but limited to royalty-free codecs. Even when the MKV file contains media encoded by a codec that the browser is able to decode, most browsers are unable to play media in such a container. This project copies the underlying media streams to containers that are supported by most browsers (e.g. mp4, webm) inside the browser without third-party extensions or programs. This is achieved by remuxing media segments with ffmpeg compiled to webassembly (thanks to the ffmpeg.wasm project) using web workers. Remuxed chunks are sent from the Web Worker to the main thread and appended to the HTML5 video element using Media Source Extensions.

WebAugi
  • 11
  • 1