Made ffmpeg video provider compile again, conforming to the new video provider interface, but it still won't work.

Originally committed to SVN as r952.
This commit is contained in:
Rodrigo Braz Monteiro 2007-03-24 00:11:49 +00:00
parent aba48b68e3
commit 4f1f9ccdf0
4 changed files with 117 additions and 200 deletions

View file

@ -35,7 +35,6 @@
#include "setup.h" #include "setup.h"
#if USE_LAVC == 1
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include "lavc_file.h" #include "lavc_file.h"
@ -69,5 +68,3 @@ LAVCFile::~LAVCFile()
if (fctx) if (fctx)
av_close_input_file(fctx); av_close_input_file(fctx);
} }
#endif

View file

@ -37,12 +37,13 @@
#pragma once #pragma once
#include "setup.h" #include "setup.h"
#if USE_LAVC == 1
#define EMULATE_INTTYPES #define EMULATE_INTTYPES
#include <wx/filename.h> #include <wx/filename.h>
extern "C" {
#include <ffmpeg/avcodec.h> #include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h> #include <ffmpeg/avformat.h>
}
class LAVCFile { class LAVCFile {
private: private:
@ -64,5 +65,3 @@ public:
LAVCFile *AddRef() { refs++; return this; }; LAVCFile *AddRef() { refs++; return this; };
void Release() { if (!--refs) delete this; }; void Release() { if (!--refs) delete this; };
}; };
#endif /* USE_LAVC */

View file

