Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|
#21 | Link |
|
Moderator
![]() Join Date: Feb 2005
Location: Spain
Posts: 7,366
|
Maybe is easy to implement.
Now if the desired frame isn't the next the decoder is reset and search the desired frame: Code:
// Seek to the frame, if required
if (FrameIndex != _FrameIndex + 1)
{
// Reset decoder
if (State)
a52_free(State);
State = a52_init(Accel);
_fseeki64(Stream, StreamOffset + __int64(FrameIndex) * __int64(FrameLength), SEEK_SET);
}
// Read the frame
if (!ReadFrame())
env->ThrowError("m2AudioAC3Source: error in file \"%s\"", StreamName);
Code:
// Seek to the frame, if required
if (FrameIndex != _FrameIndex + 1)
{
// Reset decoder
if (State)
a52_free(State);
State = a52_init(Accel);
if (FrameIndex == 0)
_fseeki64(Stream, StreamOffset, SEEK_SET);
else
{
_fseeki64(Stream, StreamOffset + __int64(FrameIndex - 1) * __int64(FrameLength), SEEK_SET);
// Read previous frame to initialize the desired frame
if (!ReadFrame())
env->ThrowError("m2AudioAC3Source: error in file \"%s\"", StreamName);
}
}
// Read the frame
if (!ReadFrame())
env->ThrowError("m2AudioAC3Source: error in file \"%s\"", StreamName);
Only ac3 decoder changed, I will see if others decoders need changes. This is the first release I encode with C++ Express 2010, I hope all is OK. New release NicAudio.dll v2.0.6 with ac3 and dts decoders changed: Last edited by tebasuna51; 30th August 2012 at 21:58. Reason: add a new official release |
|
|
|
|
|
#23 | Link | |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Looks like tebasuna51 will have sorted you out, but as I had already written below code, I thought
I'de post it anyway, it is roughly what you were wanting ToDo, compiles but untested. Code:
#include <windows.h>
#include "avisynth.h"
class preroll : public GenericVideoFilter {
__int64 A_ms; // Default 20 milli secs worth of audio samples
__int64 prev; // last audio sample previously fetched.
public:
preroll(PClip _child,int _ms, IScriptEnvironment* env);
void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env);
~preroll(){};
};
preroll::preroll(PClip _child,int _ms, IScriptEnvironment* env) : GenericVideoFilter(_child) {
if(!vi.HasAudio()) env->ThrowError("Preroll: requires Audio");
A_ms = (__int64)(vi.SamplesPerSecond() * (0.001 * _ms) + 0.5); // _ms milli secs worth of audio
prev = -1; // Init to 'never'
}
void __stdcall preroll::GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) {
// start and count are in multichannel samples, and 'start' is beginning of requested output samples to store @ buf.
if(count > 0) { // count condition avoids infinite loop and No Store of invalid prev
// If not first frame and audio seek since previous fetch, prefetch audio prior to requested audio
if(start > 0 && prev != start - 1) {
__int64 prefetch = A_ms; // Prefetch (default 20) milli secs worth of audio samples
if(prefetch > start) // Cannot prefetch prior zero
prefetch = start;
__int64 s = start - prefetch;
do { // loop is just in case count < prefetch size, most likely 1 iteration only.
__int64 tcount = prefetch;
if(tcount > count)
tcount = count; // but limit to max count, known buffer size
child->GetAudio(buf, s, tcount, env); // now prefetch audio
s += tcount;
prefetch -= tcount;
} while (prefetch > 0);
}
child->GetAudio(buf, start, count, env); // now get the requested audio
prev = start + count - 1; // store last sample fetched for next time.
}
}
AVSValue __cdecl Create_preroll(AVSValue args, void* user_data, IScriptEnvironment* env) {
int ms = args[1].AsInt(20); // Default 20 ms prefetch
if(ms<1) ms=1; // Minimum 1 milli sec
return new preroll(args[0].AsClip(),ms,env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("Preroll", "c[PrefetchMS]i", Create_preroll, 0);
return "`Preroll' Preroll plugin";
}
EDIT: Quote:
I would think a single instance immediately after each problematic audio source filter would suffice (on v2.6a3) EDIT: From memories of when last (and first) I played with audio (Prune), the count number of samples seem to be unrelated to the approx audio samples for a video frame, I seem to recall the number 60,000 samples in a typical request but may be wrong on that, perhaps totally down to eg Vdub or Mplayer. Also, the sample size is dependant on number of channels and type eg int16, int32 float. Also note, the frames referred to in tebasuna51 code are audio frames not video, audio source filters of course have no idea about video frames. EDIT: Actually usual 6000 samples request.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 31st August 2012 at 11:28. |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|