PDA

View Full Version : Use of libavcodec


CyberShaman
18th September 2005, 16:54
Does anyone have information on how to use libavcodec library? I'm using Delphi so i'm pretty lost with this one. It seems that there are no headers to delphi and very little info to any other languages.

What i would like to do is load an video file. Then if possible have a trigger which retreives next frame from the video. At this point i would use my own renderer to display the frame, and after that call the "NextFrameTrigger" again, creating continuous loop.

Any ideas? What exported function is needed? Structures?

CyberShaman
19th September 2005, 15:51
No ideas?

Is there an extra simple videoplayer using libavcodec, which source i could study. I tried to study mplayer's source but...

neuron2
19th September 2005, 17:10
http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html

and his update:

http://www.inb.uni-luebeck.de/~boehme/libavcodec_update.html

Don't miss the small demo program that he links.

Inc
20th September 2005, 14:03
@ CyberShaman

Im not shure but I think you would have to port the avcodec.h and avformat.h headers to delphi for a proper usage of avcodec/avformat api in delphi as structures and declarations out of these c++ headers are needed.

movax
20th September 2005, 19:31
asif.dll seems to be the Delphi AVS interface to use iirc.

CyberShaman
21st September 2005, 09:59
asif.dll seems to be the Delphi AVS interface to use iirc.Hmm. I have heard about AviSynth years ago but never botherd to find out what it's all about. Well yesterday i looked into AVS, i must say there are some very cool stuff happening out there. Unfortunately AviSynth can't use libavcodec, or can it?

I'm building a videoplayer and would like to use libavcodec because it decodes almost any codec. Also by using libavcodec it's not necessary to use DirectShow, which is allways a positive thing.

Im not shure but I think you would have to port the avcodec.h and avformat.h headers to delphi for a proper usage of avcodec/avformat api in delphi as structures and declarations out of these c++ headers are needed.Yes, i am aware of that nasty fact.
Unfortunately my knowledge of c++ is almost null. I manage to translate all the basic stuff but that's all. Here's where i run into trouble:

Code from avcodec.h
typedef struct AVCodec {
const char *name;
enum CodecType type;
enum CodecID id;
int priv_data_size;
int (*init)(AVCodecContext *);
int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
int (*close)(AVCodecContext *);
int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
uint8_t *buf, int buf_size);
int capabilities;
void *dummy; // FIXME remove next time we break binary compatibility
struct AVCodec *next;
void (*flush)(AVCodecContext *);
const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
const enum PixelFormat *pix_fmts; ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
} AVCodec;

I translate it like so
CodecType = (
CODEC_TYPE_UNKNOWN = -1,
CODEC_TYPE_VIDEO,
CODEC_TYPE_AUDIO );

CodecID = (
CODEC_ID_NONE,
CODEC_ID_MPEG1VIDEO,
CODEC_ID_MPEG2VIDEO_XVMC,
all the rest ... );


AVCodecContext = record
name : Char;
ctype : CodecType;
id : CodecID;
priv_data_size: Integer;

// Here my problems start.


Maybe someone knows how to translate that. :confused:

Myrsloik
21st September 2005, 13:13
My guess would be something like this:


{$Z4} //required to get the same size as c enums

PAVCodecContext = Pointer;

AVRational = record
num:Integer;
den:Integer;
end;

TAVRationalArray = array[0..high(word)] of AVRational;
PAVRationalArray = ^TAVRationalArray;

TPixelFormatArray = array[0..high(word)] of PixelFormat;
PPixelFormatArray = ^TPixelFormatArray;

TAVCodecInit = function(a:PAVCodecContext):integer;
TAVCodecEncode = function(a:PAVCodecContext; buf:PByteArray; buf_size:integer; data:pointer):integer;
TAVCodecClose = function(a:PAVCodecContext):integer;
TAVCodecDecode = function(a:PAVCodecContext; outdata:pointer; outdata_size:integer):integer;
TAVCodecFlush = procedure(a:PAVCodecContext);

PAVCodec = ^AVCodec;

AVCodec = record
name:pchar;
ctype:CodecType;
id:CodecID;
priv_data_size:integer;
init:TAVCodecInit;
encode:TAVCodecEncode;
close:TAVCodecClose;
decode:TAVCodecDecode;
capabilities:integer;
dummy:pointer;
next:PAVCodec;
flush:TAVCodecFlush;
supported_framerates:PAVRationalArray;
pix_fmts:PPixelFormatArray;
end;


But I've probably missed a * or two somewhere. If there's any interest or if I get bored enough I might attempt to do the whole thing.

CyberShaman
22nd September 2005, 11:15
If there's any interest or if I get bored enough I might attempt to do the whole thing.

Thanks for your reply. Here's my current progress if you are interested or bored.
I've marked all unfinished/unknown code with {TODO}.
http://www.cubicreality.com/delphi/avcodec/avcodec.pas

I'm currently studying the JEDI tutorial to find out more about the subject.

shark37
25th September 2005, 00:07
@ CyberShaman

This site might be helpful IMHO
http://www.progdigy.com

Inc
25th September 2005, 00:47
Also by using libavcodec it's not necessary to use DirectShow, which is allways a positive thing.

I'm currently studying the JEDI tutorial to find out more about the subject.

IIRC The Dspack from Jedi does exactly what you want to avoid by using libavcodec --> usage of Dshow, so libavcodec would be out of the list.

CyberShaman
25th September 2005, 12:10
Also by using libavcodec it's not necessary to use DirectShow, which is allways a positive thing.Well there was a hint of irony in that sentence ;) .
I know my way around DirectShow so no need for DSPack.

I guess what i'm trying to achieve is an ultimate video player for windows.
-Flexibility of Graphedit (DirectShow)
-Stability and lightness of MPC (DirectShow).
-Support for different codecs like in mplayer (libAVCodec + DirectShow).
-Highly optimized renderers for tv output (Own code).

It seems that the translation of avcodec headers is just too difficult for my level of knowlegde. So i'm thinking that maybe i should learn c++ just enough to be able to create a small dll which wraps libavcodec in few simple functions. :confused:

dvdzealot
16th March 2006, 02:02
why not try to write a wapping dll with c++.
Then you'll use it in delphi freely.

Inc
16th March 2006, 09:30
@CyberShaman

A wrapping dll could be a solution. Just look in the LibAvCodec Folder for apiexample.c and in the ffmpeg Folder for outputexample.c.
Also have a look in here:
http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html
http://www.inb.uni-luebeck.de/~boehme/libavcodec_update.html

Keep in mind that within Libavcodec the codecs XViD, X264, FAAC, FAAD, Mp3Lame, Lame which can be included separately when compilng ffmpeg, these codecs are also wrapped by libavcodec! So when compiling a "all including" wrapper dll you have to link to libxvidcore.a, libx264.a, LibFaac.a etc

dimzon
16th March 2006, 09:41
http://sourceforge.net/projects/c2pas
http://manpages.debian.net/cgi-bin/display_man.cgi?id=07302dbf1d8c462566661d624c04f8bf&format=plain
http://gd.tuwien.ac.at/www.freepascal.org/tools/h2pas.html
http://linux.com.hk/penguin/man/1/h2pas.html
http://www.programmersheaven.com/zone24/cat583/3968.htm
http://www5b.biglobe.ne.jp/~k-kumaki/tool/h2p.html