@ -37,23 +37,40 @@
/////////// ///////////
// Headers // Headers
#include "setup.h" #include "setup.h"
#if USE_LAVC == 1
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include <wx/image.h> #include <wx/image.h>
#include <algorithm> #include <algorithm>
#include "video_provider_lavc.h" #include "video_provider_lavc.h"
#include "utils.h" #include "utils.h"
#include "vfr.h" #include "vfr.h"
#include "subtitle_provider.h"
#include "ass_file.h" #include "ass_file.h"
#if 0 #if 0
#include "mkv_wrap.h" #include "mkv_wrap.h"
#endif #endif
/////////////////////
// Link to libraries
#if __VISUALC__ >= 1200
#pragma comment(lib, "avcodec-51.lib")
#pragma comment(lib, "avformat-51.lib")
#pragma comment(lib, "avutil-49.lib")
#endif
///////////
// Factory
class LAVCVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new LAVCVideoProvider(video,fps); }
LAVCVideoProviderFactory() : VideoProviderFactory(_T("ffmpeg")) {}
} registerLAVCVideo;
/////////////// ///////////////
// Constructor // Constructor
LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) { LAVCVideoProvider::LAVCVideoProvider(wxString filename,double fps) {
// Init variables // Init variables
codecContext = NULL; codecContext = NULL;
lavcfile = NULL; lavcfile = NULL;
@ -65,19 +82,10 @@ LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) {
buffer1Size = 0; buffer1Size = 0;
buffer2Size = 0; buffer2Size = 0;
vidStream = -1; vidStream = -1;
zoom = 1.0;
validFrame = false; validFrame = false;
overlay = NULL;
// Load // Load
LoadVideo(filename); LoadVideo(filename,fps);
// Attach subtitles
try {
SubtitleProvider::Class::GetProvider(_T("libass"), AssFile::top)->Bind(this);
} catch (...) {
/* warn user? */
}
} }
@ -88,19 +96,9 @@ LAVCVideoProvider::~LAVCVideoProvider() {
} }
/////////////////
// Attach overlay
void LAVCVideoProvider::AttachOverlay(SubtitleProvider::Overlay *_overlay)
{
overlay = _overlay;
if (overlay)
overlay->SetParams(display_w, display_h);
}
////////////// //////////////
// Load video // Load video
void LAVCVideoProvider::LoadVideo(wxString filename) { void LAVCVideoProvider::LoadVideo(wxString filename, double fps) {
// Close first // Close first
Close(); Close();
@ -112,7 +110,7 @@ void LAVCVideoProvider::LoadVideo(wxString filename) {
// Find video stream // Find video stream
vidStream = -1; vidStream = -1;
codecContext = NULL; codecContext = NULL;
for (int i=0;i<lavcfile->fctx->nb_streams;i++) { for (unsigned int i=0;i<lavcfile->fctx->nb_streams;i++) {
codecContext = lavcfile->fctx->streams[i]->codec; codecContext = lavcfile->fctx->streams[i]->codec;
if (codecContext->codec_type == CODEC_TYPE_VIDEO) { if (codecContext->codec_type == CODEC_TYPE_VIDEO) {
stream = lavcfile->fctx->streams[i]; stream = lavcfile->fctx->streams[i];
@ -150,10 +148,6 @@ void LAVCVideoProvider::LoadVideo(wxString filename) {
} }
#endif #endif
// Set size
dar = double(GetSourceWidth()) / GetSourceHeight();
UpdateDisplaySize();
// Allocate frame // Allocate frame
frame = avcodec_alloc_frame(); frame = avcodec_alloc_frame();
@ -201,15 +195,6 @@ void LAVCVideoProvider::Close() {
} }
///////////////////////
// Update display size
void LAVCVideoProvider::UpdateDisplaySize() {
// Set
display_w = MID(16,int((GetSourceHeight() * zoom * dar)+0.5),4096);
display_h = MID(16,int((GetSourceHeight() * zoom)+0.5),4096);
}
////////////////// //////////////////
// Get next frame // Get next frame
bool LAVCVideoProvider::GetNextFrame() { bool LAVCVideoProvider::GetNextFrame() {
@ -239,93 +224,89 @@ bool LAVCVideoProvider::GetNextFrame() {
} }
/////////////////////////////// /////////////////////////////////
// Convert AVFrame to wxBitmap //// Convert AVFrame to wxBitmap
wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source, int n) { //wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source, int n) {
// Get sizes // // Get sizes
int w = codecContext->width; // int w = codecContext->width;
int h = codecContext->height; // int h = codecContext->height;
//#ifdef __WINDOWS__ ////#ifdef __WINDOWS__
// PixelFormat format = PIX_FMT_RGBA32; //// PixelFormat format = PIX_FMT_RGBA32;
//#else ////#else
PixelFormat format = PIX_FMT_RGB24; // PixelFormat format = PIX_FMT_RGB24;
//#endif ////#endif
unsigned int size1 = avpicture_get_size(codecContext->pix_fmt,display_w,display_h); // unsigned int size1 = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
unsigned int size2 = avpicture_get_size(format,display_w,display_h); // unsigned int size2 = avpicture_get_size(format,display_w,display_h);
//
// Prepare buffers // // Prepare buffers
if (!buffer1 || buffer1Size != size1) { // if (!buffer1 || buffer1Size != size1) {
if (buffer1) delete buffer1; // if (buffer1) delete buffer1;
buffer1 = new uint8_t[size1]; // buffer1 = new uint8_t[size1];
buffer1Size = size1; // buffer1Size = size1;
} // }
if (!buffer2 || buffer2Size != size2) { // if (!buffer2 || buffer2Size != size2) {
if (buffer2) delete buffer2; // if (buffer2) delete buffer2;
buffer2 = new uint8_t[size2]; // buffer2 = new uint8_t[size2];
buffer2Size = size2; // buffer2Size = size2;
} // }
//
// Resize // // Resize
AVFrame *resized; // AVFrame *resized;
bool resize = w != display_w || h != display_h; // bool resize = w != display_w || h != display_h;
if (resize) { // if (resize) {
// Allocate // // Allocate
unsigned int resSize = avpicture_get_size(codecContext->pix_fmt,display_w,display_h); // unsigned int resSize = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
resized = avcodec_alloc_frame(); // resized = avcodec_alloc_frame();
avpicture_fill((AVPicture*) resized, buffer1, codecContext->pix_fmt, display_w, display_h); // avpicture_fill((AVPicture*) resized, buffer1, codecContext->pix_fmt, display_w, display_h);
//
// Resize // // Resize
ImgReSampleContext *resampleContext = img_resample_init(display_w,display_h,w,h); // ImgReSampleContext *resampleContext = img_resample_init(display_w,display_h,w,h);
img_resample(resampleContext,(AVPicture*) resized,(AVPicture*) source); // img_resample(resampleContext,(AVPicture*) resized,(AVPicture*) source);
img_resample_close(resampleContext); // img_resample_close(resampleContext);
//
// Set new w/h // // Set new w/h
w = display_w; // w = display_w;
h = display_h; // h = display_h;
} // }
else resized = source; // else resized = source;
//
// Allocate RGB32 buffer // // Allocate RGB32 buffer
AVFrame *frameRGB = avcodec_alloc_frame(); // AVFrame *frameRGB = avcodec_alloc_frame();
avpicture_fill((AVPicture*) frameRGB, buffer2, format, w, h); // avpicture_fill((AVPicture*) frameRGB, buffer2, format, w, h);
//
// Convert to RGB32 // // Convert to RGB32
img_convert((AVPicture*) frameRGB, format, (AVPicture*) resized, codecContext->pix_fmt, w, h); // img_convert((AVPicture*) frameRGB, format, (AVPicture*) resized, codecContext->pix_fmt, w, h);
//
// Convert to wxBitmap // // Convert to wxBitmap
wxImage img(w, h, false); // wxImage img(w, h, false);
unsigned char *data = (unsigned char *)malloc(w * h * 3); // unsigned char *data = (unsigned char *)malloc(w * h * 3);
memcpy(data, frameRGB->data[0], w * h * 3); // memcpy(data, frameRGB->data[0], w * h * 3);
img.SetData(data); // img.SetData(data);
if (overlay) // if (overlay)
overlay->Render(img, VFR_Input.GetTimeAtFrame(n)); // overlay->Render(img, VFR_Input.GetTimeAtFrame(n));
//
wxBitmap bmp(img); // wxBitmap bmp(img);
//
av_free(frameRGB); // av_free(frameRGB);
if (resized != source) // if (resized != source)
av_free(resized); // av_free(resized);
return bmp; // return bmp;
} //}
////////////////
// Refresh subs
void LAVCVideoProvider::RefreshSubtitles() {
}
///////////// /////////////
// Get frame // Get frame
wxBitmap LAVCVideoProvider::GetFrame(int n) { const AegiVideoFrame LAVCVideoProvider::DoGetFrame(int n) {
// Return stored frame // Return stored frame
n = MID(0,n,GetFrameCount()-1); n = MID(0,n,GetFrameCount()-1);
if (n == frameNumber) { if (n == frameNumber) {
if (!validFrame) { if (!validFrame) {
curFrame = AVFrameToWX(frame, n); //curFrame = AVFrameToWX(frame, n);
validFrame = true; validFrame = true;
} }
return curFrame; //return curFrame;
AegiVideoFrame dummy;
return dummy;
} }
// Following frame, just get it // Following frame, just get it
@ -400,23 +381,20 @@ wxBitmap LAVCVideoProvider::GetFrame(int n) {
} }
// Bitmap // Bitmap
wxBitmap bmp; //wxBitmap bmp;
if (frame) bmp = AVFrameToWX(frame, n); //if (frame) bmp = AVFrameToWX(frame, n);
else bmp = wxBitmap(GetWidth(),GetHeight()); //else bmp = wxBitmap(GetWidth(),GetHeight());
// Set current frame //// Set current frame
validFrame = true; //validFrame = true;
curFrame = bmp; //curFrame = bmp;
frameNumber = n; //frameNumber = n;
// Return //// Return
return curFrame; //return curFrame;
}
AegiVideoFrame dummy;
////////////////////// return dummy;
// Get frame as float
void LAVCVideoProvider::GetFloatFrame(float* Buffer, int n) {
} }
@ -441,57 +419,15 @@ double LAVCVideoProvider::GetFPS() {
} }
////////////////////
// Set aspect ratio
void LAVCVideoProvider::SetDAR(double _dar) {
dar = _dar;
validFrame = false;
UpdateDisplaySize();
}
////////////
// Set zoom
void LAVCVideoProvider::SetZoom(double _zoom) {
zoom = _zoom;
validFrame = false;
UpdateDisplaySize();
}
////////////
// Get zoom
double LAVCVideoProvider::GetZoom() {
return zoom;
}
/////////////
// Get width
int LAVCVideoProvider::GetWidth() {
return display_w;
}
//////////////
// Get height
int LAVCVideoProvider::GetHeight() {
return display_h;
}
////////////////////// //////////////////////
// Get original width // Get original width
int LAVCVideoProvider::GetSourceWidth() { int LAVCVideoProvider::GetWidth() {
return codecContext->width; return codecContext->width;
} }
/////////////////////// ///////////////////////
// Get original height // Get original height
int LAVCVideoProvider::GetSourceHeight() { int LAVCVideoProvider::GetHeight() {
return codecContext->height; return codecContext->height;
} }
#endif

View file

@ -39,10 +39,11 @@
/////////// ///////////
// Headers // Headers
#include "setup.h" #include "setup.h"
#if USE_LAVC == 1
#define EMULATE_INTTYPES #define EMULATE_INTTYPES
extern "C" {
#include <ffmpeg/avcodec.h> #include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h> #include <ffmpeg/avformat.h>
}
#include "video_provider.h" #include "video_provider.h"
#include "mkv_wrap.h" #include "mkv_wrap.h"
#include "lavc_file.h" #include "lavc_file.h"
@ -62,8 +63,6 @@ private:
AVFrame *frame; AVFrame *frame;
int vidStream; int vidStream;
double zoom;
double dar;
int display_w; int display_w;
int display_h; int display_h;
@ -81,37 +80,23 @@ private:
int buffer1Size; int buffer1Size;
int buffer2Size; int buffer2Size;
void UpdateDisplaySize();
bool GetNextFrame(); bool GetNextFrame();
void LoadVideo(wxString filename); void LoadVideo(wxString filename, double fps);
void Close(); void Close();
wxBitmap AVFrameToWX(AVFrame *frame, int n);
SubtitleProvider::Overlay *overlay;
protected: protected:
virtual void AttachOverlay(SubtitleProvider::Overlay *_overlay); const AegiVideoFrame DoGetFrame(int n);
public: public:
LAVCVideoProvider(wxString filename, wxString subfilename); LAVCVideoProvider(wxString filename, double fps);
~LAVCVideoProvider(); ~LAVCVideoProvider();
void RefreshSubtitles();
wxBitmap GetFrame(int n); wxBitmap GetFrame(int n);
void GetFloatFrame(float* Buffer, int n);
int GetPosition(); int GetPosition();
int GetFrameCount(); int GetFrameCount();
double GetFPS();
void SetDAR(double dar);
void SetZoom(double zoom);
int GetWidth(); int GetWidth();
int GetHeight(); int GetHeight();
double GetZoom(); double GetFPS();
int GetSourceWidth();
int GetSourceHeight();
}; };
#endif