Home > Back-end >  [problem] SDL Delphi SDL development problems
[problem] SDL Delphi SDL development problems

Time:10-01

 
The unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SDL, StdCtrls;

Type
TForm1=class (TForm)
For: TButton;
Procedure FormCreate (Sender: TObject);
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;


Var
Form1: TForm1;

Implementation
USES the
Avformat avcodec, avutil, mem, swscale, FFMPEGDynamiccall;
{$R *. DFM}
The function SDL_Auxilipitary_ForDelphi (var Pict: PAVPicture; Var BMP: PSDL_Overlay) : Integer; Stdcall; External 'delphiSDL. DLL';
The function SDL_GetOverlayPix (const BMP: PSDL_Overlay; Const I: integer) : System. PByte; Stdcall; External 'delphiSDL. DLL';
The function SDL_GetOverlayPit (const BMP: PSDL_Overlay; Const I: integer) : integer; Stdcall; External 'delphiSDL. DLL';
Procedure TForm1. FormCreate (Sender: TObject);
The begin
//initialize the SDL
If (SDL_Init (SDL_INIT_VIDEO or SDL_INIT_AUDIO or SDL_INIT_TIMER) & lt; 0) then
Showmessage (Format (' Couldn 't initialize SDL: % s', [SDL_GetError]));
//initialize the FFMPEG library
//dynamic invocation
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ pthreadGC2 ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ xvidcore ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ avutil ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ swscale ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ avcodec ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ avfilter ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ avformat ffmpeg research project DLL ');
FFCall_AddLibrary (' D: \ Delphi \ \ avcodeclib \ avdevice ffmpeg research project DLL ');
FFCall_Init;
end;

Procedure TForm1. Button1Click (Sender: TObject);
Const
Filename='E: \ Sample avi.//get the h. 264 can also be saved as a picture
Var
PFormatCtx: PAVFormatContext;
PCodecCtx: PAVCodecContext;
PCodec: PAVCodec;
PFrame: PAVFrame;
PScaleCtx: PSwsContext;
NumBytes: integer;
Buffer: PByte;
FrameFinished: int.
Pict: TAVPicture;
I, videoStream: integer;
PTK: TAVPacket;
CRect: TRect;
//SDL
Screen: PSDL_Surface;
BMP: PSDL_Overlay;
The begin
Av_register_all ();
//the Open video file
If av_open_input_file (pFormatCtx, filename, nil, 0, nil) & lt;> 0 then
Raise the exception. Create (' WTF? ! Couldn 't open the file!!!!!! ');
//Retrieve the stream information
If av_find_stream_info (pFormatCtx) & lt; 0 then
Raise the exception. Create (' WTF? ! Couldn 't find the stream information!!!!!! ');
Dump_format (pFormatCtx, 0, filename, 0);//& lt; <<//Get a pointer to the codec context for the video stream
VideoStream:=1;
For I:=0 to pFormatCtx. Do nb_streams - 1
The begin
If pFormatCtx. Streams [I]. Codec. Codec_type=CODEC_TYPE_VIDEO then
The begin
VideoStream:=I;
break;
end;
end;

If videoStream=1 then
Raise the exception. Create (' WTF? ! Didn 't find a video stream! ');

PCodecCtx:=pFormatCtx streams [videoStream] codec.
//Open the codec
PCodec:=avcodec_find_decoder (pCodecCtx. Codec_id);

If pCodec=nil then
Raise the exception. Create (' WTF? ! The Codec not found! ');
If avcodec_open (pCodecCtx pCodec) & lt; 0 then
Raise the exception. Create (' WTF? ! Could not open the codec. ');
//the Allocate video frame
PFrame: avcodec_alloc_frame=();
//Determine the required buffer size and the allocate buffer
NumBytes:=avpicture_get_size (PIX_FMT_RGB24, pCodecCtx. Width, pCodecCtx. Height);
{$# ifndef __DARWIN__}
Screen:=SDL_SetVideoMode (pCodecCtx. Width, pCodecCtx. Height, 0, 0).
{$else}
Screen:=SDL_SetVideoMode (pCodecCtx. Width, pCodecCtx. Height, 24, 0).
{$endif}
If not assigned (screen) then showmessage (Format (' SDL: could not set the video mode: % s', [SDL_GetError]));
BMP:=SDL_CreateYUVOverlay (pCodecCtx. Width, pCodecCtx. Height,
SDL_YV12_OVERLAY, screen);
//pFrameRGB:=avcodec_alloc_frame;
//avpicture_alloc (PAVPicture (pFrameRGB), PIX_FMT_RGB32, pCodecCtx. Width, pCodecCtx, height);
PScaleCtx:=sws_getContext (pCodecCtx. Width, pCodecCtx. Height, pCodecCtx pix_fmt,
PCodecCtx width, pCodecCtx. Height, PIX_FMT_RGB32 SWS_BICUBIC, nil, nil, nil);
I:=0;
While (av_read_frame (pFormatCtx, @ PTK) & gt;=0) do the begin
I:=I + 1;
If (PTK) stream_index=videoStream) then the begin
//Decode video frame
Avcodec_decode_video (pCodecCtx pFrame, @ frameFinished, PTK) data, PTK. Size);
//Did we get a video frame?
If frameFinished & lt;> 0 then the begin

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//the problem to the
//SDL_GetOverlayPix I written in c + + dynamic link library
{
Pict - & gt; Data [0]=BMP - & gt; Pixels [0].
Pict - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related