LAVCVideoProvider overlay support

Originally committed to SVN as r363.
This commit is contained in:
David Lamparter 2006-05-06 01:06:22 +00:00
parent c8352441e8
commit 635cfb2fa5
2 changed files with 22 additions and 8 deletions

View File

@ -63,6 +63,7 @@ LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) {
vidStream = -1;
zoom = 1.0;
validFrame = false;
overlay = NULL;
// Load
LoadVideo(filename);
@ -76,6 +77,16 @@ LAVCVideoProvider::~LAVCVideoProvider() {
}
/////////////////
// Attach overlay
void LAVCVideoProvider::AttachOverlay(SubtitleProvider::Overlay *_overlay)
{
overlay = _overlay;
if (overlay)
overlay->SetParams(display_w, display_h);
}
//////////////
// Load video
void LAVCVideoProvider::LoadVideo(wxString filename) {
@ -219,7 +230,7 @@ bool LAVCVideoProvider::GetNextFrame() {
///////////////////////////////
// Convert AVFrame to wxBitmap
wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source) {
wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source, int n) {
// Get sizes
int w = codecContext->width;
int h = codecContext->height;
@ -271,15 +282,14 @@ wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source) {
img_convert((AVPicture*) frameRGB, format, (AVPicture*) resized, codecContext->pix_fmt, w, h);
// Convert to wxBitmap
#ifdef __WINDOWS__
wxBitmap bmp((const char*) frameRGB->data[0],w,h,32);
#else
wxImage img(w, h, false);
unsigned char *data = (unsigned char *)malloc(w * h * 3);
memcpy(data, frameRGB->data[0], w * h * 3);
img.SetData(data);
if (overlay)
overlay->Render(img, n);
wxBitmap bmp(img);
#endif
av_free(frameRGB);
if (resized != source)
@ -301,7 +311,7 @@ wxBitmap LAVCVideoProvider::GetFrame(int n) {
n = MID(0,n,GetFrameCount()-1);
if (n == frameNumber) {
if (!validFrame) {
curFrame = AVFrameToWX(frame);
curFrame = AVFrameToWX(frame, n);
validFrame = true;
}
return curFrame;
@ -380,7 +390,7 @@ wxBitmap LAVCVideoProvider::GetFrame(int n) {
// Bitmap
wxBitmap bmp;
if (frame) bmp = AVFrameToWX(frame);
if (frame) bmp = AVFrameToWX(frame, n);
else bmp = wxBitmap(GetWidth(),GetHeight());
// Set current frame

View File

@ -93,7 +93,11 @@ private:
bool GetNextFrame();
void LoadVideo(wxString filename);
void Close();
wxBitmap AVFrameToWX(AVFrame *frame);
wxBitmap AVFrameToWX(AVFrame *frame, int n);
SubtitleProvider::Overlay *overlay;
protected:
virtual void AttachOverlay(SubtitleProvider::Overlay *_overlay);
public:
LAVCVideoProvider(wxString filename, wxString subfilename);