patrick_
11th November 2008, 15:39
I don't have any experience with C++ (I normally use C#), but am trying to write a plugin.
This is my code:
#include "windows.h"
#include "avisynth.h"
#include <fstream>
using namespace std;
class SaveRAW : public GenericVideoFilter {
public:
SaveRAW(PClip _child, const char* _filename, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
~SaveRAW();
private:
int framesize;
fstream file;
};
SaveRAW::SaveRAW(PClip _child, const char* _filename, IScriptEnvironment* env) : GenericVideoFilter(_child) {
framesize = vi.width * vi.height * vi.BitsPerPixel() / 8;
fstream file(_filename, ios::binary | ios::out);
if (!file) env->ThrowError("could not create file");
}
SaveRAW::~SaveRAW() {
file.close();
}
PVideoFrame __stdcall SaveRAW::GetFrame(int n, IScriptEnvironment* env) {
PVideoFrame src = child->GetFrame(n, env);
const unsigned char* srcp = src->GetReadPtr();
file.write((const char*)srcp, framesize);
return src;
}
AVSValue __cdecl Create_SaveRAW(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new SaveRAW(args[0].AsClip(), args[1].AsString(), env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("SaveRAW", "cs", Create_SaveRAW, 0);
return "`SaveRAW' SaveRAW plugin";
}
I'm trying to write the RAW video data (will be in YV12) to a file. The code creates the file, but for some reason doesn't write any data.
I guess I'm just making some stupid mistake, but I don't really have a clue about what it can be.
BTW I took part of this code from another filter, and this:
const unsigned char* srcp = src->GetReadPtr();
file.write((const char*)srcp, framesize);
seems a little strange to me: casting an unsigned char to a char, especially considering that GetReadPtr returns a byte.
Thanks in advance for any help.
This is my code:
#include "windows.h"
#include "avisynth.h"
#include <fstream>
using namespace std;
class SaveRAW : public GenericVideoFilter {
public:
SaveRAW(PClip _child, const char* _filename, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
~SaveRAW();
private:
int framesize;
fstream file;
};
SaveRAW::SaveRAW(PClip _child, const char* _filename, IScriptEnvironment* env) : GenericVideoFilter(_child) {
framesize = vi.width * vi.height * vi.BitsPerPixel() / 8;
fstream file(_filename, ios::binary | ios::out);
if (!file) env->ThrowError("could not create file");
}
SaveRAW::~SaveRAW() {
file.close();
}
PVideoFrame __stdcall SaveRAW::GetFrame(int n, IScriptEnvironment* env) {
PVideoFrame src = child->GetFrame(n, env);
const unsigned char* srcp = src->GetReadPtr();
file.write((const char*)srcp, framesize);
return src;
}
AVSValue __cdecl Create_SaveRAW(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new SaveRAW(args[0].AsClip(), args[1].AsString(), env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("SaveRAW", "cs", Create_SaveRAW, 0);
return "`SaveRAW' SaveRAW plugin";
}
I'm trying to write the RAW video data (will be in YV12) to a file. The code creates the file, but for some reason doesn't write any data.
I guess I'm just making some stupid mistake, but I don't really have a clue about what it can be.
BTW I took part of this code from another filter, and this:
const unsigned char* srcp = src->GetReadPtr();
file.write((const char*)srcp, framesize);
seems a little strange to me: casting an unsigned char to a char, especially considering that GetReadPtr returns a byte.
Thanks in advance for any help.