Skip to content

Commit

Permalink
[tinyPy] Extend API
Browse files Browse the repository at this point in the history
This adds methods getCurrentPts(), getPrevKFramePts() and getNextKFramePts() to pyEditor and seekKeyFrame(int) to pyAdm to allow to query the PTS of the current frame, the PTS of the previous or the next keyframe and to seek to keyframes relative to the current position.
  • Loading branch information
eumagga0x2a committed Mar 26, 2020
1 parent 1cd92ad commit e1f4716
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
31 changes: 31 additions & 0 deletions avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,37 @@ double pyGetDts(IEditor *editor, int frameNum)

return (double)dts;
}

/**
\fn pyGetPrevKFramePts
*/
double pyGetPrevKFramePts(IEditor *editor)
{
uint64_t pts = editor->getCurrentFramePts();
if(pts == ADM_NO_PTS)
return -1;

if(false == editor->getPKFramePTS(&pts))
return -1;

return (double)pts;
}

/**
\fn pyGetNextKFramePts
*/
double pyGetNextKFramePts(IEditor *editor)
{
uint64_t pts = editor->getCurrentFramePts();
if(pts == ADM_NO_PTS)
return -1;

if(false == editor->getNKFramePTS(&pts))
return -1;

return (double)pts;
}

/**
\fn pyFileSelWrite
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bool pyHexDumpFrame(IEditor *editor, int framenumber);
int pyPrintTiming(IEditor *editor, int framenumber);
double pyGetPts(IEditor *editor, int frameNum);
double pyGetDts(IEditor *editor, int frameNum);
double pyGetPrevKFramePts(IEditor *editor);
double pyGetNextKFramePts(IEditor *editor);

/* File operation */
char *pyFileSelWrite(IEditor *editor, const char *title);
Expand Down
18 changes: 18 additions & 0 deletions avidemux_plugins/ADM_scriptEngines/tinyPy/src/adm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,19 @@ static tp_obj zzpy_audioChannels(TP)
int r = pyGetAudioChannels(p0,p1);
return tp_number(r);
}
// seekKeyFrame -> void editor->seekKeyFrame (int )
static tp_obj zzpy_seekKeyFrame(TP)
{
tp_obj self = tp_getraw(tp);
IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val;
IEditor *editor = engine->editor();
TinyParams pm(tp);
void *me = (void *)pm.asThis(&self, ADM_PYID_AVIDEMUX);

int p0 = pm.asInt();
editor->seekKeyFrame(p0);
return tp_None;
}
tp_obj zzpy__pyAdm_get(tp_vm *vm)
{
tp_obj self = tp_getraw(vm);
Expand Down Expand Up @@ -772,6 +785,10 @@ tp_obj zzpy__pyAdm_get(tp_vm *vm)
{
return tp_method(vm, self, zzpy_audioChannels);
}
if (!strcmp(key, "seekKeyFrame"))
{
return tp_method(vm, self, zzpy_seekKeyFrame);
}
return tp_get(vm, self, tp_string(key));
}
tp_obj zzpy__pyAdm_set(tp_vm *vm)
Expand Down Expand Up @@ -857,6 +874,7 @@ static tp_obj zzpy__pyAdm_help(TP)
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioAddExternal(IEditor,str)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioSetPal2Film(IEditor,int,int)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioChannels(IEditor, int)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "seekKeyFrame(int)\n");

return tp_None;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#
#
# Seek
#/* METHOD */ int A_saveImg:saveBmp(str)
/* METHOD */ void editor->seekKeyFrame:seekKeyFrame(int)
#
# Variables
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/* CLASS */ pyEditor : void : ADM_PYID_EDITOR
/* METHOD */ double pyGetPts:getPts (int)
/* METHOD */ double pyGetDts:getDts (int)
/* METHOD */ double editor->getCurrentFramePts:getCurrentPts (void)
/* METHOD */ double pyGetPrevKFramePts:getPrevKFramePts (void)
/* METHOD */ double pyGetNextKFramePts:getNextKFramePts (void)
/* METHOD */ int pyPrintTiming:printTiming (int)
/* METHOD */ int editor->getNbSegment:nbSegments (void)
/* METHOD */ void editor->dumpSegments:dumpAllSegments (void)
Expand Down
53 changes: 53 additions & 0 deletions avidemux_plugins/ADM_scriptEngines/tinyPy/src/editor_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,44 @@ static tp_obj zzpy_getPts(TP)
double r = pyGetPts(p0,p1);
return tp_number(r);
}
// getCurrentPts -> double editor->getCurrentFramePts (void )
static tp_obj zzpy_getCurrentPts(TP)
{
tp_obj self = tp_getraw(tp);
IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val;
IEditor *editor = engine->editor();
TinyParams pm(tp);
void *me = (void *)pm.asThis(&self, ADM_PYID_EDITOR);

double r = editor->getCurrentFramePts();
return tp_number(r);
}
// getPrevKFramePts -> double pyGetPrevKFramePts (IEditor )
static tp_obj zzpy_getPrevKFramePts(TP)
{
tp_obj self = tp_getraw(tp);
IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val;
IEditor *editor = engine->editor();
TinyParams pm(tp);
void *me = (void *)pm.asThis(&self, ADM_PYID_EDITOR);

IEditor *p0 = editor;
double r = pyGetPrevKFramePts(p0);
return tp_number(r);
}
// getNextKFramePts -> double pyGetNextKFramePts (IEditor )
static tp_obj zzpy_getNextKFramePts(TP)
{
tp_obj self = tp_getraw(tp);
IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val;
IEditor *editor = engine->editor();
TinyParams pm(tp);
void *me = (void *)pm.asThis(&self, ADM_PYID_EDITOR);

IEditor *p0 = editor;
double r = pyGetNextKFramePts(p0);
return tp_number(r);
}
// getVideoDuration -> double editor->getVideoDuration (void )
static tp_obj zzpy_getVideoDuration(TP)
{
Expand Down Expand Up @@ -170,6 +208,18 @@ tp_obj zzpy__pyEditor_get(tp_vm *vm)
{
return tp_method(vm, self, zzpy_getPts);
}
if (!strcmp(key, "getCurrentPts"))
{
return tp_method(vm, self, zzpy_getCurrentPts);
}
if (!strcmp(key, "getPrevKFramePts"))
{
return tp_method(vm, self, zzpy_getPrevKFramePts);
}
if (!strcmp(key, "getNextKFramePts"))
{
return tp_method(vm, self, zzpy_getNextKFramePts);
}
if (!strcmp(key, "getVideoDuration"))
{
return tp_method(vm, self, zzpy_getVideoDuration);
Expand Down Expand Up @@ -230,6 +280,9 @@ static tp_obj zzpy__pyEditor_help(TP)
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "hexDumpFrame(IEditor,int)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getDts(IEditor,int)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getPts(IEditor,int)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getCurrentPts(void)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getPrevKFramePts(IEditor)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getNextKFramePts(IEditor)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "getVideoDuration(void)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "nextFrame(IEditor)\n");
engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "dumpRefVideo(void)\n");
Expand Down

0 comments on commit e1f4716

Please sign in to comment.