Здравствуйте. Есть модуль: | Код | unit cl_AVITag; // -----------------------------------------------------------------------------
interface
uses Classes, SysUtils, sys_Files;
type vtAVIErrorCode = ( ecNone, // None ecOpenError, // Error while opening file occurs ecReadError, // Error while reading file occurs ecRIFFError, // File does not match RIFF format ecSizeError, // File size is smaller then supposed in RIFF header ecAVIError, // File does not match AVI format ecStructureError, // Error in AVI structure detected ecCloseError, // Error while closing file occurs ecWriteError // Error while writing file occurs );
{ vtAVITag }
vtAVITag = class(TObject) private { Private declarations } FFileName : WideString; FErrorCode : vtAVIErrorCode; INAM_Title : String; IART_Director : String; ICOP_Copyright : String; IPRD_Product : String; ICRD_CreationDate : String; IGNR_Genre : String; ISGN_SecondGenre : String; ISBJ_Subject : String; IKEY_Keywords : String; ICMT_Comment : String; IWRI_Writer : String; IPRO_Producer : String; IPDS_ProductionDesigner : String; IEDT_Editor : String; ICDS_CostumeDesigner : String; IMUS_Composer : String; ISTD_ProductionStudio : String; IDST_Distributor : String; ICNT_Country : String; ILNG_Language : String; IRTD_Rating : String; IPRT_Part : String; IFRM_PartFrom : String; ISTR_Starring : String; ISFT_Software : String; ITCH_Encoder : String; IDIT_DigitationDate : String; IWEB_InternetAddress : String; ISRF_SourceForm : String; IMED_Medium : String; ISRC_Source : String; IARL_ArchivalLocation : String; ICMS_ComissionedBy : String; IENG_Enginer : String; ICRP_Croped : String; ISHP_Sharpness : String; IDIM_Dimensions : String; ILGT_Lightness : String; IDPI_Resolution : String; IPLT_Palette : String; public { Public declarations } constructor Create(const FileName: WideString); function ReadTag: Boolean; procedure ClearTag; function TagAvailable: Boolean; property ErrorCode : vtAVIErrorCode read FErrorCode; property Title : String read INAM_Title write INAM_Title; property Director : String read IART_Director write IART_Director; property Copyright : String read ICOP_Copyright write ICOP_Copyright; property Product : String read IPRD_Product write IPRD_Product; property CreationDate : String read ICRD_CreationDate write ICRD_CreationDate; property Genre : String read IGNR_Genre write IGNR_Genre; property SecondGenre : String read ISGN_SecondGenre write ISGN_SecondGenre; property Subject : String read ISBJ_Subject write ISBJ_Subject; property Keywords : String read IKEY_Keywords write IKEY_Keywords; property Comment : String read ICMT_Comment write ICMT_Comment; property Writer : String read IWRI_Writer write IWRI_Writer; property Producer : String read IPRO_Producer write IPRO_Producer; property ProductionDesigner : String read IPDS_ProductionDesigner write IPDS_ProductionDesigner; property Editor : String read IEDT_Editor write IEDT_Editor; property CostumeDesigner : String read ICDS_CostumeDesigner write ICDS_CostumeDesigner; property Composer : String read IMUS_Composer write IMUS_Composer; property ProductionStudio : String read ISTD_ProductionStudio write ISTD_ProductionStudio; property Distributor : String read IDST_Distributor write IDST_Distributor; property Country : String read ICNT_Country write ICNT_Country; property Language : String read ILNG_Language write ILNG_Language; property Rating : String read IRTD_Rating write IRTD_Rating; property Part : String read IPRT_Part write IPRT_Part; property PartFrom : String read IFRM_PartFrom write IFRM_PartFrom; property Starring : String read ISTR_Starring write ISTR_Starring; property Software : String read ISFT_Software write ISFT_Software; property Encoder : String read ITCH_Encoder write ITCH_Encoder; property DigitationDate : String read IDIT_DigitationDate write IDIT_DigitationDate; property InternetAddress : String read IWEB_InternetAddress write IWEB_InternetAddress; property SourceForm : String read ISRF_SourceForm write ISRF_SourceForm; property Medium : String read IMED_Medium write IMED_Medium; property Source : String read ISRC_Source write ISRC_Source; property ArchivalLocation : String read IARL_ArchivalLocation write IARL_ArchivalLocation; property ComissionedBy : String read ICMS_ComissionedBy write ICMS_ComissionedBy; property Enginer : String read IENG_Enginer write IENG_Enginer; property Croped : String read ICRP_Croped write ICRP_Croped; property Sharpness : String read ISHP_Sharpness write ISHP_Sharpness; property Dimensions : String read IDIM_Dimensions write IDIM_Dimensions; property Lightness : String read ILGT_Lightness write ILGT_Lightness; property Resolution : String read IDPI_Resolution write IDPI_Resolution; property Palette : String read IPLT_Palette write IPLT_Palette; end;
// -----------------------------------------------------------------------------
implementation
// -----------------------------------------------------------------------------
{ vtAVITag }
// -----------------------------------------------------------------------------
constructor vtAVITag.Create(const FileName: WideString); begin FFileName := FileName; ClearTag; ReadTag; end;
// -----------------------------------------------------------------------------
function vtAVITag.ReadTag: Boolean; type TList_Info = record // structure for remember enclosed RIFF lists Value : LongInt; // old value (needed for reading info) Counter : LongInt; // counter of bytes read end;
TFCCCode = array[1..4] of Char;
TRiff_Info = record Name : TFCCCode; Length : LongInt; end;
const TAG_Size = 131072;
var USFile : vtFile; // source tag file List_Name : TFCCCode; // name of current list Buffer : array[0..TAG_Size] of Char; // read buffer Riff_Info : TRiff_Info; // variable for reading RIFF elements Riff_Length : LongInt; // length of AVI file from RIFF header Zero, x : LongInt; List_Deep : LongInt; Lists : array[1..10] of TList_Info; // information about enclosed RIFF lists ErrorFound : Boolean;
procedure Recognize_TAG; // routine for recognizing tags var x : LongInt; Temp : String; // buffer for tag content begin if Riff_Info.Length > TAG_Size then Exit; // skip big tags Temp := ''; for x := 0 to Riff_Info.Length-1 do Temp := Temp + Buffer[x]; // get tag content
Temp := Trim(Temp);
with Riff_Info do if Name = 'INAM' then INAM_Title := Temp else if Name = 'IWRI' then IWRI_Writer := Temp else if Name = 'IART' then IART_Director := Temp else if Name = 'IPRD' then IPRD_Product := Temp else if Name = 'ICRD' then ICRD_CreationDate := Temp else if Name = 'ISTD' then ISTD_ProductionStudio := Temp else if Name = 'ISTR' then ISTR_Starring := Temp else if Name = 'IGNR' then IGNR_Genre := Temp else if Name = 'ISBJ' then ISBJ_Subject := Temp else if Name = 'IRTD' then IRTD_Rating := Temp else if Name = 'ICOP' then ICOP_Copyright := Temp else if Name = 'ILNG' then ILNG_Language := Temp else if Name = 'IKEY' then IKEY_Keywords := Temp else if Name = 'IPRT' then IPRT_Part := Temp else if Name = 'IFRM' then IFRM_PartFrom := Temp else if Name = 'ICMT' then ICMT_Comment := Temp else if Name = 'ISFT' then ISFT_Software := Temp else if Name = 'IDIT' then IDIT_DigitationDate := Temp else if Name = 'IWEB' then IWEB_InternetAddress := Temp else if Name = 'ICMS' then ICMS_ComissionedBy := Temp else if Name = 'IENG' then IENG_Enginer := Temp else if Name = 'ITCH' then ITCH_Encoder := Temp else if Name = 'ISRF' then ISRF_SourceForm := Temp else if Name = 'IMED' then IMED_Medium := Temp else if Name = 'ISRC' then ISRC_Source := Temp else if Name = 'IARL' then IARL_ArchivalLocation := Temp else if Name = 'ICRP' then ICRP_Croped := Temp else if Name = 'ISHP' then ISHP_Sharpness := Temp else if Name = 'IDIM' then IDIM_Dimensions := Temp else if Name = 'ILGT' then ILGT_Lightness := Temp else if Name = 'IDPI' then IDPI_Resolution := Temp else if Name = 'IPLT' then IPLT_Palette := Temp else if Name = 'IMUS' then IMUS_Composer := Temp else if Name = 'ICDS' then ICDS_CostumeDesigner := Temp else if Name = 'ICNT' then ICNT_Country := Temp else if Name = 'IDST' then IDST_Distributor := Temp else if Name = 'IEDT' then IEDT_Editor := Temp else if Name = 'ISGN' then ISGN_SecondGenre := Temp else if Name = 'IPRO' then IPRO_Producer := Temp else if Name = 'IPDS' then IPDS_ProductionDesigner := Temp; end;
begin Result := False; ClearTag;
// try to assign/open file USFile := vtFile.Create(FFileName, fmOpenRead or fmShareDenyWrite); try if not USFile.Ready then // assigned/opened? begin FErrorCode := ecOpenError; // if failed - set error code and go out Exit; end;
// read RIFF header if not USFile.Read(Riff_Info, 8) then begin FErrorCode := ecReadError; // if failed - set error code and go out Exit; end;
// the name should be 'RIFF' if Riff_Info.Name <> 'RIFF' then begin FErrorCode := ecRIFFError; // if failed - set error code and go out Exit; end;
// compute correct RIFF length Riff_Length := Riff_Info.Length + 8; if Riff_Length > USFile.Size then begin // the length of file should be not shorter then RIFF length FErrorCode := ecSizeError; // if failed - set error code and go out Exit; end;
// read riffinfo if not USFile.Read(Riff_Info, 4) then begin FErrorCode := ecReadError; // if failed - set error code and go out Exit; end;
// AVI file should have the corresponding mark if Riff_Info.Name <> 'AVI ' then begin FErrorCode := ecAVIError; // if failed - set error code and go out Exit; end;
// Now we have normal AVI ErrorFound := False; List_Deep := 1; // zero level of enclosed lists with Lists[List_Deep] do // make new counter begin Value := Riff_Info.Length; // remember list length Counter := 4; // initialize counter. Why "4" not "0"? We read 'AVI ', but list starts before this name. end;
while not (USFile.EOF or (USFile.Position >= Riff_Length)) do // end analyze structure on file end begin if not USFile.Read(Riff_Info, 8) then // read RIFF info ErrorFound := True;
for x := 1 to List_Deep do Inc(Lists[x].Counter, 8); // increase all the read counters
if (Riff_Info.Length mod 2 = 1) then Inc(Riff_Info.Length); // align length to 2
if Riff_Info.Name = 'LIST' then begin // new LIST found if not USFile.Read(List_Name, 4) then // read list name ErrorFound := True;
for x := 1 to List_Deep do Inc(Lists[x].Counter, 4); // increase all the read counters
Inc(List_Deep); // increase list deep with Lists[List_Deep] do begin // make new counter Value := Riff_Info.Length; // remember list length Counter := 4; // initialize counter of bytes read end;
if (List_Name = 'movi') then begin // skip LIST movi - usual the biggest list in AVI file (video/audio data) if not USFile.Seek(USFile.Position + Riff_Info.Length - 4) then // skip list ErrorFound := True;
for x := 1 to List_Deep do Inc(Lists[x].Counter, Riff_Info.Length - 4); // increase all the read counters end; end; // end of work with new LIST
if Riff_Info.Name = 'JUNK' then begin // just for space section if not USFile.Seek(USFile.Position + Riff_Info.Length) then // skip section ErrorFound := True;
for x := 1 to List_Deep do Inc(Lists[x].Counter, Riff_Info.Length); // increase all the read counters end;
if (Riff_Info.Name <> 'JUNK') and (Riff_Info.Name <> 'LIST') then begin if (Riff_Info.Length <= USFile.Size-USFile.Position+1) and (Riff_Info.Length > 0) then begin // normal tag if (Riff_Info.Length > TAG_Size) then USFile.Seek(USFile.Position + Riff_Info.Length) // skip section else USFile.Read(Buffer, Riff_Info.Length); // read tag content
for x := 1 to List_Deep do Inc(Lists[x].Counter, Riff_Info.Length); // increase all the read counters
if USFile.ErrorCode <> 0 then ErrorFound := True else Recognize_TAG; end else ErrorFound := True; // if incorrect tag - structure error end;
Zero := List_Deep; for x := 1 to Zero do // check the counters if Lists[x].Counter = Lists[x].Value then Dec(List_Deep); // decrease list deep end;
if ErrorFound then begin FErrorCode := ecStructureError; Exit; end;
FErrorCode := ecNone; // if we are here - no errors occure Result := True; finally USFile.Free; end; end;
// -----------------------------------------------------------------------------
procedure vtAVITag.ClearTag; begin INAM_Title := ''; IART_Director := ''; ICOP_Copyright := ''; IPRD_Product := ''; ICRD_CreationDate := ''; IGNR_Genre := ''; ISGN_SecondGenre := ''; ISBJ_Subject := ''; IKEY_Keywords := ''; ICMT_Comment := ''; IWRI_Writer := ''; IPRO_Producer := ''; IPDS_ProductionDesigner := ''; IEDT_Editor := ''; ICDS_CostumeDesigner := ''; IMUS_Composer := ''; ISTD_ProductionStudio := ''; IDST_Distributor := ''; ICNT_Country := ''; ILNG_Language := ''; IRTD_Rating := ''; IPRT_Part := ''; IFRM_PartFrom := ''; ISTR_Starring := ''; ISFT_Software := ''; ITCH_Encoder := ''; IDIT_DigitationDate := ''; IWEB_InternetAddress := ''; ISRF_SourceForm := ''; IMED_Medium := ''; ISRC_Source := ''; IARL_ArchivalLocation := ''; ICMS_ComissionedBy := ''; IENG_Enginer := ''; ICRP_Croped := ''; ISHP_Sharpness := ''; IDIM_Dimensions := ''; ILGT_Lightness := ''; IDPI_Resolution := ''; IPLT_Palette := ''; end;
// -----------------------------------------------------------------------------
function vtAVITag.TagAvailable: Boolean; begin if (INAM_Title <> '') or (IART_Director <> '') or (ICOP_Copyright <> '') or (IPRD_Product <> '') or (ICRD_CreationDate <> '') or (IGNR_Genre <> '') or (ISGN_SecondGenre <> '') or (ISBJ_Subject <> '') or (IKEY_Keywords <> '') or (ICMT_Comment <> '') or (IWRI_Writer <> '') or (IPRO_Producer <> '') or (IPDS_ProductionDesigner <> '') or (IEDT_Editor <> '') or (ICDS_CostumeDesigner <> '') or (IMUS_Composer <> '') or (ISTD_ProductionStudio <> '') or (IDST_Distributor <> '') or (ICNT_Country <> '') or (ILNG_Language <> '') or (IRTD_Rating <> '') or (IPRT_Part <> '') or (IFRM_PartFrom <> '') or (ISTR_Starring <> '') or (ISFT_Software <> '') or (ITCH_Encoder <> '') or (IDIT_DigitationDate <> '') or (IWEB_InternetAddress <> '') or (ISRF_SourceForm <> '') or (IMED_Medium <> '') or (ISRC_Source <> '') or (IARL_ArchivalLocation <> '') or (ICMS_ComissionedBy <> '') or (IENG_Enginer <> '') or (ICRP_Croped <> '') or (ISHP_Sharpness <> '') or (IDIM_Dimensions <> '') or (ILGT_Lightness <> '') or (IDPI_Resolution <> '') or (IPLT_Palette <> '') then Result := True else Result := False; end;
// -----------------------------------------------------------------------------
end. |
Он получается информацию о avi-тэгах в видео файле, проблема в том, что если в пути(C:\mypath\моймувик\movie.avi) содержатся, я так понимаю, символы кирилицы, то модуль ничего не возвращает. Немогу понять в чем проблема... P.S. Можно ли с помощью TNT Unicode Control решить проблему? Это сообщение отредактировал(а) Girder - 1.1.2007, 12:37
|