Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Media";
Текущий архив: 2004.10.24;
Скачать: [xml.tar.bz2];

Вниз

Информация о видеофайле   Найти похожие ветки 

 
Anf   (2004-07-30 16:53) [0]

Каким образом узнать в программе информацию о видеофайле, например об AVI?
Интересует длительность, видеониформация (кодек, размеры, частота кадров), аудиоинформация (битрейт, формат звука) количество потоков и т.п.


 
antonn   (2004-07-30 17:14) [1]

Где-то откопал старый пример:

// First, put a memo, button and a open dialog on an empty form.
// Then use the following code to show the information of a avi file.

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;
   Memo1: TMemo;
   OpenDialog1: TOpenDialog;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
   procedure ReadAviInfo(FileName: string);

 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ReadAviInfo(FileName: string);
var
 iFileHandle: Integer; // File handle

 // Needed for positioning in the avi file
 Aviheadersize: integer;
 Vheadersize: integer;
 Aviheaderstart: integer;
 Vheaderstart: integer;
 Aheaderstart: integer;
 Astrhsize: integer;

 // Temporary values
 TempTest: String[5];
 TempSize: Integer;
 TempVcodec: String[5];
 TempAcodec: integer;
 TempMicrosec: integer;
 TempLengthInFrames: integer;
 TempAchannels: integer;
 TempAsamplerate: integer;
 TempAbitrate: integer;

 // Final values
 Size: double;
 Length: string;
 Vcodec: string;
 Vbitrate: double;
 VWidth: integer;
 VHeight: integer;
 Fps: double;

 LengthInSec: double;
 Acodec: string;
 Abitrate: string;
