When sharing h.264 (AVC) formatted video in an MP4 container, Windows Media Player may have trouble interpreting this format. In many cases it is simply the audio that causes the issue, but my general methodology is to convert to an AVI container anyway. This tutorial describes how to convert an existing video into an AVI formatted file suitable for Windows XP or later.

The first step is to take a look at what kind of video you’ve got:

$ ffmpeg -i input.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-05-22 19:21:02
  Duration: 00:02:53.52, start: 0.000000, bitrate: 2984 kb/s
    Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720, 2789 kb/s, 29.97 fps, 29.97 tbr, 60k tbn, 59.94 tbc
    Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 191 kb/s
    Metadata:
      creation_time   : 2013-05-22 19:21:09

The audio format is AAC and the video is h.264; but Windows may not support this. You can view a list of supported files at http://support.microsoft.com/kb/316992. Essentially, anything other than Media Player 12 will present issues and while this is a very prevalent version (Windows 7 and above) there are still a good percentage of systems that won’t have this.

Fortunately, the conversion process is fairly straightforward. Looking at what is supported, MPEG video and WAV audio are the most ubiquitous CODECS and should be widely supported from within an AVI. The first in this case is to extract the audio from my MP4:

avconv -i input.mp4 -map 0:1 sound.wav

This basically says take input.mp4 and pull out Input 0/Stream 1 (-map 0:1) – and send the result for that to the file sound.wav.

You can try to playback the WAV at this point to make sure the audio track is good. The last step will be to multiplex the WAV audio with the video portion of the original media:

avconv -y -i input.mp4 -i sound.wav -acodec copy -c:v mpeg4  -q:v 2 -map 0:v:0 -map 1:a:0 -f avi final.avi

Quite a few things are happening here. First of all, the -i parameters are used to denote one or more input files and the map parameters designate what portion of those files should be picked for output. For example, -map 0:v:0 says to pick the first file video and grab stream 0 from that file and -map 1:a:0 says use the second file audio with stream 0.

There is a video conversion denoted by -c:v mpeg4 which says the video should be transcoded to MPEG4 and -f avi tells it to select AVI as the container format for the resulting file.

When all is said and done, you will have an MPEG-4 video with WAV audio contained inside an AVI file. This should be able to play on just about any version of Windows, and on other platforms using VLC.

$ avenc -i final.avi
avconv version 0.8.10-4:0.8.10-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Feb  6 2014 20:56:59 with gcc 4.6.3
Input #0, avi, from 'final.avi':
  Metadata:
    encoder         : Lavf53.21.1
  Duration: 00:02:53.50, start: 0.000000, bitrate: 13592 kb/s
    Stream #0.0: Video: mpeg4 (Simple Profile), yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 29.97 tbn, 30k tbc
    Stream #0.1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s