Re: FFMPEG Debugging

Leon Bottou <[email protected]> Sun, 23 Apr 2006 09:37:42 -0400
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Saturday 22 April 2006 16:51, Ian Smith-Heisters wrote:
> It's apparently not working, unfortunately. --version declares FFMPEG
> to be build 3277056 (whether that's the CVS revision, the freshrpms
> build, or the what, I have no idea). I tried compiling FFMPEG from
> CVS, but to no avail. Can you give me some tips on debugging so that I
> can just hack ffmpeg.lsh to work with the version of FFMPEG I have?

Do you see my (extensive) changes.
I am not sure they have updated the anonymous cvs in a long time.
I attach the modified files below.

The ffmpeg version I use is the one that comes with ubuntu.
The necessary packages are called libavcodec-dev and libavformat-dev.
See: http://packages.ubuntu.com/dapper/source/ffmpeg

- L.
ffmpeg.lsh (text/x-java, 29.3 KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: ffmpeg.lsh,v 1.13 2006/04/10 22:19:22 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(libload "avsource")
(libload "ffmpeg-config")
(libload "ffmpeg-enum")
(libload "libidx/idx-macros")
(libload "libidx/idx-ubyte")
(libload "libc/libc")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


#? ** FFmpeg Decoding Interface

(de av-init()
  #{{
    static int av_init = 0;
    if (! av_init) {
      av_init = 1;
      av_register_all();
    }
  }#}
  t
)

#? (av-open-input-file <filename>)
;; {<see> AvInputFile}
;;
;; {<p>
;;   Open the multimedia file <filename> using the FFmpeg library and
;;   returns an instance of class <AvInputFile>.
;; }
(de av-open-input-file(s)
  ((-str-) s)
  (let ((ai (new AvInputFile)))
    (==> ai open s)
    ai ) )

#? (av-open-video-source <filename>)
;; {<see> VideoSource}
;; {<see> AvVideoSource}
;;
;; {<p>
;;   Open the multimedia file <filename> using the FFmpeg library and
;;   returns a <AvVideoSource> object connected to the first video stream in
;;   the file.
;; }
(de av-open-video-source(s)
  ((-str-) s)
  (let ((ai (new AvInputFile)))
    (==> ai open s)
    (let ((vs 0)
	  (ns (==> ai get-number-of-streams)))
      ((-int-) vs ns)
      (while (and (< vs ns) 
		  (<> (==> ai get-stream-codec-type vs) @CODEC_TYPE_VIDEO))
	(incr vs) )
      (when (>= vs ns)
	(error "No video stream in this file") )
      (new AvVideoSource ai vs) ) ) )

#? (av-open-audio-source <filename>)
;; {<see> AudioSource}
;; {<see> AvAudioSource}
;;
;; {<p>
;;   Open the multimedia file <filename> using the FFmpeg library and
;;   returns a <AvAudioSource> object connected to the first audio stream in
;;   the file.
;; }
(de av-open-audio-source(s)
  ((-str-) s)
  (let ((ai (new AvInputFile)))
    (==> ai open s)
    (let ((vs 0)
	  (ns (==> ai get-number-of-streams)))
      ((-int-) vs ns)
      (while (and (< vs ns) 
		  (<> (==> ai get-stream-codec-type vs) @CODEC_TYPE_AUDIO))
	(incr vs) )
      (when (>= vs ns)
	(error "No video stream in this file") )
      (new AvAudioSource ai vs) ) ) )

	   

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; AVINPUTFILE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#? * AvInputFile
;; {<see> (av-open-input-file <filename>)}
;;
;; {<p>
;;   Class <AvInputFile> is a handle for reading a multimedia file. It is
;;   best created using the utility function <av-open-input-file>. Each
;;   multimedia file contains one or more streams. Each stream is either an
;;   audio stream or a video stream.
;; }
;; {<p>
;;   This class defines several useful slots:
;; }
;; {<ul>
;;   {<li>
;;     Slots <audio-streams> and <video-streams> contain the number of
;;     streams of each type.
;;   }
;;   {<li>
;;     The geometry of the first video stream is stored in fields 
;;     <frame-height>, <frame-width>, <frame-aspect-ratio>.
;;   }
;;   {<li>
;;     The sampling rate and the number of channels of the first audio
;;     stream are stored in slots <audio-sample-rate> and <audio-channels>.
;;   }
;; }
(defclass AvInputFile Object
  ((-gptr-) ic)
  ((-bool-) gotpacket)
  ((-gptr-) curpacket)
  ((-idx1- (-gptr-)) sources)
  ((-gptr-) image_format) 
  ((-gptr-) file_iformat)
  ((-int-)  audio_streams)
  ((-int-)  video_streams)
  ((-int-)  audio_channels)
  ((-int-)  audio_sample_rate)
  ((-int-)  frame_height)
  ((-int-)  frame_width)
  ((-real-) frame_aspect_ratio)
  ((-int-)  frame_pix_fmt)
  ((-real-) frame_rate)
  ((-int-)  workaround_bugs)
  ((-int-)  error_resilience)
  ((-int-)  error_concealment)
  ((-int-)  idct_algo)
  ((-int-)  bitexact)
  ((-int-)  debug)
  )

