Windows-Compatible Video on Linux

Windows Media Player with its default codecs won't play many common video formats in widespread use today. It seems to vary with Windows version as to which codecs are and are not supported. Other codecs can be downloaded and installed for the player — most of them are even free1. But most people won't or cannot do this.

As I should have expected, once I started making video clips and posting them on this site, many people were not be able to view them. This lead to an attempt to determine which codecs, exactly, Windows could be counted on to support. Damned few outside of their own proprietary formats, it turns out. Support for most other codecs seems to come from third parties.

There are several formats which are commonly supposed to be legible to WMP and I found ways to either generate them from my image sequences or convert my existing formats into them. But I had conflicting reports from different Windows users as to whether or not these can always be viewed on WMP.

With those caveats in mind, here are some sample scripts showing which formats I thought should work and how I manipulated them. Hopefully, they will still work for me if I come back and want to do this again sometime.

(1) There are free codecs available at free-codecs.com

From Raw Bitmap Images

In my original attempts I used memcoder to make all the movies. I don't know why I made that choice. At this point I am using ffmpeg directly.

This first command works from .JPG files, which must be named such that an ascii sort results in the images in the right sequence (e.g. test-001.jpg, test-002.jpg, ..., NOT test-1.jpg because test-10.jpg would then come before test-2.jpg). uses all the bmp files it finds in JPGDIR to make an mp4-encoded AVI movie.

## Make an avi out of jpeg files located in DIR
mencoder mf://${DIR}/*.jpg -ovc lavc -o test.avi

## Make (supposedly) windows compatible mpegs with one of
## the following:
mencoder mf://${DIR/*.jpg -o test2.mpg -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=msmpeg4v2:vbitrate=800 

mencoder mf://${DIR}/*.jpg -o test3.mpg -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=msmpeg4v2:vbitrate=800 

mencoder mf://${DIR}/*.jpg -o test4.mpg -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=wmv1:vbitrate=800 

mencoder mf://${DIR}/*.jpg -o test1.wmv -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=wmv1:vbitrate=800 


## The following are supposed to be Windows Media Player compatable
## but didn't work for most people:

mencoder mf://${DIR}/*.jpg -mf fps=10 -o test5.mpg -ovc lavc 
      -lavcopts vcodec=msmpeg4v2:vbitrate=800 

mencoder mf://${DIR}/*.jpg -o test6.mpg -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=mjpeg

mencoder mf://${DIR}/*.jpg -mf fps=10 -o test7.mpg -ovc lavc 
       -lavcopts vcodec=msmpeg4v2:vbitrate=800 

mencoder mf://${DIR}/*.jpg -o test8.mpg -ovc lavc 
	-mf type=jpg:fps=10 -lavcopts vcodec=msmpeg4

Conversions

These days I am using ffmpeg2— especially to convert from one movie format to another. Here is a script which does this with a very simple user interface:

#!/bin/bash

# Display usage help and exit
function usage () {
        cat << EOF

This command converts a video clip from one format to another using ffmpeg.
By default it keeps the same quality. 

Syntax:

  cnvt-movie [options]   
Options:

  -v  Video codec. [Default: wmv2]

Note: for Windows compatibility, try wmv2 or msmpeg4v2 for codecs.

EOF
        exit
}

CODEC="wmv2"
QUALITY="-sameq"
## -sameq uses same quality as input for output


# Process commandline
while getopts "v:h" opt; do
  case $opt in
    v) CODEC="$OPTARG";;
    ?) usage; exit 1;;
    h) usage; exit 1;;
  esac
done
shift $(($OPTIND - 1))
# $1 is what's left

INFILE=$1
OUTFILE=$2

ffmpeg -i ${INFILE} -vcodec $CODEC $QUALITY ${OUTFILE}

(2) Ffmpeg is an excellent quality, very fast multi-platform video and audio streamer and converter that understands a truly astounding number of codecs. It is free software licensed under LGPL or GPL, depending on how you configure it.