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

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th August 2012, 21:57   #21  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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);
But we can read the previous frame first:
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);
Please check the new NicAudio.dll.
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:
Attached Files
File Type: 7z NicAudio_206.7z (167.9 KB, 1231 views)

Last edited by tebasuna51; 30th August 2012 at 21:58. Reason: add a new official release
tebasuna51 is offline   Reply With Quote
Old 16th August 2012, 22:51   #22  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,816
Quote:
Originally Posted by tebasuna51 View Post
Maybe is easy to implement.

Please check the new NicAudio.dll.
That seems to fix the problem too - thanks!

David
wonkey_monkey is offline   Reply With Quote
Old 16th August 2012, 22:55   #23  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
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: Above Code Edited, removed reliance on Video frame duration, added PrefetchMS arg, default 20(ms).

EDIT:
Quote:
Originally Posted by davidhorman View Post
To do: skip the pre-fetch if that previous frame was the last "current" frame (may not be possible with multiple instances of the filter running)
Data members are local to an individual filter instance (unless defined 'static'), so there are no conflicts with the 'prev' variable.
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.
StainlessS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:48.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.