Video Capture, Editing and Processing > Avisynth Development
AviSynth Plugin to drop undecodeable frames
(1/1)
may24:
Hi all,
I try to create a Aßvisynth Plugin that will drop the current frame when it is undecodeable and will only produce a green screen.
I'm very new to plugin devellopment, so I'm sorry in advance for the nubee questions.
This is my code so far:
--- Code: ---#include "windows.h"
#include "C:\Program Files (x86)\AviSynth 2.5\FilterSDK\include\avisynth.h"
class Broken : public GenericVideoFilter
{
Broken(PClip _child, IScriptEnvironment* env); // empty constructor
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};
Broken::Broken(PClip _child, IScriptEnvironment* env) : GenericVideoFilter(_child)
{
if (vi.IsPlanar()) // is input planar?
env->ThrowError("SimpleSample: input to filter must be in YUY2 or RGB");
}
PVideoFrame __stdcall Broken::GetFrame(int n, IScriptEnvironment *env)
{
PVideoFrame src = child->GetFrame(n, env);
if (vi.HasVideo)
return src;
}
--- End code ---
Since I don't know exactly how to detect such a broken frame, my first attempt was to check if the current frame has video at all. However I'm not sure if this will work or if I have to get through the whole (delivered) picture to test if everything is just green ???
Another problem is: When I try to compile the code I get:
--- Quote ---C:\Program Files (x86)\AviSynth 2.5\FilterSDK\include\avisynth.h|554|error: conflicting type attributes specified for 'virtual GenericVideoFilter::~GenericVideoFilter()'|
C:\Program Files (x86)\AviSynth 2.5\FilterSDK\include\avisynth.h|429|error: overriding 'virtual IClip::~IClip()'|
D:\Video\devel\DropBrokenFrames\main.cpp||In member function 'virtual PVideoFrame Broken::GetFrame(int, IScriptEnvironment*)':|
D:\Video\devel\DropBrokenFrames\main.cpp|20|error: could not convert '((Broken*)this)->Broken::<anonymous>.GenericVideoFilter::vi.VideoInfo::HasVideo' to 'bool'|
||=== Build finished: 3 errors, 0 warnings ===|
--- End quote ---
Any help would be highly arreciated ! :)
TheFluff:
what you're trying to do pretty much cannot be done in a filter that isn't the source filter itself, so have fun with that
Why not, you ask?
Pretty much all source filters just throw an exception when retrieving a frame fails, and once that happens it's game over and you can't do shit. You usually cannot restart decoding in a safe way once the exception is thrown, even if we presume that you actually manage to catch the exception in the first place (which in and of itself is decidedly nontrivial to do from inside a plugin, since most likely the script environment will catch the exception before you ever get to see it; you will need some serious C++ voodoo to catch it before someone else does, if it's even possible at all).
Assuming that you actually do manage to catch the exception, in many (most?) cases you'd either need to reinit the decoder and/or reopen the source file in order to restart decoding at the next frame in a safe way (since once the exception is thrown, all assumptions about the decoder state are completely useless), and you can't do that from inside another plugin.
Furthermore, you need to consider that most modern codecs use predictive or even bidirectionally predictive coding, which means that if decoding frame X fails, decoding all frames that depend on X (possibly the entire GOP, which is typically 2-300 frames) will also either fail completely, or succeed with serious artifacts.
edit: if you're actually trying to just drop frames that are green, and not detect actual decoding failures, then ignore the above. dropping green frames is relatively easy.
Navigation
[0] Message Index
Go to full version