Новичок
Профиль
Группа: Участник
Сообщений: 8
Регистрация: 17.11.2004
Репутация: нет Всего: нет
|
Если тебе это поможет в качестве примера.... Модули найдешь по ссылке выше. Код |
unit DSInfo;
interface uses Windows, SysUtils, DirectShow9, ActiveX, MMSystem, FourCC, DSUtil;
procedure GetFileData(FileName : String; Var fAllInfo : String; Var Count:Integer; Var vW:Integer; Var vH:Integer); function GetFileLength(FileName : String):Longint; implementation
procedure FreeMediaType(medType : PAMMEDIATYPE); begin If medType.cbFormat <> 0 then CoTaskMemFree(medType.pbFormat); If medType.pUnk <> nil then medType.pUnk := nil; FillChar(medType^,Sizeof(TAMMEDIATYPE),0); end;
function GetMediaTypeDescriptionX(MediaType: TAMMediaType; MediaLength: Double; var W:Integer; var H:Integer): string; var MediaFPS : Double;
function GetChannels(Channels: Cardinal): string; begin case Channels of 1 : result := 'Mono'; 2 : result := 'Stereo'; else result := IntToStr(Channels)+' Channels'; end; end;
function ConvertFloat(Num: Double): string; begin if Frac(Num) = 0 then result := FloatToStrF(Num,ffFixed,15,0) else result := FloatToStrF(Num,ffFixed,15,3); end;
begin // major types result := ''; if IsEqualGUID(MediaType.majortype,MEDIATYPE_AnalogAudio) then result := result+'AnalogAudio' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_AnalogVideo) then result := result+'Analogvideo' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Audio) then result := result+'Audio' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_AUXLine21Data) then result := result+'AUXLine21Data' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_File) then result := result+'File' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Interleaved) then result := result+'Interleaved' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_LMRT) then result := result+'LMRT' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Midi) then result := result+'Midi' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_MPEG2_PES) then result := result+'MPEG2_PES' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_ScriptCommand) then result := result+'ScriptCommand' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Stream) then result := result+'Stream' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Text) then result := result+'Text' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Timecode) then result := result+'Timecode' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_URL_STREAM) then result := result+'URL_STREAM' else if IsEqualGUID(MediaType.majortype,MEDIATYPE_Video) then result := result+'Video' else result := result+'Unknown';
/////////////////////////////////////////// { result := result + '|Sub Type: '; if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_CLPL) then result := result+'CLPL' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_YUYV) then result := result+'YUYV' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_IYUV) then result := result+'IYUV' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_YVU9) then result := result+'YVU9' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Y411) then result := result+'Y411' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Y41P) then result := result+'Y41P' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_YUY2) then result := result+'YUY2' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_YVYU) then result := result+'YVYU' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_UYVY) then result := result+'UYVY' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Y211) then result := result+'Y211' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_YV12) then result := result+'YV12' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_CLJR) then result := result+'CLJR' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_IF09) then result := result+'IF09' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_CPLA) then result := result+'CPLA' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MJPG) then result := result+'MJPG' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_TVMJ) then result := result+'TVMJ' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_WAKE) then result := result+'WAKE' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_CFCC) then result := result+'CFCC' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_IJPG) then result := result+'IJPG' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Plum) then result := result+'Plum' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVCS) then result := result+'DVCS' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVSD) then result := result+'DVSD' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MDVF) then result := result+'MDVF' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB1) then result := result+'RGB1' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB4) then result := result+'RGB4' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB8) then result := result+'RGB8' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB565) then result := result+'RGB565' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB555) then result := result+'RGB555' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB24) then result := result+'RGB24' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB32) then result := result+'RGB32' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_ARGB32) then result := result+'ARGB32' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Overlay) then result := result+'Overlay' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1Packet) then result := result+'MPEG1Packet' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1Payload) then result := result+'MPEG1Payload' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1AudioPayload) then result := result+'MPEG1AudioPayload' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1System) then result := result+'MPEG1System' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1VideoCD) then result := result+'MPEG1VideoCD' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1Video) then result := result+'MPEG1Video' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG1Audio) then result := result+'MPEG1Audio' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Avi) then result := result+'Avi' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Asf) then result := result+'Asf' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_QTMovie) then result := result+'QTMovie' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_QTRpza) then result := result+'QTRpza' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_QTSmc) then result := result+'QTSmc' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_QTRle) then result := result+'QTRle' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_QTJpeg) then result := result+'QTJpeg' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_PCMAudio_Obsolete) then result := result+'PCMAudio_Obsolete' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_PCM) then result := result+'PCM' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_WAVE) then result := result+'WAVE' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AU) then result := result+'AU' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AIFF) then result := result+'AIFF' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_dvsd_) then result := result+'dvsd_' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_dvhd) then result := result+'dvhd' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_dvsl) then result := result+'dvsl' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Line21_BytePair) then result := result+'Line21_BytePair' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Line21_GOPPacket) then result := result+'Line21_GOPPacket' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_Line21_VBIRawData) then result := result+'Line21_VBIRawData' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DRM_Audio) then result := result+'DRM_Audio' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_IEEE_FLOAT) then result := result+'IEEE_FLOAT' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DOLBY_AC3_SPDIF) then result := result+'DOLBY_AC3_SPDIF' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RAW_SPORT) then result := result+'RAW_SPORT' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_SPDIF_TAG_241h) then result := result+'SPDIF_TAG_241h' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DssVideo) then result := result+'DssVideo' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DssAudio) then result := result+'DssAudio' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_VPVideo) then result := result+'VPVideo' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_VPVBI) then result := result+'VPVBI' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_NTSC_M) then result := result+'AnalogVideo_NTSC_M' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_B) then result := result+'AnalogVideo_PAL_B' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_D) then result := result+'AnalogVideo_PAL_D' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_G) then result := result+'AnalogVideo_PAL_G' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_H) then result := result+'AnalogVideo_PAL_H' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_I) then result := result+'AnalogVideo_PAL_I' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_M) then result := result+'AnalogVideo_PAL_M' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_N) then result := result+'AnalogVideo_PAL_N' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_PAL_N_COMBO) then result := result+'AnalogVideo_PAL_N_COMBO' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_B) then result := result+'AnalogVideo_SECAM_B' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_D) then result := result+'AnalogVideo_SECAM_D' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_G) then result := result+'AnalogVideo_SECAM_G' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_H) then result := result+'AnalogVideo_SECAM_H' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_K) then result := result+'AnalogVideo_SECAM_K' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_K1) then result := result+'AnalogVideo_SECAM_K1' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_AnalogVideo_SECAM_L) then result := result+'AnalogVideo_SECAM_L' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG2_VIDEO) then result := result+'MPEG2_VIDEO' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG2_PROGRAM) then result := result+'MPEG2_PROGRAM' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG2_TRANSPORT) then result := result+'MPEG2_TRANSPORT' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MPEG2_AUDIO) then result := result+'MPEG2_AUDIO' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DOLBY_AC3) then result := result+'DOLBY_AC3' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVD_SUBPICTURE) then result := result+'DVD_SUBPICTURE' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVD_LPCM_AUDIO) then result := result+'DVD_LPCM_AUDIO' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DTS) then result := result+'DTS' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_SDDS) then result := result+'SDDS' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVD_NAVIGATION_PCI) then result := result+'PCI' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVD_NAVIGATION_DSI) then result := result+'DSI' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DVD_NAVIGATION_PROVIDER) then result := result+'PROVIDER' else // if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_MP42) then result := result+'MS-MPEG4' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_DIVX) then result := result+'DIVX' else if IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_VOXWARE) then result := result+'VOXWARE_MetaSound' else result := result+'UnKnown '; } ///////////////////////////////////////
// format result := result+ ' '+CaptList.Values['MFORMAT']+': '; if IsEqualGUID(MediaType.formattype,FORMAT_VideoInfo) then begin if ((MediaType.cbFormat > 0) and assigned(MediaType.pbFormat)) then begin if PVideoInfoHeader(MediaType.pbFormat)^.AvgTimePerFrame > 0 then dsMediaFPS := 10000000 / PVideoInfoHeader(MediaType.pbFormat)^.AvgTimePerFrame else dsMediaFPS := 0;
with PVideoInfoHeader(MediaType.pbFormat)^.bmiHeader do begin result := result + format('%d x %d, %d Bits, %s Frames, %s Frames/Sec, %s', [biWidth, biHeight, biBitCount, FloatToStrF(dsMediaFPS * MediaLength, ffFixed, 15, 0), ConvertFloat(dsMediaFPS), GetVideoFourCC(biCompression)]); W:=biWidth; H:=biHeight; end; end; end else begin if IsEqualGUID(MediaType.formattype,FORMAT_VideoInfo2) then begin if ((MediaType.cbFormat > 0) and assigned(MediaType.pbFormat)) then begin if PVideoInfoHeader2(MediaType.pbFormat)^.AvgTimePerFrame > 0 then dsMediaFPS := 10000000 / PVideoInfoHeader2(MediaType.pbFormat)^.AvgTimePerFrame else dsMediaFPS := 0;
with PVideoInfoHeader2(MediaType.pbFormat)^.bmiHeader do begin result := result + format('%d x %d, %d Bits, %s Frames, %s Frames/Sec, %s', [biWidth, biHeight, biBitCount, FloatToStrF(dsMediaFPS * MediaLength, ffFixed, 15, 0), ConvertFloat(dsMediaFPS), GetVideoFourCC(biCompression)]); W:=biWidth; H:=biHeight; end; end; end else begin if IsEqualGUID(MediaType.formattype,FORMAT_WaveFormatEx) then begin if ((MediaType.cbFormat > 0) and assigned(MediaType.pbFormat)) then begin with PWaveFormatEx(MediaType.pbFormat)^ do result := result + format('%s, %s kBit/s, %s kHz, %s', [GetAudioTwoCC(wFormatTag), ConvertFloat(nAvgBytesPerSec*8/1000), ConvertFloat(nSamplesPerSec / 1000), GetChannels(nChannels)]); end; end else begin if IsEqualGUID(MediaType.formattype,FORMAT_MPEGVideo) then begin if ((MediaType.cbFormat > 0) and assigned(MediaType.pbFormat)) then begin if PMPEG1VIDEOINFO(MediaType.pbFormat)^.hdr.AvgTimePerFrame > 0 then dsMediaFPS := 10000000 / PMPEG1VIDEOINFO(MediaType.pbFormat)^.hdr.AvgTimePerFrame else dsMediaFPS := 0;
with PMPEG1VIDEOINFO(MediaType.pbFormat)^.hdr.bmiHeader do begin result := result + format('%d x %d, %d Bits, %s Frames, %s Frames/Sec, %s', [biWidth, biHeight, biBitCount, FloatToStrF(dsMediaFPS * MediaLength, ffFixed, 15, 0), ConvertFloat(dsMediaFPS), GetVideoFourCC(biCompression)]); W:=biWidth; H:=biHeight; end; end; end else begin if IsEqualGUID(MediaType.formattype,FORMAT_MPEG2Video) then begin if ((MediaType.cbFormat > 0) and assigned(MediaType.pbFormat)) then begin if PMPEG2VIDEOINFO(MediaType.pbFormat)^.hdr.AvgTimePerFrame > 0 then dsMediaFPS := 10000000 / PMPEG2VIDEOINFO(MediaType.pbFormat)^.hdr.AvgTimePerFrame else dsMediaFPS := 0;
with PMPEG2VIDEOINFO(MediaType.pbFormat)^.hdr.bmiHeader do begin result := result + format('%d x %d, %d Bits, %s Frames, %s Frames/Sec, %s', [biWidth, biHeight, biBitCount, FloatToStrF(dsMediaFPS * MediaLength, ffFixed, 15, 0), ConvertFloat(dsMediaFPS), GetVideoFourCC(biCompression)]); W:=biWidth; H:=biHeight; end; end; end else begin // todo if IsEqualGUID(MediaType.formattype,FORMAT_DvInfo) then result := result+'DvInfo' else if IsEqualGUID(MediaType.formattype,FORMAT_MPEGStreams) then result := result+'MPEGStreams' else if IsEqualGUID(MediaType.formattype,FORMAT_DolbyAC3) then result := result+'DolbyAC3' else if IsEqualGUID(MediaType.formattype,FORMAT_MPEG2Audio) then result := result+'MPEG2Audio' else if IsEqualGUID(MediaType.formattype,FORMAT_DVD_LPCMAudio) then result := result+'DVD_LPCMAudio' else result := result+'Unknown'; end; end; end; end; end; end;
procedure GetFileData(FileName : String; Var fAllInfo : String; Var Count:Integer; Var vW:Integer; Var vH:Integer); Var dsMediaDet : IMediaDet; dsMediaStreams : Integer; dsMediaLength : Double; dsMediaType : TAMMEDIATYPE; dsMediaFRate : Double; dsSec : Single; dsMin : Integer; fDuration : String; I : Integer; hr : HRESULT; begin vW:=0; vH:=0; Count :=1; fAllInfo := ''; hr := CoCreateInstance(CLSID_MediaDet, nil, CLSCTX_INPROC, IID_IMediaDet, dsMediaDet); if hr <> S_OK then begin // Showmessage('Media Detector not available'); exit; end;
hr := dsMediaDet.put_Filename(FileName); if hr <> S_OK then begin dsMediaDet := nil; exit; end; dsMediaDet.get_OutputStreams(dsMediaStreams); if dsMediaStreams > 0 then Begin dsMediaDet.put_CurrentStream(0); if dsMediaDet.get_StreamLength(dsMediaLength) = S_OK then Begin if dsMediaLength > 60 then begin dsMin := Trunc(dsMediaLength / 60); dsSec := dsMediaLength - (dsMin * 60); fDuration := IntToStr(dsMin)+ ' min. '+FloatToStrF(dsSec,ffFixed,15,3)+' sec.'; end else fDuration := FloatToStrF(dsMediaLength,ffFixed,15,3)+' sec.'; end else begin dsMediaLength := 0; fDuration := 'Unknown'; end;
fAllInfo := CaptList.Values['MLENGTH']+': '+fDuration+'|';
for i := 0 to dsMediaStreams -1 do begin Count:=Count+1; ////////////////////////////// dsMediaDet.put_CurrentStream(i); dsMediaDet.get_StreamMediaType(dsMediaType); dsMediaDet.get_FrameRate(dsMediaFRate); fAllinfo := fAllInfo + GetMediaTypeDescriptionX(dsMediaType, dsMediaLength, vW, vH) + '|'; FreeMediaType(@dsMediaType); end; end; dsMediaDet := nil; end;
function GetFileLength(FileName : String):Longint; Var dsMediaDet : IMediaDet; dsMediaStreams : Integer; dsMediaLength : Double; // dsMediaType : TAMMEDIATYPE; // dsMediaFRate : Double;
hr : HRESULT; begin result:=0; hr := CoCreateInstance(CLSID_MediaDet, nil, CLSCTX_INPROC, IID_IMediaDet, dsMediaDet); if hr <> S_OK then begin // Showmessage('Media Detector not available'); exit; end;
hr := dsMediaDet.put_Filename(FileName); if hr <> S_OK then begin dsMediaDet := nil; exit; end;
dsMediaDet.get_OutputStreams(dsMediaStreams); if dsMediaStreams > 0 then Begin dsMediaDet.put_CurrentStream(0); if dsMediaDet.get_StreamLength(dsMediaLength) = S_OK then result:=Round(dsMediaLength); end; dsMediaDet := nil; end;
end.
|
|