title: Writing an MP4 file on the Mac with OpenCV ffmpeg
body: <p>I am using OpenCV with ffmpeg on a mac to write video. I've been able to successfully write .avi files using the codec/fourcc code, FMP4. I would like to write .mp4 files, however. When I try to write an .mp4 file using fourcc FMP4 I get this error:</p>
  
  <pre><code>[mp4 @ 0x100b4ec00] Tag FMP4/0x34504d46 incompatible with output codec id '13' ( [0][0][0])
  </code></pre>
  
  <p>When I use AVC1 I get the following error:</p>
  
  <pre><code>[libx264 @ 0x104003000] broken ffmpeg default settings detected
  [libx264 @ 0x104003000] use an encoding preset (e.g. -vpre medium)
  [libx264 @ 0x104003000] preset usage: -vpre &lt;speed&gt; -vpre &lt;profile&gt;
  [libx264 @ 0x104003000] speed presets are listed in x264 --help
  [libx264 @ 0x104003000] profile is optional; x264 defaults to high
  Could not open codec 'libx264': Unspecified error
  </code></pre>
  
  <p>Does anyone here know the right codec to use with OpenCV and ffmpeg to write to an MP4 container on the Mac? </p>
  
  <p>If AVC1 is the right codec, how do I install ffmpeg + OpenCV correctly? I did</p>
  
  <pre><code>brew install gpac
  brew install ffmpeg
  brew install opencv
  </code></pre>
  
  <p>The call I am using to open the videowriter:</p>
  
  <pre><code>fourcc = cv2.cv.CV_FOURCC('A', 'V', 'C', '1')   
  video_out = cv2.VideoWriter(
      filename=output_filename,
      fourcc=fourcc,
      fps=video_fps,
      frameSize=(video_width,video_height),
      isColor=1)
  </code></pre>
  
  <p>When I run <code>x264 --help</code> I get</p>
  
  <pre><code>% x264 --help
  x264 core:125
  Syntax: x264 [options] -o outfile infile
  
  Infile can be raw (in which case resolution is required),
    or YUV4MPEG (*.y4m),
    or Avisynth if compiled with support (no).
    or libav* formats if compiled with lavf support (no) or ffms support (no).
  Outfile type is selected by filename:
   .264 -&gt; Raw bytestream
   .mkv -&gt; Matroska
   .flv -&gt; Flash Video
   .mp4 -&gt; MP4 if compiled with GPAC support (no)
  Output bit depth: 8 (configured at compile time)
  
  Options:
  
    -h, --help                  List basic options
        --longhelp              List more options
        --fullhelp              List all options
  
  Example usage:
  
        Constant quality mode:
              x264 --crf 24 -o &lt;output&gt; &lt;input&gt;
  
        Two-pass with a bitrate of 1000kbps:
              x264 --pass 1 --bitrate 1000 -o &lt;output&gt; &lt;input&gt;
              x264 --pass 2 --bitrate 1000 -o &lt;output&gt; &lt;input&gt;
  
        Lossless:
              x264 --qp 0 -o &lt;output&gt; &lt;input&gt;
  
        Maximum PSNR at the cost of speed and visual quality:
              x264 --preset placebo --tune psnr -o &lt;output&gt; &lt;input&gt;
  
        Constant bitrate at 1000kbps with a 2 second-buffer:
              x264 --vbv-bufsize 2000 --bitrate 1000 -o &lt;output&gt; &lt;input&gt;
  
  Presets:
  
        --profile &lt;string&gt;      Force the limits of an H.264 profile
                                    Overrides all settings.
                                    - baseline,main,high,high10,high422,high444
        --preset &lt;string&gt;       Use a preset to select encoding settings [medium]
                                    Overridden by user settings.
                                    - ultrafast,superfast,veryfast,faster,fast
                                    - medium,slow,slower,veryslow,placebo
        --tune &lt;string&gt;         Tune the settings for a particular type of source
                                or situation
                                    Overridden by user settings.
                                    Multiple tunings are separated by commas.
                                    Only one psy tuning can be used at a time.
                                    - psy tunings: film,animation,grain,
                                                   stillimage,psnr,ssim
                                    - other tunings: fastdecode,zerolatency
  
  Frame-type options:
  
    -I, --keyint &lt;integer or "infinite"&gt; Maximum GOP size [250]
        --tff                   Enable interlaced mode (top field first)
        --bff                   Enable interlaced mode (bottom field first)
        --pulldown &lt;string&gt;     Use soft pulldown to change frame rate
                                    - none, 22, 32, 64, double, triple, euro (requires cfr input)
  
  Ratecontrol:
  
    -B, --bitrate &lt;integer&gt;     Set bitrate (kbit/s)
        --crf &lt;float&gt;           Quality-based VBR (0-51) [23.0]
        --vbv-maxrate &lt;integer&gt; Max local bitrate (kbit/s) [0]
        --vbv-bufsize &lt;integer&gt; Set size of the VBV buffer (kbit) [0]
    -p, --pass &lt;integer&gt;        Enable multipass ratecontrol
                                    - 1: First pass, creates stats file
                                    - 2: Last pass, does not overwrite stats file
  
  Input/Output:
  
    -o, --output &lt;string&gt;       Specify output file
        --sar width:height      Specify Sample Aspect Ratio
        --fps &lt;float|rational&gt;  Specify framerate
        --seek &lt;integer&gt;        First frame to encode
        --frames &lt;integer&gt;      Maximum number of frames to encode
        --level &lt;string&gt;        Specify level (as defined by Annex A)
        --quiet                 Quiet Mode
  
  Filtering:
  
        --vf, --video-filter &lt;filter0&gt;/&lt;filter1&gt;/... Apply video filtering to the input file
  
        Filter options may be specified in &lt;filter&gt;:&lt;option&gt;=&lt;value&gt; format.
  
        Available filters:
        crop:left,top,right,bottom
        select_every:step,offset1[,...]
  </code></pre>
  
  <p>Thanks,
  -s</p>