我在我的项目中使用paslibvlc从ip 摄像机中获取以 h.264 流式传输的视频。我需要从此流中获取快照并尝试使用vmem。我的项目是用delphi 7编写的。当我使用字符串“rtsp://ip/main”连接到相机时,一切正常,但是当我设置回调和格式化时,会出现访问内存冲突错误。有人可以对我说,我做错了什么吗?这是代码
PBytes = ^TBytes;
TBytes = array of byte;
var
MainForm: TMainForm;
ctx:TBytes;
const
cameraURL = 'rtsp://192.168.123.100/main';
function lock(opaque : Pointer; var planes : Pointer) : Pointer;
function unlock(opaque : Pointer; picture : Pointer; planes : Pointer) : Pointer;
function display(opaque : Pointer; picture : Pointer) : Pointer;
implementation
{$R *.dfm}
function lock(opaque : Pointer; var planes : Pointer) : Pointer;
begin
planes := x;
end;
function unlock(opaque : Pointer; picture : Pointer; planes : Pointer) : Pointer;
begin
end;
function display(opaque : Pointer; picture : Pointer) : Pointer;
begin
end;
procedure TMainForm.PlayerInit();
var
args: packed array[0..6] of PAnsiChar;
begin
libvlc_dynamic_dll_init();
SetLength(ctx, 1280*720*4+32);
if (libvlc_dynamic_dll_error <> '') then
begin
MessageDlg(libvlc_dynamic_dll_error, mtError, [mbOK], 0);
exit;
end;
args[0] := PAnsiChar(libvlc_dynamic_dll_path);
args[1] := '--no-video-title-show';
args[2] := '--no-xlib';
args[3] := '--no-audio';
p_li := libvlc_new(Length(args)-1, @args[0]);
p_mi := NIL;
end;
procedure TMainForm.PlayerPlay(fileName: WideString);
var
p_md: libvlc_media_t_ptr;
begin
btm:=Tbitmap.Create;
btm.Width:=1280;
btm.Height:=720;
PlayerStop();
// create new media from fileName
p_md := libvlc_media_new_path(p_li, PAnsiChar(System.UTF8Encode(fileName)));
//libvlc_media_player_set_media(p_mi, p_md);
p_mi := libvlc_media_player_new_from_media(p_md);
if (p_mi <> NIL) then
begin
libvlc_video_set_callbacks(p_mi,@lock,@unlock,@display,@ctx);
libvlc_video_set_format(p_mi, 'RV32', 1280, 720, 1280*4);
//libvlc_media_player_set_hwnd(p_mi, btm.Handle);
end;
// play
libvlc_media_player_play(p_mi);
// release media
if (p_md <> NIL) then
begin
libvlc_media_release(p_md);
// p_md := NIL;
end;
end;
procedure TMainForm.FormActivate(Sender: TObject);
begin
PlayerInit();
PlayerPlay(cameraURL);
end;