2002-12-16 01:49:39 +00:00
|
|
|
/*qt video encoder using win32 libs
|
|
|
|
released under gnu gpl
|
|
|
|
(C)Sascha Sommer */
|
|
|
|
|
|
|
|
#define MAX_IDSIZE 0x6F
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
2006-11-29 15:02:45 +00:00
|
|
|
#include "libavutil/common.h"
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2002-12-16 01:49:39 +00:00
|
|
|
|
2003-02-15 17:45:10 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2003-02-02 02:42:59 +00:00
|
|
|
#include "ldt_keeper.h"
|
|
|
|
#endif
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "loader/qtx/qtxsdk/components.h"
|
2002-12-16 01:49:39 +00:00
|
|
|
#include "wine/windef.h"
|
|
|
|
|
|
|
|
#include "codec-cfg.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
|
2006-12-18 21:03:59 +00:00
|
|
|
#include "stream.h"
|
2002-12-27 22:43:20 +00:00
|
|
|
#include "muxer.h"
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
|
|
|
|
HMODULE WINAPI LoadLibraryA(LPCSTR);
|
|
|
|
FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
|
|
|
|
int WINAPI FreeLibrary(HMODULE);
|
2005-01-17 20:57:48 +00:00
|
|
|
static HINSTANCE qtime_qts; //handle to preloaded quicktime.qts
|
2002-12-16 01:49:39 +00:00
|
|
|
static HMODULE handler;
|
|
|
|
|
|
|
|
static OSErr (*FindCodec)(CodecType cType,
|
|
|
|
CodecComponent specCodec,
|
|
|
|
CompressorComponent * compressor,
|
|
|
|
DecompressorComponent * decompressor);
|
|
|
|
static OSErr (*InitializeQTML)(long flags);
|
|
|
|
static PixMapHandle (*GetGWorldPixMap)(GWorldPtr offscreenGWorld);
|
|
|
|
static OSErr (*QTNewGWorldFromPtr)(GWorldPtr *gw,
|
|
|
|
OSType pixelFormat,
|
|
|
|
const Rect *boundsRect,
|
|
|
|
CTabHandle cTable,
|
|
|
|
/*GDHandle*/void* aGDevice, /*unused anyway*/
|
|
|
|
GWorldFlags flags,
|
|
|
|
void *baseAddr,
|
|
|
|
long rowBytes);
|
|
|
|
static OSErr (*NewHandleClear)(Size byteCount);
|
|
|
|
static OSErr (*CompressSequenceBegin) (
|
|
|
|
ImageSequence *seqID,
|
|
|
|
PixMapHandle src,
|
|
|
|
PixMapHandle prev,
|
|
|
|
const Rect *srcRect,
|
|
|
|
const Rect *prevRect,
|
|
|
|
short colorDepth,
|
|
|
|
CodecType cType,
|
|
|
|
CompressorComponent codec,
|
|
|
|
CodecQ spatialQuality,
|
|
|
|
CodecQ temporalQuality,
|
|
|
|
long keyFrameRate,
|
|
|
|
CTabHandle ctable,
|
|
|
|
CodecFlags flags,
|
|
|
|
ImageDescriptionHandle desc );
|
|
|
|
|
|
|
|
static OSErr (*CompressSequenceFrame) (
|
|
|
|
ImageSequence seqID,
|
|
|
|
PixMapHandle src,
|
|
|
|
const Rect *srcRect,
|
|
|
|
CodecFlags flags,
|
|
|
|
Ptr data,
|
|
|
|
long *dataSize,
|
|
|
|
UInt8 *similarity,
|
|
|
|
ICMCompletionProcRecordPtr asyncCompletionProc );
|
|
|
|
|
|
|
|
static OSErr (*GetMaxCompressionSize)(PixMapHandle src,
|
|
|
|
const Rect *srcRect,
|
|
|
|
short colorDepth,
|
|
|
|
CodecQ quality,
|
|
|
|
CodecType cType,
|
|
|
|
CompressorComponent codec,
|
|
|
|
long *size );
|
|
|
|
static OSErr (*CDSequenceEnd)( ImageSequence seqID );
|
|
|
|
static Component (*FindNextComponent)(Component prev,ComponentDescription* desc);
|
|
|
|
static long (*CountComponents)(ComponentDescription* desc);
|
|
|
|
static OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//static int format=mmioFOURCC('S','V','Q','1');
|
|
|
|
static int format=mmioFOURCC('S','V','Q','3');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//static void *frame_in; //input frame
|
|
|
|
static void *frame_prev; //previous frame
|
|
|
|
static void *frame_comp; //compressed frame
|
|
|
|
static GWorldPtr frame_GWorld_in = NULL;//a GWorld is some kind of description for a drawing environment
|
|
|
|
static GWorldPtr frame_GWorld_prev = NULL;
|
|
|
|
static Rect FrameRect;
|
|
|
|
|
|
|
|
static CompressorComponent compressor;
|
|
|
|
static DecompressorComponent decompressor;
|
|
|
|
static ImageDescriptionHandle desc;
|
|
|
|
static ImageSequence seq;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
2002-12-27 22:43:20 +00:00
|
|
|
muxer_stream_t* mux;
|
2002-12-16 01:49:39 +00:00
|
|
|
//dv_encoder_t* enc;
|
|
|
|
|
|
|
|
};
|
|
|
|
#define mux_v (vf->priv->mux)
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int config(struct vf_instance_s* vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
|
|
|
OSErr cres;
|
|
|
|
ComponentDescription cdesc;
|
|
|
|
mux_v->bih->biWidth=width;
|
|
|
|
mux_v->bih->biHeight=height;
|
|
|
|
mux_v->bih->biSizeImage=width*height*2;
|
2004-03-24 15:16:36 +00:00
|
|
|
mux_v->aspect = (float)d_width/d_height;
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-27 12:43:30 +00:00
|
|
|
memset(&cdesc,0,sizeof(cdesc));
|
2002-12-16 01:49:39 +00:00
|
|
|
cdesc.componentType= (((unsigned char)'i')<<24)|
|
|
|
|
(((unsigned char)'m')<<16)|
|
|
|
|
(((unsigned char)'c')<<8)|
|
|
|
|
(((unsigned char)'o'));
|
|
|
|
|
|
|
|
cdesc.componentSubType=bswap_32(format);
|
|
|
|
cdesc.componentManufacturer=0;
|
|
|
|
cdesc.componentFlags=0;
|
|
|
|
cdesc.componentFlagsMask=0;
|
|
|
|
|
|
|
|
|
2006-01-12 20:04:36 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Count = %ld\n",CountComponents(&cdesc));
|
2002-12-16 01:49:39 +00:00
|
|
|
compressor=FindNextComponent(NULL,&cdesc);
|
|
|
|
if(!compressor){
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"Cannot find requested component\n");
|
2002-12-16 01:49:39 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2006-01-12 20:04:36 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Found it! ID = %p\n",compressor);
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
// cres= FindCodec (fourcc,anyCodec,&compressor,&decompressor );
|
|
|
|
// printf("FindCodec returned:%i compressor: 0x%X decompressor: 0x%X\n",cres&0xFFFF,compressor,decompressor);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vf_instance_s* vf, int request, void* data){
|
|
|
|
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
2005-04-18 15:52:38 +00:00
|
|
|
if(fmt==IMGFMT_YUY2) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
2002-12-16 01:49:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int codec_inited = 0;
|
|
|
|
|
2006-03-21 21:26:42 +00:00
|
|
|
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
OSErr cres;
|
|
|
|
long framesizemax;
|
2002-12-21 20:42:40 +00:00
|
|
|
UInt8 similarity=0;
|
2002-12-16 01:49:39 +00:00
|
|
|
long compressedsize;
|
2004-08-28 20:59:49 +00:00
|
|
|
OSType in_format=kYUVSPixelFormat;
|
2002-12-16 01:49:39 +00:00
|
|
|
int width = mpi->width;
|
|
|
|
int height = mpi->height;
|
|
|
|
int stride = width*2;
|
|
|
|
if(!codec_inited){
|
|
|
|
FrameRect.top=0;
|
|
|
|
FrameRect.left=0;
|
|
|
|
FrameRect.right=width;
|
|
|
|
FrameRect.bottom=height;
|
|
|
|
cres = QTNewGWorldFromPtr(
|
|
|
|
&frame_GWorld_in,
|
|
|
|
in_format,
|
|
|
|
&FrameRect,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
mpi->planes[0],
|
|
|
|
stride);
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
|
2002-12-16 01:49:39 +00:00
|
|
|
//dunno what todo about this
|
|
|
|
frame_prev = malloc(stride * height);
|
|
|
|
cres = QTNewGWorldFromPtr(
|
|
|
|
&frame_GWorld_prev,
|
|
|
|
in_format,
|
|
|
|
&FrameRect,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
frame_prev,
|
|
|
|
stride);
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"height:%i width:%i stride:%i\n",height,width,stride);
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
|
2002-12-16 01:49:39 +00:00
|
|
|
cres= GetMaxCompressionSize (
|
|
|
|
GetGWorldPixMap(frame_GWorld_in),
|
|
|
|
&FrameRect,
|
|
|
|
24,
|
|
|
|
codecNormalQuality,
|
|
|
|
bswap_32(format),
|
|
|
|
compressor,
|
|
|
|
&framesizemax );
|
2006-01-12 20:04:36 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"GetMaxCompressionSize returned:%i : MaxSize:%li\n",cres&0xFFFF,framesizemax);
|
2002-12-16 01:49:39 +00:00
|
|
|
frame_comp=malloc(framesizemax);
|
2002-12-21 20:42:40 +00:00
|
|
|
|
2002-12-16 01:49:39 +00:00
|
|
|
desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored
|
|
|
|
(*desc)->idSize=MAX_IDSIZE;
|
|
|
|
|
|
|
|
cres= CompressSequenceBegin (
|
|
|
|
&seq,
|
|
|
|
GetGWorldPixMap( frame_GWorld_in),
|
|
|
|
GetGWorldPixMap( frame_GWorld_prev),
|
|
|
|
&FrameRect,
|
|
|
|
&FrameRect,
|
|
|
|
24, // color depth
|
|
|
|
bswap_32(format), // fourcc
|
|
|
|
compressor, // codec component
|
|
|
|
codecNormalQuality, //codecNormalQuality,
|
|
|
|
codecMaxQuality, //codecNormalQuality,
|
2002-12-21 20:42:40 +00:00
|
|
|
10*30, // keyframe rate
|
2002-12-16 01:49:39 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
desc);
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceBegin returned:%i\n",cres&0xFFFF);
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Sequence ID:%i\n",seq);
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
dump_ImageDescription(*desc);
|
|
|
|
codec_inited++;
|
|
|
|
}
|
|
|
|
cres = CompressSequenceFrame (
|
|
|
|
seq,
|
|
|
|
GetGWorldPixMap(frame_GWorld_in),
|
|
|
|
&FrameRect,
|
|
|
|
0,
|
|
|
|
(char*)mux_v->buffer,
|
|
|
|
&compressedsize,
|
|
|
|
&similarity,
|
|
|
|
0);
|
|
|
|
|
2004-04-13 15:04:25 +00:00
|
|
|
if(cres&0xFFFF)mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceFrame returned:%i\n",cres&0xFFFF);
|
2002-12-16 01:49:39 +00:00
|
|
|
#if 0
|
2002-12-21 20:42:40 +00:00
|
|
|
printf("Size %i->%i \n",stride*height,compressedsize);
|
2002-12-16 01:49:39 +00:00
|
|
|
printf("Ratio: %i:1\n",(stride*height)/compressedsize);
|
|
|
|
#endif
|
2006-01-26 19:32:07 +00:00
|
|
|
muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
|
2002-12-16 01:49:39 +00:00
|
|
|
|
|
|
|
if(((*desc)->idSize)>MAX_IDSIZE){
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize));
|
2002-12-16 01:49:39 +00:00
|
|
|
} else {
|
|
|
|
// according to QT docs, imagedescription may be changed while encoding
|
|
|
|
// a frame (even its size may (and does!) change!)
|
|
|
|
memcpy(mux_v->bih+1,*desc,(*desc)->idSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int vf_open(vf_instance_t *vf, char* args){
|
|
|
|
OSErr cres = 1;
|
|
|
|
vf->config=config;
|
2005-03-01 20:21:58 +00:00
|
|
|
vf->default_caps=VFCAP_CONSTANT;
|
2002-12-16 01:49:39 +00:00
|
|
|
vf->control=control;
|
|
|
|
vf->query_format=query_format;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
|
|
memset(vf->priv,0,sizeof(struct vf_priv_s));
|
2002-12-27 22:43:20 +00:00
|
|
|
vf->priv->mux=(muxer_stream_t*)args;
|
2002-12-16 01:49:39 +00:00
|
|
|
|
2005-01-20 22:53:37 +00:00
|
|
|
mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+MAX_IDSIZE);
|
2002-12-16 01:49:39 +00:00
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+MAX_IDSIZE;
|
|
|
|
mux_v->bih->biWidth=0;
|
|
|
|
mux_v->bih->biHeight=0;
|
|
|
|
mux_v->bih->biCompression=format;
|
|
|
|
mux_v->bih->biPlanes=1;
|
|
|
|
mux_v->bih->biBitCount=24;
|
|
|
|
|
|
|
|
|
2003-02-15 17:45:10 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2002-12-16 01:49:39 +00:00
|
|
|
Setup_LDT_Keeper();
|
2003-02-15 17:45:10 +00:00
|
|
|
#endif
|
2005-01-17 20:57:48 +00:00
|
|
|
//preload quicktime.qts to avoid the problems caused by the hardcoded path inside the dll
|
|
|
|
qtime_qts = LoadLibraryA("QuickTime.qts");
|
|
|
|
if(!qtime_qts){
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load QuickTime.qts\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-16 01:49:39 +00:00
|
|
|
handler = LoadLibraryA("qtmlClient.dll");
|
2004-04-13 15:04:25 +00:00
|
|
|
if(!handler){
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load qtmlClient.dll\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-03 12:26:17 +00:00
|
|
|
InitializeQTML = (OSErr (*)(long))GetProcAddress(handler, "InitializeQTML");
|
|
|
|
GetGWorldPixMap = (PixMapHandle (*)(GWorldPtr))GetProcAddress(handler, "GetGWorldPixMap");
|
|
|
|
QTNewGWorldFromPtr = (OSErr(*)(GWorldPtr *,OSType,const Rect *,CTabHandle,void*,GWorldFlags,void *,long))GetProcAddress(handler, "QTNewGWorldFromPtr");
|
|
|
|
NewHandleClear = (OSErr(*)(Size))GetProcAddress(handler, "NewHandleClear");
|
|
|
|
FindCodec = (OSErr (*)(CodecType,CodecComponent,CompressorComponent *,DecompressorComponent *))GetProcAddress(handler,"FindCodec");
|
|
|
|
CompressSequenceBegin = (OSErr(*)(ImageSequence *,PixMapHandle,PixMapHandle,const Rect *,const Rect *,short,CodecType,CompressorComponent,CodecQ,CodecQ,long,CTabHandle,CodecFlags,ImageDescriptionHandle))GetProcAddress(handler,"CompressSequenceBegin");
|
|
|
|
CompressSequenceFrame = (OSErr(*)(ImageSequence,PixMapHandle,const Rect *,CodecFlags,Ptr,long *,UInt8 *,ICMCompletionProcRecordPtr))GetProcAddress(handler,"CompressSequenceFrame");
|
|
|
|
GetMaxCompressionSize = (OSErr(*)(PixMapHandle,const Rect *,short,CodecQ,CodecType,CompressorComponent,long *))GetProcAddress(handler,"GetMaxCompressionSize");
|
|
|
|
CDSequenceEnd = (OSErr (*)(ImageSequence))GetProcAddress(handler,"CDSequenceEnd");
|
|
|
|
FindNextComponent = (Component (*)(Component,ComponentDescription*))GetProcAddress(handler, "FindNextComponent");
|
|
|
|
CountComponents = (long (*)(ComponentDescription*))GetProcAddress(handler, "CountComponents");
|
|
|
|
GetComponentInfo = (OSErr (*)(Component,ComponentDescription*,Handle,Handle,Handle))GetProcAddress(handler, "GetComponentInfo");
|
2002-12-16 01:49:39 +00:00
|
|
|
if(!InitializeQTML ||!CompressSequenceBegin){
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"invalid qt DLL!\n");
|
2002-12-16 01:49:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//printf("%i,%i,%i\n",mmioFOURCC('S','V','Q','1'),'SVQ1',bswap_32(mmioFOURCC('S','V','Q','1')));
|
|
|
|
cres=InitializeQTML(6+16);
|
2004-04-13 15:04:25 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_DBG2,"InitializeQTML returned %i\n",cres);
|
2002-12-16 01:49:39 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t ve_info_qtvideo = {
|
|
|
|
"Quicktime video encoder using win32 DLLs",
|
|
|
|
"qtvideo",
|
|
|
|
"Sascha Sommer",
|
|
|
|
"for internal use by mencoder",
|
|
|
|
vf_open
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|