begin
 // Open the file
 iFileHandle := FileOpen(FileName, fmOpenRead);

 // Test to see if file is AVI
 FileSeek(iFileHandle, 7, 0);
 FileRead(iFileHandle, TempTest, 5);
 if copy(TempTest, 0, 4) <> "AVI " then
 begin
   MessageDlg("Could not open " + FileName +
     " because it is not a valid video file", mtError, [mbOk], 0);
   Exit;
 end;

 // File size
 FileSeek(iFileHandle,4,0);
 FileRead(iFileHandle, TempSize, 4);

 // Avi header size (needed to locate the audio part)
 FileSeek(iFileHandle,28,0);
 FileRead(iFileHandle, Aviheadersize, 4);

 // Avi header start (needed to locate the video part)
 Aviheaderstart := 32;

 // Microseconds (1000000 / TempMicrosec = fps)
 FileSeek(iFileHandle,Aviheaderstart,0);
 FileRead(iFileHandle, TempMicrosec, 4);

 // Length of movie in frames
 FileSeek(iFileHandle,Aviheaderstart + 16,0);
 FileRead(iFileHandle, TempLengthInFrames, 4);

 // Width
 FileSeek(iFileHandle,Aviheaderstart + 32,0);
 FileRead(iFileHandle, VWidth, 4);

 // Height
 FileSeek(iFileHandle,Aviheaderstart + 36,0);
 FileRead(iFileHandle, VHeight, 4);

 FileSeek(iFileHandle,Aviheaderstart + Aviheadersize + 4,0);
 FileRead(iFileHandle, Vheadersize, 4);

 Vheaderstart := Aviheaderstart + Aviheadersize + 20;

 // Video codec
 FileSeek(iFileHandle,Vheaderstart + 3,0);
 FileRead(iFileHandle, TempVCodec, 5);

 Aheaderstart := Vheaderstart + Vheadersize + 8;

 FileSeek(iFileHandle,Aheaderstart - 4,0);
 FileRead(iFileHandle, Astrhsize, 5);

 // Audio codec
 FileSeek(iFileHandle,Aheaderstart + Astrhsize + 8,0);
 FileRead(iFileHandle, TempACodec, 2);

 // Audio channels (1 = mono, 2 = stereo)
 FileSeek(iFileHandle,Aheaderstart + Astrhsize + 10,0);
 FileRead(iFileHandle, TempAchannels, 2);

 // Audio samplerate
 FileSeek(iFileHandle,Aheaderstart + Astrhsize + 12,0);
 FileRead(iFileHandle, TempAsamplerate, 4);

 // Audio bitrate
 FileSeek(iFileHandle,Aheaderstart + Astrhsize + 16,0);
 FileRead(iFileHandle, TempAbitrate, 4);

 // Close the file
 FileClose(iFileHandle);

 // Analyse the video codec (more can be added)
 Vcodec := copy(TempVcodec, 0, 4);
 if Vcodec = "div2" then Vcodec := "MS MPEG4 v2"
 else if Vcodec = "DIV2" then Vcodec := "MS MPEG4 v2"
 else if Vcodec = "div3" then Vcodec := "DivX;-) MPEG4 v3"
 else if Vcodec = "DIV3" then Vcodec := "DivX;-) MPEG4 v3"
 else if Vcodec = "div4" then Vcodec := "DivX;-) MPEG4 v4"
 else if Vcodec = "DIV4" then Vcodec := "DivX;-) MPEG4 v4"
 else if Vcodec = "div5" then Vcodec := "DivX;-) MPEG4 v5"
 else if Vcodec = "DIV5" then Vcodec := "DivX;-) MPEG4 v5"
 else if Vcodec = "divx" then Vcodec := "DivX 4"
 else if Vcodec = "mp43" then Vcodec := "Microcrap MPEG4 v3";

 // Analyse the audio codec (more can be added)
 case TempAcodec of
   0: Acodec := "PCM";
   1: Acodec := "PCM";
   85: Acodec := "MPEG Layer 3";
   353: Acodec := "DivX;-) Audio";
   8192: Acodec := "AC3-Digital";
 else
   Acodec := "Unknown (" + IntToStr(TempAcodec) + ")";
 end;

 case (Trunc(TempAbitrate / 1024 * 8)) of
   246..260: Abitrate := "128 Kbit/s";
   216..228: Abitrate := "128 Kbit/s";
   187..196: Abitrate := "128 Kbit/s";
   156..164: Abitrate := "128 Kbit/s";
   124..132: Abitrate := "128 Kbit/s";
   108..116: Abitrate := "128 Kbit/s";
   92..100: Abitrate := "128 Kbit/s";
   60..68: Abitrate := "128 Kbit/s";
 else
   Abitrate := FormatFloat("# Kbit/s", TempAbitrate / 1024 * 8);
 end;

 // Some final calculations
 Size := TempSize / 1024 / 1024;
 Fps := 1000000 / TempMicrosec; // FPS
 LengthInSec := TempLengthInFrames / fps; // Length in seconds
 Length := FormatFloat("# min", Int(LengthInSec / 60)) +
   FormatFloat(" # sec", Round(LengthInSec - (Int(LengthInSec / 60) * 60)));
 Vbitrate := (TempSize / LengthInSec - TempABitrate) / 1024 * 8;

 // Output information to memo field
 Memo1.Lines.Add("AVI INFORMATION");
 Memo1.lines.Add("Size: " + FormatFloat("#.## MB",Size));
 Memo1.Lines.Add("Length: " + Length);
 Memo1.Lines.Add("");
 Memo1.Lines.Add("VIDEO INFORMATION");
 Memo1.Lines.Add("Codec: " + Vcodec);
 Memo1.Lines.Add("Bitrate: " + FormatFloat("# Kbit/s", Vbitrate));
 Memo1.lines.Add("Width: " + IntToStr(VWidth) + " px");
 Memo1.lines.Add("Height: " + IntToStr(VHeight) + " px");
 Memo1.Lines.Add("FPS: " + FormatFloat("#.##", fps));
 Memo1.Lines.Add("");
 Memo1.Lines.Add("AUDIO INFORMATION");
 Memo1.Lines.Add("Codec: " + Acodec);
 Memo1.Lines.Add("Bitrate: " + Abitrate);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 OpenDialog1.Filter := "AVI files (*.avi)|*.avi";
 if OpenDialog1.Execute then
 begin
   Memo1.Clear;
   ReadAviInfo(OpenDialog1.FileName);
 end;
