流浪的加菲
deepin
2024-02-23 16:58 不知道为什么有差异,但是既然已经用UOS系统了,本身也是推荐大家在UOS上使用Qt Creator,而且看你说的使用Qt 解码效率是正常的,那就用Qt来干活咯😂
Reply Like 0 View the author
不知道为什么有差异,但是既然已经用UOS系统了,本身也是推荐大家在UOS上使用Qt Creator,而且看你说的使用Qt 解码效率是正常的,那就用Qt来干活咯😂
试试把你代码sdl的渲染器用GPU硬件加速渲染,
源代码里这句
sdlRenderer := SDL_CreateRenderer(sdlWindow, -1, 0);
改成
sdlRenderer := SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED);
Popular Ranking
ChangePopular Events
More
运行环境如题,详细如图。简单的调用ffmpeg 动态库解码1080P h264文件,结果解码每帧要40-70毫秒,正常应该是10毫秒左右。
同样的机器,同样的ffmpeg库和调用逻辑,换做qt creator就效率正常。求助各位,看有哪些因素导致。谢谢。
后附主要代码。解码函数avcodec_decode_video2耗时40-70毫秒。

Program ffmpeg_sample_player;
Uses
//Windows,
SysUtils,
Classes,
libSDL2,
ffmpeg_loader,
ffmpeg_types,
libavcodec,
libavdevice,
libavfilter,
libavformat,
libavutil,
libpostproc,
libswresample,
libswscale;
Var
err: Integer;
filename: AnsiString;
pFormatCtx: pAVFormatContext = Nil;
pCodecCtx: pAVCodecContext;
pCodec: pAVCodec;
screen: pSDL_Surface;
//bmp: pSDL_Overlay;
sdlWindow: PSDL_Window;
sdlRenderer: PSDL_Renderer;
sdlTexture: PSDL_Texture;
img_convert_context: pSwsContext;
frame: pAVFrame;
pFrameYUV420P: pAVFrame;
packet: AVPacket;
frame_finished: Integer;
pict: AVPicture;
rect: TSDL_Rect;
event: TSDL_Event;
FLoaderFFmpeg: TLoaderFFmpeg;
i,videoStream:Integer;
xoptions: pAVDictionary = nil;
curDir: string;
h264File: THandle;
itick: cardinal;
Procedure ExitX;
begin
WriteLN(' ');
WriteLN('-----ERROR-------------');
WriteLN('Press any key to Exit...');
ReadLN;
Halt(0);
end;
function alloc_avframe(pix_fmt: AVPixelFormat; width, height: integer): PAVFrame;
var
picture: PAVFrame;
picture_buf: PByte;
size: integer;
begin
Result := nil;
picture := av_frame_alloc();
if (picture = nil) then
Exit;
size := av_image_get_buffer_size(pix_fmt, width, height, 1);
picture_buf := av_malloc(size);
if (picture_buf = nil) then
begin
av_frame_free(picture);
Exit;
end;
av_image_fill_arrays(@picture^.data[0], @picture^.linesize[0], picture_buf, pix_fmt, width, height, 1);
Result := picture;
end;
Begin
curDir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
filename := curDir + 'video.h264';
{$if defined(windows)}
curDir := curDir + 'windows_sdl2' + DirectorySeparator;
{$else}
curDir := curDir + 'linux_sdl' + DirectorySeparator;
{$ifend}
libSDL2_Load(curDir + SDL_LibName);
If libSDL2_IsLoaded = False Then
Begin
WriteLn('Unable to Load SDL2 Library');
ExitX;
End;
FLoaderFFmpeg := TLoaderFFmpeg.Create(Nil);
FLoaderFFmpeg.Active := true;
If (FLoaderFFmpeg.IslibavCodec_Loaded = False) Or
(FLoaderFFmpeg.IslibavDevice_Loaded = False) Then
Begin
WriteLn('Unable to Load libavCodec Library');
ExitX;
End;
Try
Except
On E: Exception Do
WriteLn(E.ClassName, ': ', E.Message);
End;
FLoaderFFmpeg.free;
WriteLN(' ');
WriteLN('Press any key to Exit...');
ReadLN;
End.