#? (new AvInputFile)
;; {<p>
;;   Create a new empty instance of class <AvInputFile>. Calling method
;;   <open> associates this handle with a multimedia file. Various FFmpeg
;;   options can be set by defining certain slots of this object before
;;   calling <open>.
;; }
(defmethod AvInputFile AvInputFile()
  (setq ic (gptr ()))
  (setq gotpacket ())
  (setq curpacket (to-gptr #{ av_mallocz(sizeof(AVPacket)) #}))
  (setq sources (gptr-matrix 4))
  (setq image_format (gptr ())) 	;ffmpeg opt_image_format: -img
  (setq file_iformat (gptr ()))		;ffmpeg opt_format: -f
  (setq audio_streams 0)
  (setq video_streams 0)
  (setq audio_channels 1)		;ffmpeg opt_audio_channels: -ac
  (setq audio_sample_rate 44100)	;ffmpeg opt_audio_rate: -ar
  (setq frame_height 128)		;ffmpeg opt_frame_size: -s
  (setq frame_width 160)		;ffmpeg opt_frame_size: -s
  (setq frame_aspect_ratio 0)		;ffmpeg opt_frame_aspect_ratio: -aspect
  (setq frame_pix_fmt @PIX_FMT_YUV420P)	;ffmpeg opt_frame_pix_fmt:  -pix_fmt
  (setq frame_rate 25)			;ffmpeg opt_frame_rate: -r
  (setq workaround_bugs 1) 		;ffmpeg opt_workaround_bug: -bug
  (setq error_resilience 2)		;ffmpeg opt_error_resilience: -er
  (setq error_concealment 3)		;ffmpef opt_error_concealment: -ec
  (setq idct_algo 0)			;ffmpeg opt_idct_algo: -idct_algo
  (setq bitexact 0)			;ffmpeg opt_bitexact: -bitexatc
  (setq debug 0)			;ffmpef opt_debug: -debug
  (when (not curpacket)
    (error "out of memory") )
  () )

(defmethod AvInputFile -destructor()
  (when curpacket
    (when gotpacket
      #{ av_free_packet((AVPacket*)$curpacket); #} )
    #{ av_free($curpacket); #} )
  (when ic
    #{ av_close_input_file((AVFormatContext*)$ic); #} 
    (setq ic (gptr ())) )
  () )

#? (==> <avinputfile> get-number-of-streams)
;; {<p>
;;   Return the total number of streams in the multimedia file.
;; }
(defmethod AvInputFile get-number-of-streams()
  (+ audio-streams video-streams) )

#? (==> <avinputfile> get-stream-codec-type <n>)
;; {<p>
;;   Returns the type of the stream number <n>. The return value is one of
;;   the constants named <@CODEC_TYPE_XXX>. This includes 
;;   <@CODEC_TYPE_VIDEO> or <@CODEC_TYPE_AUDIO>.
;; }
(defmethod AvInputFile get-stream-codec-type(n)
  ((-int-) n)
  (when (or (< n 0) (>= n (+ audio-streams video-streams)))
    (error "Illegal stream number") )
  (to-int #{ ((AVFormatContext*)($this->ic))->streams[$n]
                           ->codec->codec_type #}) )

#? (==> <avinputfile> get-stream-codec-id <n>)
;; {<p>
;;   Returns the identifier of the codec for stream number <n>. The return
;;   value is one of the constants named <@CODEC_ID_XXX>.
;; }
(defmethod AvInputFile get-stream-codec-id(n)
  ((-int-) n)
  (when (or (< n 0) (>= n (+ audio-streams video-streams)))
    (error "Illegal stream number") )
  (to-int #{ ((AVFormatContext*)($this->ic))->streams[$n]
                           ->codec->codec_id #}) )

#? (==> <avinputfile> get-format-name)
;; {<p>
;;   Returns a string describing the multimedia file format.
;; }
(defmethod AvInputFile get-format-name()
  (if file_iformat
      (ptr-str (to-gptr #{ ((AVInputFormat*)($file_iformat))->name #} ))
    "<?>" ) )

#? (==> <avinputfile> get-start-time)
;; {<p>
;;   Returns the first presentation time stamp for the multimedia file.
;;   Presentation time stamps are real numbers expressed in seconds.
;; }
(defmethod AvInputFile get-start-time()
  (if ic
      (to-real #{ (double)(((AVFormatContext*)($ic))->start_time)/AV_TIME_BASE #})
    0 ) )

#? (==> <avinputfile> get-duration)
;; {<p>
;;   Returns the duration of the multimedia file expressed in seconds.
;;  }
(defmethod AvInputFile get-duration()
  (if ic
      (to-real #{ (double)(((AVFormatContext*)($ic))->duration)/AV_TIME_BASE #})
    0 ) )


#? (==> <avinputfile> open <filename>)
;; {<p>
;;   Associate the empty <avinputfile> object with the multimedia file named
;;   <filename>. This function checks the file format and the file codecs.
;;   It causes an error if the file cannot be decoded by the ffmpeg library.
;;  }
(defmethod AvInputFile open(s)
  ((-str-) s)
  (av-init)
  (when ic (error "Already open"))
  (let ((ai this))
    #{{
        /* ------------------------------------------------- */
        /* This is derived from 'opt_input_file' in ffmpeg.c */
        /* ------------------------------------------------- */
        AVFormatParameters params;
        AVFormatParameters *ap = &params;
        AVFormatContext *ic = 0;
        AVInputFormat *ifmt = (AVInputFormat*)($ai->file_iformat);
        int err, i, ret;
        AVRational rfps;
        char *filename = $s->data;

        if (!strcmp(filename, "$stdin"))
           filename = "pipe:";

        /* get default parameters from command line */ 
        memset(ap, 0, sizeof(*ap));
        ap->sample_rate = $ai->audio_sample_rate;
        ap->channels = $ai->audio_channels;
        ap->width = $ai->frame_width;
        ap->height = $ai->frame_height;
        ap->image_format = $ai->image_format;
        ap->pix_fmt = $ai->frame_pix_fmt;
        
        /* open the input file with generic libav function */
        err = av_open_input_file(&ic,filename,ifmt,0,ap);
        if (err < 0) {
           fprintf(stderr, "%s: Error %d while opening file\n", filename, err);
           run_time_error("FFmpeg returned an error code");
        }
        $ai->ic = (gptr)(ic);
        $ai->file_iformat = (gptr)(ic->iformat);

        /* If not enough info to get the stream parameters, we decode the
           first frames to get it. (used in mpeg case for example) */
        ret = av_find_stream_info(ic);
        if (ret < 0) {
           fprintf(stderr, "%s: could not find codec parameters\n", filename);
           run_time_error("FFmpeg returned an error code");
        }
    
        /* update the current parameters so that they match 
           the one of the input stream */
        $ai->audio_streams = 0;
        $ai->video_streams = 0;
        for(i=0;i<ic->nb_streams;i++) {
           AVCodecContext *enc = ic->streams[i]->codec;
           switch(enc->codec_type) {
           case CODEC_TYPE_AUDIO:
             $ai->audio_streams += 1;
             $ai->audio_channels = enc->channels;
             $ai->audio_sample_rate = enc->sample_rate;
             break;
           case CODEC_TYPE_VIDEO:
             $ai->video_streams += 1;
             $ai->frame_height = enc->height;
             $ai->frame_width = enc->width;
	     $ai->frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
	     $ai->frame_pix_fmt = enc->pix_fmt;
             rfps      = ic->streams[i]->r_frame_rate;
             enc->workaround_bugs = $ai->workaround_bugs;
             enc->error_resilience = $ai->error_resilience;
             enc->error_concealment = $ai->error_concealment;
             enc->idct_algo = $ai->idct_algo;
             enc->debug = $ai->debug;
             if(enc->codec_id==CODEC_ID_MPEG1VIDEO || enc->codec_id==CODEC_ID_H264)
                enc->flags |= CODEC_FLAG_TRUNCATED;
             if ($ai->bitexact)
                enc->flags |= CODEC_FLAG_BITEXACT;
             /* update the current frame rate to match the stream frame rate */
             $ai->frame_rate      = av_q2d(rfps);
             enc->rate_emu = 0;
             break;
           default:
             break;
        }
      }
    }#} 
    )
  ;; resize source vector
  (idx-g1resize sources (==> this get-number-of-streams))
  this )

#? (==> <avinputfile> pump)
;;
;; {<p>
;;   Method <pump> reads data from the multimedia file and distributes it to
;;   the various streams.
;; }
(defmethod AvInputFile pump()
  ;; Get rid of current packet
  (when gotpacket
    #{ av_free_packet((AVPacket*)$curpacket); #}
    (setq gotpacket ()) )
  #{{
     AVFormatContext *ic = (AVFormatContext*)$ic;
     AVPacket *pkt = (AVPacket*)$curpacket;
     if (av_read_packet(ic, pkt) >= 0)
        $gotpacket = 1;
  }#}
  ;; Signal avsources
  (when gotpacket
    (let ((n (to-int #{ ((AVPacket*)$curpacket)->stream_index #})))
      (when (sources n)
        (==> (to-obj AVSource (sources n)) process) ) )
    t ) )



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; AVPACKETLIST
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; This class is private

(defclass AvPacketList Object
  ((-gptr-) head)
  ((-gptr-) tail)
  ((-int-)  count)
)

(defmethod AvPacketList AvPacketList()
  (setq head (gptr ()))
  (setq tail (gptr ())) 
  (setq count 0) )

(defmethod AvPacketList put(p)
  ((-gptr-) p)
  #{{ 
     AVPLElt *z = (AVPLElt*)av_malloc(sizeof(AVPLElt));
     if (!z) run_time_error("Out of memory");
     z->next = (AVPLElt*)$head;
     z->prev = 0;
     z->pkt = *(AVPacket*)$p;
     if (z->next) 
       z->next->prev = z;
     else
       $tail = (gptr)z;
     $head = (gptr)z;
  }#}
  (incr count) )

(defmethod AvPacketList pop()
  (when tail
    #{{
       AVPLElt *z = (AVPLElt*)$tail;
       $tail = (gptr)(z->prev);
       if (z->prev)
         z->prev->next = 0;
       else
         $head = 0;
       av_free_packet(&z->pkt);
       av_free(z);
    }#} 
    (incr count -1) )
  count )

(defmethod AvPacketList peek()
  (let ((p (gptr ())))
    (when tail
      #{ $p = (gptr)&((AVPLElt*)$tail)->pkt; #} )
    p ) )

(defmethod AvPacketList -destructor()
  (while (> count 0)
    (==> this pop) ) )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; AVAUDIOSOURCE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


#? * AvAudioSource
;; {<see> AudioSource}
;;
;; {<p>
;;   This subclass of <AudioSource> provides access to the audio streams of
;;   a multimedia file represented by an instance of <AvInputFile>.
;;
;; {<b> WARNING}: Currently, this class is not usable.
;; }
(defclass AvAudioSource AudioSource
  ((-obj- (AvInputFile)) ai)
  ((-obj- (AvPacketList)) data)
  ((-int-) streamno)
  ((-gptr-) st) 
  ;; information
  ((-int-)  audio_channels)
  ((-int-)  audio_sample_rate) )


#? (new AvAudioSource <avinputfile> <n>)
;; {<p>
;;   Creates a new <AvAudioSource> object for accessing stream number <n> in
;;   the multimedia file <avinputfile>. Stream number <n> must of course be
;;   an audio stream.
;; }
(defmethod AvAudioSource AvAudioSource(avfile n)
  ((-obj- (AvInputFile)) avfile)
  ((-int-) n)
  (setq ai avfile)
  (setq data (new AvPacketList))
  (setq streamno n)
  (setq st (gptr ()))
  (setq audio_channels 1)
  (setq audio_sample_rate 44100)
  (when (or (< n 0) (>= n (==> avfile get-number-of-streams)))
    (error "Illegal stream number") )
  (when (<> (==> avfile get-stream-codec-type n) @CODEC_TYPE_AUDIO)
    (error "Not an audio stream") )
  #{ $st = (gptr)( ((AVFormatContext*)($ai->ic))->streams[$n] ); #}
  (when (not st) 
    (error "Stream not found")) 
  #{{
    AVStream *st = (AVStream*)($st);
    AVCodec *codec = avcodec_find_decoder(st->codec->codec_id);
    if (!codec)
       run_time_error("FFmpeg error: unsupported codec");
    if (avcodec_open(st->codec, codec) < 0) 
       run_time_error("FFmpeg error: error while opening codec");
  }#}
  #{{
    AVStream *st = (AVStream*)($st);
    AVCodecContext *enc = st->codec;
    $audio_channels = enc->channels;
    $audio_sample_rate = enc->sample_rate;
  }#}
  (:ai:sources streamno (gptr this))
  () )

(defmethod AvAudioSource process()
  ;; This is disabled for now because 
  ;; AudioSource is not implemented yet.
  (when (and () :ai:gotpacket)
    (==> data put :ai:curpacket)
    (setq :ai:gotpacket ())
    t ) )

(defmethod AvAudioSource -destructor()
  (when (and (to-gptr ai) (to-gptr :ai:sources))
    (:ai:sources streamno (gptr ())) ) 
  () )

#? (==> <avaudiosource> get-codec-name)
;; {<p>
;;   Returns a string containing the name of the codec for this audio stream.
;; }
(defmethod AvAudioSource get-codec-name()
  (ptr-str (to-gptr #{ ((AVStream*)($st))->codec->codec->name #})) )

#? (==> <avaudiosource> get-codec-id)
;; {<p>
;;   Returns the identifier of the codec for this audio stream. This
;;   function returns one of the <@CODEC_ID_XXX> constant.
;; }
(defmethod AvAudioSource get-codec-id()
  (==> ai get-stream-codec-id streamno) )

#? (==> <avaudiosource> get-start-time)
;; {<p>
;;   Returns the first presentation time stamp for this audio stream.
;;   Presentation time stamps are real numbers expressed in seconds.
;; }
(defmethod AvAudioSource get-start-time()
  (to-real #{ (double)(((AVStream*)($st))->start_time)/AV_TIME_BASE #}) )

#? (==> <avaudiosource> get-duration)
;; {<p>
;;   Returns the duration of this audio stream expressed in seconds.
;; }
(defmethod AvAudioSource get-duration()
  (to-real #{ (double)(((AVStream*)($st))->duration)/AV_TIME_BASE #}) )





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; AVVIDEOSOURCE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


#? * AvVideoSource
;; {<see> VideoSource}
;;
;; {<p>
;;   This subclass of <VideoSource> provides access to the audio streams of
;;   a multimedia file represented by an instance of <AvInputFile>.
;;
;;   The current frame geometry is available in slots <frame-height>,
;;   <frame-width>, and <frame-aspect-ratio>.
;; }
(defclass AvVideoSource VideoSource
  ((-obj- (AvInputFile)) ai)
  ((-obj- (AvPacketList)) data)
  ((-int-) streamno)
  ((-gptr-) st)
  ;; frames
  ((-bool-) gotcurframe)
  ((-gptr-) curframe)
  ((-gptr-) curptr)
  ((-int-)  curlen)
  ((-real-) curpts)
  ((-int-)  curno)
  ;; information...
  ((-int-)  frame_height)
  ((-int-)  frame_width)
  ((-real-) frame_aspect_ratio)
  ((-int-)  frame_pix_fmt)
  ((-int-)  frame_rate)
  ((-int-)  frame_rate_base) 
  )


#? (new AvVideoSource <avinputfile> <n>)
;; {<p>
;;   Creates a new <AvVideoSource> object for accessing stream number <n> in
;;   the multimedia file <avinputfile>. Stream number <n> must of course be
;;   a video stream.
;; }
(defmethod AvVideoSource AvVideoSource(avfile n)
  ((-obj- (AvInputFile)) avfile)
  ((-int-) n)
  (setq ai avfile)
  (setq data (new AvPacketList))
  (setq streamno n)
  (setq st (gptr ()))
  ;; frame
  (setq gotcurframe ())
  (setq curframe (to-gptr #{ av_mallocz(sizeof(AVFrame)) #}))
  (when (not curframe) (error "Out of memory"))
  (setq curptr (gptr ()))
  (setq curlen 0)
  (setq curpts -1)
  (setq curno -1)
  ;; information
  (setq frame_height 128)
  (setq frame_width 160)
  (setq frame_aspect_ratio 0)
  (setq frame_pix_fmt @PIX_FMT_YUV420P)
  (setq frame_rate 25)
  (setq frame_rate_base 1)
  ;; checks
  (when (or (< n 0) (>= n (==> avfile get-number-of-streams)))
    (error "Illegal stream number") )
  (when (<> (==> avfile get-stream-codec-type n) @CODEC_TYPE_VIDEO)
    (error "Not a video stream") )
  #{ $st = (gptr)( ((AVFormatContext*)($ai->ic))->streams[$n] ); #}
  (when (not st) 
    (error "Stream not found") ) 
  #{{
    AVStream *st = (AVStream*)($st);
    AVCodecContext *enc = st->codec;
    AVCodec *codec = avcodec_find_decoder(enc->codec_id);
    if (!codec)
       run_time_error("FFmpeg error: unsupported codec");
    if (avcodec_open(st->codec, codec) < 0) 
       run_time_error("FFmpeg error: error while opening codec");
    $frame_height = enc->height;
    $frame_width = enc->width;
    $frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
    $frame_pix_fmt = enc->pix_fmt;
    $frame_rate = av_q2d(st->r_frame_rate);
    $curpts = st->start_time/AV_TIME_BASE;
  }#}
  (:ai:sources streamno (gptr this))
  () )

(defmethod AvVideoSource process()
  (when :ai:gotpacket
    (==> data put :ai:curpacket)
    (setq :ai:gotpacket ())
    t ) )

(defmethod AvVideoSource -destructor()
  (when (and (to-gptr ai) (to-gptr :ai:sources))
    (:ai:sources streamno (gptr ())) )
  (when curframe #{ av_free($curframe); #})
  () )

#? (==> <avvideosource> get-codec-name)
;;
;; {<p>
;;   Returns a string containing the name of the codec for this video stream.
;; }
(defmethod AvVideoSource get-codec-name()
  (ptr-str (to-gptr #{ ((AVStream*)($st))->codec->codec->name #})) )

#? (==> <avvideosource> get-codec-id)
;;
;; {<p>
;;   Returns the identifier of the codec for this video stream. This
;;   function returns one of the <@CODEC_ID_XXX> constant.
;; }
(defmethod AvVideoSource get-codec-id()
  (==> ai get-stream-codec-id streamno) )

#? (==> <avvideosource> get-start-time)
;; {<p>
;;   Returns the first presentation time stamp for this video stream.
;;   Presentation time stamps are real numbers expressed in seconds.
;; }
(defmethod AvVideoSource get-start-time()
  (to-real #{ (double)(((AVStream*)($st))->start_time)/AV_TIME_BASE #}) )

#? (==> <avvideosource> get-duration)
;; {<p>
;;   Returns the duration of this video stream expressed in seconds.
;; }
(defmethod AvVideoSource get-duration()
  (to-real #{ (double)(((AVStream*)($st))->duration)/AV_TIME_BASE #}) )

#? (==> <avvideosource> get-frame-rate)
;; {<p>
;;   Returns the frame rate of this video stream expressed in frames per
;;   seconds.
;; }
(defmethod AvVideoSource get-frame-rate()
  (to-real #{ av_q2d(((AVStream*)($st))->r_frame_rate) #}) )

#? (==> <avvideosource> get-frame-period)
;;
;; {<p>
;; Returns the delay between consecutive frames expressed in seconds.
;; This is the inverse of the frame rate.

(defmethod AvVideoSource get-frame-period()
  (/ (==> this get-frame-rate)) )

#? (==> <avvideosource> get-number-of-frames)
;; {<p>
;;   Returns the number of frames estimated from the frame rate and stream
;;   duration.  This is only an estimate because certain files have variable
;;   frame rate, and because certain frames last more than one period.
;; }
(defmethod AvVideoSource get-number-of-frames()
  (* (==> this get-duration) (==> this get-frame-rate)) )

#? (==> <avvideosource> nextframe)
;; {<p>
;;   Method <nextframe> obtains the next video frame. It returns <t> if a
;;   new frame can be accessed, using the frame access methods 
;;   <get-frame-xxx>, and returns <()> when reaching the end of the video
;;   stream.  
;; }
;; {<p>
;;   After initializing the video source, this method must be called once in
;;   order to access the first video frame.
;; }
(defmethod AvVideoSource nextframe()
  (let ((again t))
    ;; increment curpts
    (when (>= curno 0)
      (let ((period (==> this get-frame-period))) 
	(incr curpts period)
	(when gotcurframe
	  (let ((rpt (to-int #{ ((AVFrame*)$curframe)->repeat_pict #})))
	    (when (> rpt 0)
	      (incr curpts (* period rpt 0.5)) ) ) ) ) )
    ;; continue decoding
    (setq gotcurframe ())
    (while (and again (not gotcurframe))
      ;; pump data
      (when (<= curlen 0)
	(==> data pop)
	(while (and again (<= :data:count 0))
	  (setq again (==> ai pump)) )
	(let ((pkt (==> data peek)))
	  (when pkt
	    #{{
	        AVPacket *pkt = (AVPacket*)$pkt;
	        $curlen = pkt->size;
	        $curptr = (gptr) pkt->data;
	    }#} ) ) )
      ;; call decoder
      (when (> curlen 0)
	#{{
            AVStream *st = (AVStream*)$st;
	    AVFrame *curframe = (AVFrame*)$curframe;
	    int gotpic = 0;
	    int ret = avcodec_decode_video(st->codec, curframe, &gotpic, $curptr, $curlen);
	    if (ret < 0) run_time_error("FFmpeg returned an error code while decoding");
	    $curptr = (gptr) (((const char*)$curptr) + ret);
	    $curlen = $curlen - ret;
	    if (gotpic) {
	      $gotcurframe = 1;
              $frame_height = st->codec->height;
              $frame_width = st->codec->width;
              $frame_aspect_ratio = av_q2d(st->codec->sample_aspect_ratio) 
                     * st->codec->width / st->codec->height;
              $frame_pix_fmt = st->codec->pix_fmt;
	    }
	}#} ) ) 
    (when gotcurframe
      (incr curno) 
      t ) ) )

#? (==> <avvideosource> get-frame-pts)
;; {<p>
;;   Returns the presentation time stamp of the current frame. The
;;   presentation time stamp is a real number expressed in seconds.
;;   Calling this function before the first call to <nextframe> gives the
;;   starting time of the movie.
;; }
(defmethod AvVideoSource get-frame-pts()
  curpts )

#? (==> <avvideosource> get-frame-number)
;; {<p>
;;   Returns the presentation frame number of the current frame.
;; }
(defmethod AvVideoSource get-frame-number()
  (when (not gotcurframe) (error "No current frame"))
  curno )

#? (==> <avvideosource> get-frame-gray)
;; {<p>
;;   Returns the gray level image associated with the current frame as a two
;;   dimensional matrix of unsigned bytes.
;; }
(defmethod AvVideoSource get-frame-gray()
  (when (not gotcurframe) (error "No current frame"))
  (let ((image (ubyte-matrix-nc frame_height frame_width)))
    #{{
        AVPicture pic;
        AVPicture *curframe = (AVPicture*)$curframe;
        pic.data[0] = IDX_PTR($image, unsigned char);
        pic.data[1] = pic.data[2] = 0;
        pic.linesize[0] = $image->mod[0];
        pic.linesize[1] = pic.linesize[2] = 0;
        if (img_convert(&pic, PIX_FMT_GRAY8, curframe, 
                        $frame_pix_fmt, $frame_width, $frame_height) < 0)
           run_time_error("FFmpeg image type conversion not supported");
    }#}
    image ) )

#? (==> <avvideosource> get-frame-rgba)
;; {<p>
;;   Returns the RBGA image associated with the current frame as a three
;;   dimensional matrix of unsigned bytes. The last dimentsion contains four
;;   elements: three color components (R, G, B) and one alpha channel (A).
;; }
(defmethod AvVideoSource get-frame-rgba()
  (when (not gotcurframe) (error "No current frame"))
  (let ((image (ubyte-matrix-nc frame_height frame_width 4)))
    #{{
        AVPicture pic;
        AVPicture *curframe = (AVPicture*)$curframe;
        pic.data[0] = IDX_PTR($image, unsigned char);
        pic.data[1] = pic.data[2] = 0;
        pic.linesize[0] = $image->mod[0];
        pic.linesize[1] = pic.linesize[2] = 0;
        if (img_convert(&pic, PIX_FMT_RGBA32, curframe, 
                        $frame_pix_fmt, $frame_width, $frame_height) < 0)
           run_time_error("FFmpeg image type conversion not supported");
    }#}
    ;; Stupid ffmpeg says RGBA but generates BGRA!
    (cinline-idx2loop image "unsigned char" "p" "i" "j"
       #{{ unsigned char r = p[0]; p[0]=p[2]; p[2]=r; }#} )
    image ) )

#? (==> <avvideosource> get-frame-yuv)
;; {<p>
;;   Returns the YUV image associated with the current frame as a three
;;   dimensional matrix of unsigned bytes. The last dimentsion contains
;;   three elements, one per color component (Y, U, V).
;; }
(defmethod AvVideoSource get-frame-yuv()
  (when (not gotcurframe) (error "No current frame"))
  (let ((image (ubyte-matrix-nc 3 frame_height frame_width)))
    #{{
        AVPicture pic;
        AVPicture *curframe = (AVPicture*)$curframe;
        pic.data[0] = IDX_PTR($image, unsigned char);
        pic.data[1] = pic.data[0] + $image->mod[0];
        pic.data[2] = pic.data[1] + $image->mod[0];
        pic.linesize[0] = $image->mod[1];
        pic.linesize[1] = $image->mod[1];
        pic.linesize[2] = $image->mod[1];
        if (img_convert(&pic, PIX_FMT_YUVJ444P, curframe, 
                        $frame_pix_fmt, $frame_width, $frame_height) < 0)
           run_time_error("FFmpeg image type conversion not supported");
    }#}
    (idx-transpose image '(1 2 0)) 
    image ) )



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; MAKE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(let ((dhc-make-lushflags (concat dhc-make-lushflags ffmpeg-cflags)))

  (each ((lib ffmpeg-libs))
    (libload-add-dependency lib) )

  (dhc-make-with-libs () ffmpeg-libs
	#{ 
	   #include <ffmpeg/avformat.h>
	   #include <ffmpeg/avcodec.h>
	   #define assert(x) do{if(!(x))\
              run_time_error("Assertion failed: " #x);}while(0)
           typedef struct AVPLElt_s {
             struct AVPLElt_s *prev;
             struct AVPLElt_s *next;
             AVPacket pkt;
           } AVPLElt;
	#}
        av-init
        (AvInputFile AvInputFile 
                     -destructor 
                     get-format-name
                     get-number-of-streams
                     get-stream-codec-type
                     get-stream-codec-id
                     get-start-time
                     get-duration
                     open pump )
        (AvPacketList AvPacketList
                      put pop peek -destructor )
        (AvAudioSource AvAudioSource 
                       process -destructor
                       get-codec-name get-codec-id 
                       get-start-time get-duration )
        (AvVideoSource AvVideoSource
                       process -destructor
                       get-codec-name get-codec-id 
                       get-start-time get-duration
                       get-frame-rate get-frame-period get-number-of-frames
		       nextframe
		       get-frame-pts get-frame-number
		       get-frame-gray get-frame-rgba get-frame-yuv )
        av-open-input-file 
        av-open-video-source 
        av-open-audio-source ) )
ffmpeg-config.lsh (text/plain, 4.2 KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: ffmpeg-config.lsh,v 1.4 2006/04/10 22:19:22 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar ffmpeg-libs ())
(defvar ffmpeg-cflags ())

(when (not ffmpeg-libs)
  (let ((soregex (concat ".*\\." (or (getconf "SOEXT") "so") "[0-9.]*"))
        (soonly t) )
    (let ((lib (find-shared-or-static-library "libavformat")))
      (if (and lib (filep lib))
          (progn 
            (setq ffmpeg-libs (nconc1 ffmpeg-libs lib))
            (setq soonly (and solonly (regex-match soregex lib))) )
        (printf "libavformat.so could not be found.\n")
        (printf "please make sure ffmpeg is installed.\n")
        (printf "Both the library and the development packages are needed.\n")
        (printf "(see %s for more details)\n" file-being-loaded)
        (error "cannot configure FFMPEG") ) )
    (let ((lib (find-shared-or-static-library "libavcodec")))
      (if (and lib (filep lib))
          (progn
            (setq ffmpeg-libs (nconc1 ffmpeg-libs lib))
            (setq soonly (and solonly (regex-match soregex lib))) )
        (printf "libavcodec.so could not be found.\n")
        (printf "please make sure ffmpeg is installed.\n")
        (printf "Both the library and the development packages are needed.\n")
        (printf "(see %s for more details)\n" file-being-loaded)
        (error "cannot configure FFMPEG") ) )
    (let ((lib (find-shared-or-static-library "libavutil")))
      (if (and lib (filep lib))
          (progn 
            (setq ffmpeg-libs (nconc1 ffmpeg-libs lib))
            (setq soonly (and solonly (regex-match soregex lib))) )
        (printf "libavutil.so could not be found.\n")
        (printf "please make sure ffmpeg is installed.\n")
        (printf "Both the library and the development packages are needed.\n")
        (printf "(see %s for more details)\n" file-being-loaded)
        (error "cannot configure FFMPEG") ) )
    (when (not soonly)
      (each ((libname '("libdts" "libz" "libogg" "libvorbisenc"
                        "libvorbis" "libtheora" "libgsm" 
                        "libdc1394" "libdc1394_control" "libraw1394"
                        ) ))
        (let ((lib (find-shared-or-static-library libname)))
          (when lib (setq ffmpeg-libs (nconc1 ffmpeg-libs lib))) ) ) ) ) )


(when (not ffmpeg-cflags)
  (setq ffmpeg-cflags "")
  (when (not (find-c-include "ffmpeg/avcodec.h"))
    (printf "ffmpeg/avcodec.h could not be found.\n")
    (printf "please make sure ffmpeg-devel is installed.\n")
    (printf "Both the library and the development packages are needed.\n")
    (printf "(see %s for more details)\n" file-being-loaded)
    (error "cannot configure FFMPEG") )
  (when (not (find-c-include "ffmpeg/avformat.h"))
    (printf "ffmpeg/avformat.h could not be found.\n")
    (printf "please make sure ffmpeg-devel is installed.\n")
    (printf "Both the library and the development packages are needed.\n")
    (printf "(see %s for more details)\n" file-being-loaded)
    (error "cannot configure FFMPEG") ) )
avsource.lsh (text/x-java, 4.9 KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: avsource.lsh,v 1.5 2006/04/10 17:03:46 laseray Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


#? ** Audio/Video Sources

#? * AVSource
;; {<p>
;;   Class <AVSource> is a common superclass for the <AudioSource> and
;;   <VideoSource> classes.
;; }
(defclass AVSource Object)
(defmethod AVSource AVSource() ())


#? (==> <avsource> process)
;; {<p>
;;   This internal function is called when new data is available for the
;;   source.
;; }
(defmethod AVSource process() t)



;;; ----------------------------------------

#? * AudioSource
;; {<see> AvAudioSource}
;;
;; {<p>
;;   The abstract class <AudioSource> defines generic methods 
;;   that enable access to a stream of audio data. The actual work is
;;   performed by related subclasses, such as <AvAudioSource>.
;;
;; {<b> WARNING}: Currently, this class is not usable.
;; }
(defclass AudioSource AVSource)

(defmethod AudioSource AudioSource() ())

#? (==> <audiosource> nextframe)
;; {<p>
;;   Method <nextframe> obtains the next segment of audio data. It returns
;;   <t> if new audio data is available, and returns <()> when it reaches the
;;   end of an audio stream.
;; }
;; {<p>
;;   After initialization of an audio source, this method must be called
;;   once in order to access the first segment of audio data.
;; }
(defmethod AudioSource nextframe() 
  () )


;;; ----------------------------------------

#? * VideoSource
;; {<see> AvAudioSource}
;;
;; {<p>
;;   The abstract class <VideoSource> defines generic methods to enable
;;   access to a stream of video data. The actual work is performed by
;;   related subclasses, such as <AvVideoSource>.
;; }
(defclass VideoSource AVSource)

(defmethod VideoSource VideoSource() ())

#? (==> <videosource> nextframe)
;; {<p>
;;   Method <nextframe> obtains the next video frame. It returns <t> if a
;;   new frame can be accessed using the frame access methods 
;;   <get-frame-xxx>, and returns <()> when reaching the end of the
;;   video stream.
;; }
;; {<p>
;;   After initialization of a video source, this method must be called once
;;   in order to access the first video frame.
;; }
(defmethod VideoSource nextframe() 
  () )

#? (==> <videosource> get-frame-pts)
;; {<p>
;;   Returns the presentation time stamp of the current frame. The
;;   presentation time stamp is a real number expressed in seconds.
;;   Calling this function before the first call to <nextframe>
;;   gives the starting time of a movie.
;; }
(defmethod VideoSource get-frame-pts()
  (to-real 0) )

#? (==> <videosource> get-frame-gray)
;; {<p>
;;   Returns the gray level image associated with the current frame
;;   as a two dimensional matrix of unsigned bytes.
;; }
(defmethod VideoSource get-frame-gray() 
  (error "not implemented")
  (ubyte-matrix 1 1))

#? (==> <videosource> get-frame-rgba)
;; {<p>
;;   Returns the RBGA image associated with the current frame as a three
;;   dimensional matrix of unsigned bytes. The last dimentsion contains four
;;   elements: three color components (R, G, B) and one alpha channel (A).
;; }
(defmethod VideoSource get-frame-rgba()
  (error "not implemented")
  (ubyte-matrix 1 1 4))

#? (==> <videosource> get-frame-yuv)
;; {<p>
;;   Returns the YUV image associated with the current frame as a three
;;   dimensional matrix of unsigned bytes. The last dimension contains
;;   three elements, one per color component (Y, U, V).
;; }
(defmethod VideoSource get-frame-yuv() 
  (error "not implemented")
  (ubyte-matrix 1 1 3))




;;; ----------------------------------------

(dhc-make ()
          (AVSource AVSource process)
	  (AudioSource AudioSource
		       nextframe )
	  (VideoSource VideoSource 
		       nextframe 
		       get-frame-pts
		       get-frame-gray 
		       get-frame-rgba 
		       get-frame-yuv ) )
play.lsh (text/plain, 3 KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: play.lsh,v 1.2 2004/02/04 21:16:57 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(libload "ffmpeg")

;;; ----------------------------------------

#? ** Lush Video Player
;; Function <av-play> provides a simple video player.

;;; ----------------------------------------

#? (av-play <filename> [<mag> [<speedup> [<osd>]]])
;; Play the video file <filename>.
;; Argument <mag> is a display maginification.
;; Argument <speedup> changes the play rate.
;; Setting argument <osd> to <t> prints the time stamp 
;; on the upper left corner of the window.

(de av-play(filename &optional (mag 1) (fast 1) (osd ()))
  (let* ((window ())
	 (image ())
	 (timer (new AvTimer))
	 (src (av-open-video-source filename))
	 (w :src:frame-width)
	 (h :src:frame-height)
	 (pts (==> src get-frame-pts)) 
	 (oldpts pts) )
    (new-window 0 0 (* mag w) (* mag h) "Lush video player")
    (when osd (when font-18 (font-18)) (color-rgb 0 0.7 0))
    (while (==> src nextframe)
      (setq pts (==> src get-frame-pts))
      (setq image (==> src get-frame-rgba))
      (==> timer sleep (/ (- pts oldpts) fast))
      (rgb-draw-matrix 0 0 image mag mag)
      (when osd (gprintf 5 20 "%08.3f" pts))
      (setq oldpts pts) )
    window ) )


;;; ----------------------------------------


(defclass AvTimer Object
  last )

(defmethod AvTimer AvTimer()
  (setq last (time)) )

(defmethod AvTimer sleep(delay)
  (if (functionp create-timer-absolute)
      ;; count delay since last time we woke up.
      (let* ((now (time))
	     (dat (max now (+ last delay))) )
	(when (> dat now)
	  (create-timer-absolute this dat)	  
	  (let ((h ()))
	    (while (<> (setq h (waitevent)) this)
	      (while (checkevent h) t) )
	    (checkevent this) ) )
	(setq last dat) )
    ;; otherwise use function <sleep>
    (sleep delay) )
  () )
ffmpeg-enum.lsh (text/plain, 17.1 KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: ffmpeg-enum.lsh,v 1.3 2006/04/10 21:44:22 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(libload "libc/constants")

;; Constants extracted from avcodec.h

(progn
  (defconstant "FFMPEG_VERSION_INT" 1033)
  (defconstant "FFMPEG_VERSION" "CVS")
  (defconstant "AV_TIME_BASE" 1000000)
  (defconstant "CODEC_ID_NONE" 0)
  (defconstant "CODEC_ID_MPEG1VIDEO" 1)
  (defconstant "CODEC_ID_MPEG2VIDEO" 2)
  (defconstant "CODEC_ID_MPEG2VIDEO_XVMC" 3)
  (defconstant "CODEC_ID_H261" 4)
  (defconstant "CODEC_ID_H263" 5)
  (defconstant "CODEC_ID_RV10" 6)
  (defconstant "CODEC_ID_RV20" 7)
  (defconstant "CODEC_ID_MJPEG" 8)
  (defconstant "CODEC_ID_MJPEGB" 9)
  (defconstant "CODEC_ID_LJPEG" 10)
  (defconstant "CODEC_ID_SP5X" 11)
  (defconstant "CODEC_ID_MPEG4" 12)
  (defconstant "CODEC_ID_RAWVIDEO" 13)
  (defconstant "CODEC_ID_MSMPEG4V1" 14)
  (defconstant "CODEC_ID_MSMPEG4V2" 15)
  (defconstant "CODEC_ID_MSMPEG4V3" 16)
  (defconstant "CODEC_ID_WMV1" 17)
  (defconstant "CODEC_ID_WMV2" 18)
  (defconstant "CODEC_ID_H263P" 19)
  (defconstant "CODEC_ID_H263I" 20)
  (defconstant "CODEC_ID_FLV1" 21)
  (defconstant "CODEC_ID_SVQ1" 22)
  (defconstant "CODEC_ID_SVQ3" 23)
  (defconstant "CODEC_ID_DVVIDEO" 24)
  (defconstant "CODEC_ID_HUFFYUV" 25)
  (defconstant "CODEC_ID_CYUV" 26)
  (defconstant "CODEC_ID_H264" 27)
  (defconstant "CODEC_ID_INDEO3" 28)
  (defconstant "CODEC_ID_VP3" 29)
  (defconstant "CODEC_ID_THEORA" 30)
  (defconstant "CODEC_ID_ASV1" 31)
  (defconstant "CODEC_ID_ASV2" 32)
  (defconstant "CODEC_ID_FFV1" 33)
  (defconstant "CODEC_ID_4XM" 34)
  (defconstant "CODEC_ID_VCR1" 35)
  (defconstant "CODEC_ID_CLJR" 36)
  (defconstant "CODEC_ID_MDEC" 37)
  (defconstant "CODEC_ID_ROQ" 38)
  (defconstant "CODEC_ID_INTERPLAY_VIDEO" 39)
  (defconstant "CODEC_ID_XAN_WC3" 40)
  (defconstant "CODEC_ID_XAN_WC4" 41)
  (defconstant "CODEC_ID_RPZA" 42)
  (defconstant "CODEC_ID_CINEPAK" 43)
  (defconstant "CODEC_ID_WS_VQA" 44)
  (defconstant "CODEC_ID_MSRLE" 45)
  (defconstant "CODEC_ID_MSVIDEO1" 46)
  (defconstant "CODEC_ID_IDCIN" 47)
  (defconstant "CODEC_ID_8BPS" 48)
  (defconstant "CODEC_ID_SMC" 49)
  (defconstant "CODEC_ID_FLIC" 50)
  (defconstant "CODEC_ID_TRUEMOTION1" 51)
  (defconstant "CODEC_ID_VMDVIDEO" 52)
  (defconstant "CODEC_ID_MSZH" 53)
  (defconstant "CODEC_ID_ZLIB" 54)
  (defconstant "CODEC_ID_QTRLE" 55)
  (defconstant "CODEC_ID_SNOW" 56)
  (defconstant "CODEC_ID_TSCC" 57)
  (defconstant "CODEC_ID_ULTI" 58)
  (defconstant "CODEC_ID_QDRAW" 59)
  (defconstant "CODEC_ID_VIXL" 60)
  (defconstant "CODEC_ID_QPEG" 61)
  (defconstant "CODEC_ID_XVID" 62)
  (defconstant "CODEC_ID_PNG" 63)
  (defconstant "CODEC_ID_PPM" 64)
  (defconstant "CODEC_ID_PBM" 65)
  (defconstant "CODEC_ID_PGM" 66)
  (defconstant "CODEC_ID_PGMYUV" 67)
  (defconstant "CODEC_ID_PAM" 68)
  (defconstant "CODEC_ID_FFVHUFF" 69)
  (defconstant "CODEC_ID_RV30" 70)
  (defconstant "CODEC_ID_RV40" 71)
  (defconstant "CODEC_ID_VC9" 72)
  (defconstant "CODEC_ID_WMV3" 73)
  (defconstant "CODEC_ID_LOCO" 74)
  (defconstant "CODEC_ID_WNV1" 75)
  (defconstant "CODEC_ID_AASC" 76)
  (defconstant "CODEC_ID_INDEO2" 77)
  (defconstant "CODEC_ID_FRAPS" 78)
  (defconstant "CODEC_ID_PCM_S16LE" 65536)
  (defconstant "CODEC_ID_PCM_S16BE" 65537)
  (defconstant "CODEC_ID_PCM_U16LE" 65538)
  (defconstant "CODEC_ID_PCM_U16BE" 65539)
  (defconstant "CODEC_ID_PCM_S8" 65540)
  (defconstant "CODEC_ID_PCM_U8" 65541)
  (defconstant "CODEC_ID_PCM_MULAW" 65542)
  (defconstant "CODEC_ID_PCM_ALAW" 65543)
  (defconstant "CODEC_ID_PCM_S32LE" 65544)
  (defconstant "CODEC_ID_PCM_S32BE" 65545)
  (defconstant "CODEC_ID_PCM_U32LE" 65546)
  (defconstant "CODEC_ID_PCM_U32BE" 65547)
  (defconstant "CODEC_ID_PCM_S24LE" 65548)
  (defconstant "CODEC_ID_PCM_S24BE" 65549)
  (defconstant "CODEC_ID_PCM_U24LE" 65550)
  (defconstant "CODEC_ID_PCM_U24BE" 65551)
  (defconstant "CODEC_ID_PCM_S24DAUD" 65552)
  (defconstant "CODEC_ID_ADPCM_IMA_QT" 69632)
  (defconstant "CODEC_ID_ADPCM_IMA_WAV" 69633)
  (defconstant "CODEC_ID_ADPCM_IMA_DK3" 69634)
  (defconstant "CODEC_ID_ADPCM_IMA_DK4" 69635)
  (defconstant "CODEC_ID_ADPCM_IMA_WS" 69636)
  (defconstant "CODEC_ID_ADPCM_IMA_SMJPEG" 69637)
  (defconstant "CODEC_ID_ADPCM_MS" 69638)
  (defconstant "CODEC_ID_ADPCM_4XM" 69639)
  (defconstant "CODEC_ID_ADPCM_XA" 69640)
  (defconstant "CODEC_ID_ADPCM_ADX" 69641)
  (defconstant "CODEC_ID_ADPCM_EA" 69642)
  (defconstant "CODEC_ID_ADPCM_G726" 69643)
  (defconstant "CODEC_ID_ADPCM_CT" 69644)
  (defconstant "CODEC_ID_ADPCM_SWF" 69645)
  (defconstant "CODEC_ID_ADPCM_YAMAHA" 69646)
  (defconstant "CODEC_ID_AMR_NB" 73728)
  (defconstant "CODEC_ID_AMR_WB" 73729)
  (defconstant "CODEC_ID_RA_144" 77824)
  (defconstant "CODEC_ID_RA_288" 77825)
  (defconstant "CODEC_ID_ROQ_DPCM" 81920)
  (defconstant "CODEC_ID_INTERPLAY_DPCM" 81921)
  (defconstant "CODEC_ID_XAN_DPCM" 81922)
  (defconstant "CODEC_ID_SOL_DPCM" 81923)
  (defconstant "CODEC_ID_MP2" 86016)
  (defconstant "CODEC_ID_MP3" 86017)
  (defconstant "CODEC_ID_AAC" 86018)
  (defconstant "CODEC_ID_MPEG4AAC" 86019)
  (defconstant "CODEC_ID_AC3" 86020)
  (defconstant "CODEC_ID_DTS" 86021)
  (defconstant "CODEC_ID_VORBIS" 86022)
  (defconstant "CODEC_ID_DVAUDIO" 86023)
  (defconstant "CODEC_ID_WMAV1" 86024)
  (defconstant "CODEC_ID_WMAV2" 86025)
  (defconstant "CODEC_ID_MACE3" 86026)
  (defconstant "CODEC_ID_MACE6" 86027)
  (defconstant "CODEC_ID_VMDAUDIO" 86028)
  (defconstant "CODEC_ID_SONIC" 86029)
  (defconstant "CODEC_ID_SONIC_LS" 86030)
  (defconstant "CODEC_ID_FLAC" 86031)
  (defconstant "CODEC_ID_MP3ADU" 86032)
  (defconstant "CODEC_ID_MP3ON4" 86033)
  (defconstant "CODEC_ID_SHORTEN" 86034)
  (defconstant "CODEC_ID_ALAC" 86035)
  (defconstant "CODEC_ID_WESTWOOD_SND1" 86036)
  (defconstant "CODEC_ID_GSM" 86037)
  (defconstant "CODEC_ID_OGGTHEORA" 90112)
  (defconstant "CODEC_ID_DVD_SUBTITLE" 94208)
  (defconstant "CODEC_ID_DVB_SUBTITLE" 94209)
  (defconstant "CODEC_ID_MPEG2TS" 131072)
  (defconstant "CODEC_ID_MP3LAME" 86017)
  (defconstant "CODEC_TYPE_UNKNOWN" -1)
  (defconstant "CODEC_TYPE_VIDEO" 0)
  (defconstant "CODEC_TYPE_AUDIO" 1)
  (defconstant "CODEC_TYPE_DATA" 2)
  (defconstant "CODEC_TYPE_SUBTITLE" 3)
  (defconstant "PIX_FMT_NONE" -1)
  (defconstant "PIX_FMT_YUV420P" 0)
  (defconstant "PIX_FMT_YUV422" 1)
  (defconstant "PIX_FMT_RGB24" 2)
  (defconstant "PIX_FMT_BGR24" 3)
  (defconstant "PIX_FMT_YUV422P" 4)
  (defconstant "PIX_FMT_YUV444P" 5)
  (defconstant "PIX_FMT_RGBA32" 6)
  (defconstant "PIX_FMT_YUV410P" 7)
  (defconstant "PIX_FMT_YUV411P" 8)
  (defconstant "PIX_FMT_RGB565" 9)
  (defconstant "PIX_FMT_RGB555" 10)
  (defconstant "PIX_FMT_GRAY8" 11)
  (defconstant "PIX_FMT_MONOWHITE" 12)
  (defconstant "PIX_FMT_MONOBLACK" 13)
  (defconstant "PIX_FMT_PAL8" 14)
  (defconstant "PIX_FMT_YUVJ420P" 15)
  (defconstant "PIX_FMT_YUVJ422P" 16)
  (defconstant "PIX_FMT_YUVJ444P" 17)
  (defconstant "PIX_FMT_XVMC_MPEG2_MC" 18)
  (defconstant "PIX_FMT_XVMC_MPEG2_IDCT" 19)
  (defconstant "PIX_FMT_UYVY422" 20)
  (defconstant "PIX_FMT_UYVY411" 21)
  (defconstant "PIX_FMT_NB" 22)
  (defconstant "SAMPLE_FMT_S16" 0)
  (defconstant "SAMPLE_FMT_S32" 1)
  (defconstant "SAMPLE_FMT_FLT" 2)
  (defconstant "SAMPLE_FMT_DBL" 3)
  (defconstant "AVCODEC_MAX_AUDIO_FRAME_SIZE" 131072)
  (defconstant "FF_INPUT_BUFFER_PADDING_SIZE" 8)
  (defconstant "FF_MIN_BUFFER_SIZE" 16384)
  (defconstant "ME_ZERO" 1)
  (defconstant "ME_FULL" 2)
  (defconstant "ME_LOG" 3)
  (defconstant "ME_PHODS" 4)
  (defconstant "ME_EPZS" 5)
  (defconstant "ME_X1" 6)
  (defconstant "AVDISCARD_NONE" -16)
  (defconstant "AVDISCARD_DEFAULT" 0)
  (defconstant "AVDISCARD_NONREF" 8)
  (defconstant "AVDISCARD_BIDIR" 16)
  (defconstant "AVDISCARD_NONKEY" 32)
  (defconstant "AVDISCARD_ALL" 48)
  (defconstant "FF_MAX_B_FRAMES" 8)
  (defconstant "CODEC_FLAG_QSCALE" 2)
  (defconstant "CODEC_FLAG_4MV" 4)
  (defconstant "CODEC_FLAG_QPEL" 16)
  (defconstant "CODEC_FLAG_GMC" 32)
  (defconstant "CODEC_FLAG_MV0" 64)
  (defconstant "CODEC_FLAG_PART" 128)
  (defconstant "CODEC_FLAG_INPUT_PRESERVED" 256)
  (defconstant "CODEC_FLAG_PASS1" 512)
  (defconstant "CODEC_FLAG_PASS2" 1024)
  (defconstant "CODEC_FLAG_EXTERN_HUFF" 4096)
  (defconstant "CODEC_FLAG_GRAY" 8192)
  (defconstant "CODEC_FLAG_EMU_EDGE" 16384)
  (defconstant "CODEC_FLAG_PSNR" 32768)
  (defconstant "CODEC_FLAG_TRUNCATED" 65536)
  (defconstant "CODEC_FLAG_NORMALIZE_AQP" 131072)
  (defconstant "CODEC_FLAG_INTERLACED_DCT" 262144)
  (defconstant "CODEC_FLAG_LOW_DELAY" 524288)
  (defconstant "CODEC_FLAG_ALT_SCAN" 1048576)
  (defconstant "CODEC_FLAG_TRELLIS_QUANT" 2097152)
  (defconstant "CODEC_FLAG_GLOBAL_HEADER" 4194304)
  (defconstant "CODEC_FLAG_BITEXACT" 8388608)
  (defconstant "CODEC_FLAG_H263P_AIC" 16777216)
  (defconstant "CODEC_FLAG_AC_PRED" 16777216)
  (defconstant "CODEC_FLAG_H263P_UMV" 33554432)
  (defconstant "CODEC_FLAG_CBP_RD" 67108864)
  (defconstant "CODEC_FLAG_QP_RD" 134217728)
  (defconstant "CODEC_FLAG_H263P_AIV" 8)
  (defconstant "CODEC_FLAG_OBMC" 1)
  (defconstant "CODEC_FLAG_LOOP_FILTER" 2048)
  (defconstant "CODEC_FLAG_H263P_SLICE_STRUCT" 268435456)
  (defconstant "CODEC_FLAG_INTERLACED_ME" 536870912)
  (defconstant "CODEC_FLAG_SVCD_SCAN_OFFSET" 1073741824)
  (defconstant "CODEC_FLAG_CLOSED_GOP" -2147483648)
  (defconstant "CODEC_FLAG2_FAST" 1)
  (defconstant "CODEC_FLAG2_STRICT_GOP" 2)
  (defconstant "CODEC_FLAG2_NO_OUTPUT" 4)
  (defconstant "CODEC_FLAG2_LOCAL_HEADER" 8)
  (defconstant "CODEC_CAP_DRAW_HORIZ_BAND" 1)
  (defconstant "CODEC_CAP_DR1" 2)
  (defconstant "CODEC_CAP_PARSE_ONLY" 4)
  (defconstant "CODEC_CAP_TRUNCATED" 8)
  (defconstant "CODEC_CAP_HWACCEL" 16)
  (defconstant "CODEC_CAP_DELAY" 32)
  (defconstant "MB_TYPE_INTRA4x4" 1)
  (defconstant "MB_TYPE_INTRA16x16" 2)
  (defconstant "MB_TYPE_INTRA_PCM" 4)
  (defconstant "MB_TYPE_16x16" 8)
  (defconstant "MB_TYPE_16x8" 16)
  (defconstant "MB_TYPE_8x16" 32)
  (defconstant "MB_TYPE_8x8" 64)
  (defconstant "MB_TYPE_INTERLACED" 128)
  (defconstant "MB_TYPE_DIRECT2" 256)
  (defconstant "MB_TYPE_ACPRED" 512)
  (defconstant "MB_TYPE_GMC" 1024)
  (defconstant "MB_TYPE_SKIP" 2048)
  (defconstant "MB_TYPE_P0L0" 4096)
  (defconstant "MB_TYPE_P1L0" 8192)
  (defconstant "MB_TYPE_P0L1" 16384)
  (defconstant "MB_TYPE_P1L1" 32768)
  (defconstant "MB_TYPE_QUANT" 65536)
  (defconstant "MB_TYPE_CBP" 131072)
  (defconstant "FF_QSCALE_TYPE_MPEG1" 0)
  (defconstant "FF_QSCALE_TYPE_MPEG2" 1)
  (defconstant "FF_BUFFER_TYPE_INTERNAL" 1)
  (defconstant "FF_BUFFER_TYPE_USER" 2)
  (defconstant "FF_BUFFER_TYPE_SHARED" 4)
  (defconstant "FF_BUFFER_TYPE_COPY" 8)
  (defconstant "FF_I_TYPE" 1)
  (defconstant "FF_P_TYPE" 2)
  (defconstant "FF_B_TYPE" 3)
  (defconstant "FF_S_TYPE" 4)
  (defconstant "FF_SI_TYPE" 5)
  (defconstant "FF_SP_TYPE" 6)
  (defconstant "FF_BUFFER_HINTS_VALID" 1)
  (defconstant "FF_BUFFER_HINTS_READABLE" 2)
  (defconstant "FF_BUFFER_HINTS_PRESERVE" 4)
  (defconstant "FF_BUFFER_HINTS_REUSABLE" 8)
  (defconstant "DEFAULT_FRAME_RATE_BASE" 1001000)
  (defconstant "FF_ASPECT_EXTENDED" 15)
  (defconstant "FF_BUG_AUTODETECT" 1)
  (defconstant "FF_BUG_OLD_MSMPEG4" 2)
  (defconstant "FF_BUG_XVID_ILACE" 4)
  (defconstant "FF_BUG_UMP4" 8)
  (defconstant "FF_BUG_NO_PADDING" 16)
  (defconstant "FF_BUG_AMV" 32)
  (defconstant "FF_BUG_AC_VLC" 0)
  (defconstant "FF_BUG_QPEL_CHROMA" 64)
  (defconstant "FF_BUG_STD_QPEL" 128)
  (defconstant "FF_BUG_QPEL_CHROMA2" 256)
  (defconstant "FF_BUG_DIRECT_BLOCKSIZE" 512)
  (defconstant "FF_BUG_EDGE" 1024)
  (defconstant "FF_BUG_HPEL_CHROMA" 2048)
  (defconstant "FF_BUG_DC_CLIP" 4096)
  (defconstant "FF_BUG_MS" 8192)
  (defconstant "FF_COMPLIANCE_VERY_STRICT" 2)
  (defconstant "FF_COMPLIANCE_STRICT" 1)
  (defconstant "FF_COMPLIANCE_NORMAL" 0)
  (defconstant "FF_ER_CAREFUL" 1)
  (defconstant "FF_ER_COMPLIANT" 2)
  (defconstant "FF_ER_AGGRESSIVE" 3)
  (defconstant "FF_ER_VERY_AGGRESSIVE" 4)
  (defconstant "FF_DCT_AUTO" 0)
  (defconstant "FF_DCT_FASTINT" 1)
  (defconstant "FF_DCT_INT" 2)
  (defconstant "FF_DCT_MMX" 3)
  (defconstant "FF_DCT_MLIB" 4)
  (defconstant "FF_DCT_ALTIVEC" 5)
  (defconstant "FF_DCT_FAAN" 6)
  (defconstant "FF_IDCT_AUTO" 0)
  (defconstant "FF_IDCT_INT" 1)
  (defconstant "FF_IDCT_SIMPLE" 2)
  (defconstant "FF_IDCT_SIMPLEMMX" 3)
  (defconstant "FF_IDCT_LIBMPEG2MMX" 4)
  (defconstant "FF_IDCT_PS2" 5)
  (defconstant "FF_IDCT_MLIB" 6)
  (defconstant "FF_IDCT_ARM" 7)
  (defconstant "FF_IDCT_ALTIVEC" 8)
  (defconstant "FF_IDCT_SH4" 9)
  (defconstant "FF_IDCT_SIMPLEARM" 10)
  (defconstant "FF_IDCT_H264" 11)
  (defconstant "FF_IDCT_VP3" 12)
  (defconstant "FF_IDCT_IPP" 13)
  (defconstant "FF_IDCT_XVIDMMX" 14)
  (defconstant "FF_EC_GUESS_MVS" 1)
  (defconstant "FF_EC_DEBLOCK" 2)
  (defconstant "FF_MM_FORCE" -2147483648)
  (defconstant "FF_MM_MMX" 1)
  (defconstant "FF_MM_3DNOW" 4)
  (defconstant "FF_MM_MMXEXT" 2)
  (defconstant "FF_MM_SSE" 8)
  (defconstant "FF_MM_SSE2" 16)
  (defconstant "FF_MM_3DNOWEXT" 32)
  (defconstant "FF_MM_IWMMXT" 256)
  (defconstant "FF_PRED_LEFT" 0)
  (defconstant "FF_PRED_PLANE" 1)
  (defconstant "FF_PRED_MEDIAN" 2)
  (defconstant "FF_DEBUG_PICT_INFO" 1)
  (defconstant "FF_DEBUG_RC" 2)
  (defconstant "FF_DEBUG_BITSTREAM" 4)
  (defconstant "FF_DEBUG_MB_TYPE" 8)
  (defconstant "FF_DEBUG_QP" 16)
  (defconstant "FF_DEBUG_MV" 32)
  (defconstant "FF_DEBUG_DCT_COEFF" 64)
  (defconstant "FF_DEBUG_SKIP" 128)
  (defconstant "FF_DEBUG_STARTCODE" 256)
  (defconstant "FF_DEBUG_PTS" 512)
  (defconstant "FF_DEBUG_ER" 1024)
  (defconstant "FF_DEBUG_MMCO" 2048)
  (defconstant "FF_DEBUG_BUGS" 4096)
  (defconstant "FF_DEBUG_VIS_QP" 8192)
  (defconstant "FF_DEBUG_VIS_MB_TYPE" 16384)
  (defconstant "FF_DEBUG_VIS_MV_P_FOR" 1)
  (defconstant "FF_DEBUG_VIS_MV_B_FOR" 2)
  (defconstant "FF_DEBUG_VIS_MV_B_BACK" 4)
  (defconstant "FF_CMP_SAD" 0)
  (defconstant "FF_CMP_SSE" 1)
  (defconstant "FF_CMP_SATD" 2)
  (defconstant "FF_CMP_DCT" 3)
  (defconstant "FF_CMP_PSNR" 4)
  (defconstant "FF_CMP_BIT" 5)
  (defconstant "FF_CMP_RD" 6)
  (defconstant "FF_CMP_ZERO" 7)
  (defconstant "FF_CMP_VSAD" 8)
  (defconstant "FF_CMP_VSSE" 9)
  (defconstant "FF_CMP_NSSE" 10)
  (defconstant "FF_CMP_W53" 11)
  (defconstant "FF_CMP_W97" 12)
  (defconstant "FF_CMP_DCTMAX" 13)
  (defconstant "FF_CMP_CHROMA" 256)
  (defconstant "FF_DTG_AFD_SAME" 8)
  (defconstant "FF_DTG_AFD_4_3" 9)
  (defconstant "FF_DTG_AFD_16_9" 10)
  (defconstant "FF_DTG_AFD_14_9" 11)
  (defconstant "FF_DTG_AFD_4_3_SP_14_9" 13)
  (defconstant "FF_DTG_AFD_16_9_SP_14_9" 14)
  (defconstant "FF_DTG_AFD_SP_4_3" 15)
  (defconstant "FF_DEFAULT_QUANT_BIAS" 999999)
  (defconstant "FF_LAMBDA_SHIFT" 7)
  (defconstant "FF_QP2LAMBDA" 118)
  (defconstant "FF_CODER_TYPE_VLC" 0)
  (defconstant "FF_CODER_TYPE_AC" 1)
  (defconstant "SLICE_FLAG_CODED_ORDER" 1)
  (defconstant "SLICE_FLAG_ALLOW_FIELD" 2)
  (defconstant "SLICE_FLAG_ALLOW_PLANE" 4)
  (defconstant "FF_MB_DECISION_SIMPLE" 0)
  (defconstant "FF_MB_DECISION_BITS" 1)
  (defconstant "FF_MB_DECISION_RD" 2)
  (defconstant "FF_AA_AUTO" 0)
  (defconstant "FF_AA_FASTINT" 1)
  (defconstant "FF_AA_INT" 2)
  (defconstant "FF_AA_FLOAT" 3)
  (defconstant "AVPALETTE_SIZE" 1024)
  (defconstant "AVPALETTE_COUNT" 256)
  (defconstant "FF_LOSS_RESOLUTION" 1)
  (defconstant "FF_LOSS_DEPTH" 2)
  (defconstant "FF_LOSS_COLORSPACE" 4)
  (defconstant "FF_LOSS_ALPHA" 8)
  (defconstant "FF_LOSS_COLORQUANT" 16)
  (defconstant "FF_LOSS_CHROMA" 32)
  (defconstant "FF_ALPHA_TRANSP" 1)
  (defconstant "FF_ALPHA_SEMI_TRANSP" 2)
  (defconstant "AV_PARSER_PTS_NB" 4)
  (defconstant "PARSER_FLAG_COMPLETE_FRAMES" 1)
  (defconstant "AV_LOG_ERROR" 0)
  (defconstant "AV_LOG_INFO" 1)
  (defconstant "AV_LOG_DEBUG" 2)
  t )


;; Constants extracted from avformat.h

(progn
  (defconstant "PKT_FLAG_KEY" 1)
  (defconstant "AVPROBE_SCORE_MAX" 100)
  (defconstant "AVFMT_NOFILE" 1)
  (defconstant "AVFMT_NEEDNUMBER" 2)
  (defconstant "AVFMT_SHOW_IDS" 8)
  (defconstant "AVFMT_RAWPICTURE" 32)
  (defconstant "AVFMT_GLOBALHEADER" 64)
  (defconstant "AVINDEX_KEYFRAME" 1)
  (defconstant "AVFMTCTX_NOHEADER" 1)
  (defconstant "MAX_STREAMS" 20)
  (defconstant "AVFMT_INFINITEOUTPUTLOOP" 0)
  (defconstant "AVFMT_FLAG_GENPTS" 1)
  (defconstant "AVIMAGE_INTERLEAVED" 1)
  (defconstant "AVSEEK_FLAG_BACKWARD" 1)
  (defconstant "AVSEEK_FLAG_BYTE" 2)
  (defconstant "AVSEEK_FLAG_ANY" 4)
  (defconstant "FFM_PACKET_SIZE" 4096)
  t )