end;

end.

От себя добавлю - заменить первый цикл:

if (copy(FTempTest, 0, 4) <> "AVI ") and  (copy(FTempTest, 0, 4) <> "A") and (copy(FTempTest, 0, 4) <> "AV") and (copy(FTempTest, 0, 1) <> "A") and (copy(FTempTest, 0, 1) <> "C") then
        begin
         MessageDlg("Could not open " + FileName +
           " because it is not a valid video file", mtError, [mbOk], 0);

         Exit;
       
        end;


 
Anf   (2004-07-30 17:24) [2]

Понятно, спасибо.


 
antonn   (2004-07-30 17:30) [3]

Кстати, можно видео-кодеков добавить:

else if FVcodec = "yvu9" then FVcodec := "Intel Indeo(C)Video Raw R1.2"
 else if FVcodec = "cvid" then FVcodec := "Cinepak Codec by CTi"
 else if FVcodec = "3ivx" then FVcodec := "3ivx D4 4.0.4"
 else if FVcodec = "mdvd" then FVcodec := "MicroDVD Video Decodec"
 else if FVcodec = "vcr2" then FVcodec := "ATI VCR2 Format Codec"
 else if FVcodec = "yv12" then FVcodec := "ATI YUV12 Format Codec"
 else if FVcodec = "aflc" then FVcodec := "Autodesk FLC Compressor"
 else if FVcodec = "aasc" then FVcodec := "Autodesk RLE Compressor"
 else if FVcodec = "wrpr" then FVcodec := "AVI Wrapper Video Client Codec"
 else if FVcodec = "avrn" then FVcodec := "Avid Avi Codec 2.0d2"
 else if FVcodec = "mszh" then FVcodec := "AVImszh Compressor"
 else if FVcodec = "zlib" then FVcodec := "AVIzlib Compressor"
 else if FVcodec = "bt20" then FVcodec := "Brooktree ProSumer Video (32)"
 else if FVcodec = "y41p" then FVcodec := "Brooktree YUV 411 Raw"
 else if FVcodec = "cscd" then FVcodec := "CamStudio Lossless Codec v1.0"
 else if FVcodec = "ddvc" then FVcodec := "Canopus Soft DVSD Codec"
 else if FVcodec = "cdvc" then FVcodec := "Canopus Software DV Codec"
 else if FVcodec = "png1" then FVcodec := "CorePNG VFW Codec v0.6"
 else if FVcodec = "dcmj" then FVcodec := "dcmj MainConcept Video V3.00a"
 else if FVcodec = "dvx4" then FVcodec := "DivX Codec"
 else if FVcodec = "advs" then FVcodec := "DVSoft (TM)"
 else if FVcodec = "em2v" then FVcodec := "Etymonix MPEG-2 Video Codec v1.10"
 else if FVcodec = "frwd" then FVcodec := "Forward JPEG"
 else if FVcodec = "frwt" then FVcodec := "Forward JPEG+Alpha"
 else if FVcodec = "frwu" then FVcodec := "Forward Uncompressed"
 else if FVcodec = "fps1" then FVcodec := "Fraps Video Decompressor"
 else if FVcodec = "mkvc" then FVcodec := "FullMotionVideo Decoder"
 else if FVcodec = "glzw" then FVcodec := "GLZW 1.00"
 else if FVcodec = "gpeg" then FVcodec := "GPEF 1.00"
 else if FVcodec = "hfyu" then FVcodec := "Huffyuv v2.1.1 - CCESP Path v0.2.2"
 else if FVcodec = "iv50" then FVcodec := "Indeo(c) video 5.10"
 else if FVcodec = "i420" then FVcodec := "Intel 4:2:0 Video V2.50"
 else if FVcodec = "i263" then FVcodec := "Intel I.263 Video Driver 2.55.016"
 else if FVcodec = "iv41" then FVcodec := "Intel Indeo(R) Video Interactive"
 else if FVcodec = "iv32" then FVcodec := "Intel Indeo(R) Video R3.2"
 else if FVcodec = "yvu9" then FVcodec := "Intel Indeo(C) Video Raw R1.2"
 else if FVcodec = "lead" then FVcodec := "LEAD MCMP/MJPEG Codec (VFW)"
 else if FVcodec = "dvsd" then FVcodec := "MainConcept DV Codec 2.0.4"
 else if FVcodec = "dv25" then FVcodec := "Matrox DVCPRO"
 else if FVcodec = "dv50" then FVcodec := "Matrox DVCPRO50"
 else if FVcodec = "mmes" then FVcodec := "Matrox MPEG-2 I-frame"
 else if FVcodec = "m261" then FVcodec := "Microsoft H.261 Video Codec"
 else if FVcodec = "m263" then FVcodec := "Microsoft H.263 Video Codec"
 else if FVcodec = "mrle" then FVcodec := "Microsoft RLE"
 else if FVcodec = "msvc" then FVcodec := "Microsoft Video 1"
 else if FVcodec = "wmv3" then FVcodec := "Microsoft Windows Media Video 9"
 else if FVcodec = "vixl" then FVcodec := "MiroVideo-XL 32-bit Compressor"
 else if FVcodec = "fljp" then FVcodec := "Morgan FLJP LSI M-JPEG Codec"
 else if FVcodec = "dmb1" then FVcodec := "Morgan Multimedia M-JPEG V3 Codec"
 else if FVcodec = "mjpg" then FVcodec := "Morgan Multimedia M-JPEG V3 Codec"
 else if FVcodec = "mj2c" then FVcodec := "Morgan Multimedia M-JPEG2000 V1 Codec"
 else if FVcodec = "tvmj" then FVcodec := "Morgan TVMJ LSI M-JPEG Codec"
 else if FVcodec = "mwv1" then FVcodec := "MotionWavelets by Aware"
 else if FVcodec = "nt00" then FVcodec := "Newtek Inc. version 0.0"
 else if FVcodec = "ipdv" then FVcodec := "Panasonic and I-O DATA DV GigaAVI CODEC"
 else if FVcodec = "pdvc" then FVcodec := "Panasonic and I-O DATA DV GigaAVI CODEC"
 else if FVcodec = "pim1" then FVcodec := "PCLEPIM1 32-bit Compressor"
 else if FVcodec = "pimj" then FVcodec := "PICVideo Lossless LPEG Codec"
 else if FVcodec = "mjpx" then FVcodec := "PICVideo MJPEG Codec"
 else if FVcodec = "pvw2" then FVcodec := "PICVideo Wavelet 2000 Codec"
 else if FVcodec = "miro" then FVcodec := "Pinnacle DV codec"
 else if FVcodec = "qpeg" then FVcodec := "QPEG(C) Video Codec"
 else if FVcodec = "mjpa" then FVcodec := "ReelTime MJPEG Codec"
 else if FVcodec = "rud0" then FVcodec := "Rududu Encoder ver 0"
 else if FVcodec = "rmp4" then FVcodec := "Sigma RMP4 MPEG-4 codec"
 else if FVcodec = "sony" then FVcodec := "Sony DV software CODEC"
 else if FVcodec = "tscc" then FVcodec := "TECHSmith SCREEN Capture Codec"
 else if FVcodec = "s422" then FVcodec := "Tekram YUV422 Codec"
 else if FVcodec = "vifp" then FVcodec := "VFAPI reader Cxodec 1.05"



Страницы: 1 вся ветка

Форум: "Media";
Текущий архив: 2004.10.24;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.49 MB
Время: 0.034 c
14-1097136819
pan
2004-10-07 12:13
2004.10.24
редактирование реестра запрещено администратором системы


8-1088758202
qwerg
2004-07-02 12:50
2004.10.24
Трабл со скинами


3-1096274444
Bless
2004-09-27 12:40
2004.10.24
Как восстановить удаленную таблицу!


1-1097057165
Cosinus
2004-10-06 14:06
2004.10.24
Как получить Handle системного Popup меню?


8-1091114404
parovoZZ
2004-07-29 19:20
2004.10.24
16 разрядов и 32





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский