Selur
21st July 2008, 14:47
Wrote a small c program to simply grab some infos from an avisynthscript and output them via command line.
Works fine, as long as I use a simple script like:
Avisource("test.avi")
but when using a scritp with AudioDub in it like:
video = AviSource("video.avi", false)
audio = wavSource("audio.wav")
return AudioDub(video,audio)
all the infos are reported but, the program does not terminate.
Attached the sourcecode and here's the code I wrote:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "internal.h"
#ifdef _MSC_VER
#define dup _dup
#define popen _popen
#define pclose _pclose
#define fdopen _fdopen
#define setmode _setmode
#else
#include <unistd.h>
#endif
#ifndef INT_MAX
#define INT_MAX 0x7fffffff
#endif
#define MY_VERSION "avsInfo"
#define MAX_FH 10
int __cdecl main(int argc, const char* argv[]){
const char* infile = NULL;
infile = argv[1];
const char *dot = strrchr(infile, '.');
if(!dot || strcmp(".avs", dot))
fprintf(stderr, "%s scheint kein AvisynthFile zu sein\n", infile);
try {
HMODULE avsdll = LoadLibrary("avisynth.dll");
if(!avsdll)
{fprintf(stderr, "avisynth.dll konnte nicht gefunden werden\n"); return 2;}
IScriptEnvironment* (* CreateScriptEnvironment)(int version)
= (IScriptEnvironment*(*)(int)) GetProcAddress(avsdll, "CreateScriptEnvironment");
if(!CreateScriptEnvironment)
{fprintf(stderr, "CreateScriptEnvironment() konnte nicht geladen werden\n"); return 1;}
IScriptEnvironment* env = CreateScriptEnvironment(AVISYNTH_INTERFACE_VERSION);
AVSValue arg(infile);
AVSValue res = env->Invoke("Import", AVSValue(&arg, 1));
if(!res.IsClip())
{fprintf(stderr, "Error: '%s' lieferte keine VideoInfos.\n", infile); return 1;}
PClip clip = res.AsClip();
VideoInfo inf = clip->GetVideoInfo();
fprintf(stderr, "%s:\n Aufloesung: %dx%d, ", infile, inf.width, inf.height);
if(inf.fps_denominator == 1)
fprintf(stderr, "Framerate: %d fps, ", inf.fps_numerator);
else
fprintf(stderr, "Framerate: %d/%d fps, ", inf.fps_numerator, inf.fps_denominator);
fprintf(stderr, "Laenge: %d frames\n", inf.num_frames);
if(inf.audio_samples_per_second != 0){
fprintf(stderr, "Audio:\n Samplerate: %d Hz, ", inf.audio_samples_per_second);
fprintf(stderr, "Anzahl an Channels:%d\n", inf.nchannels);
}
if(!inf.IsYV12())
{fprintf(stderr, "Nur Yv12 Input wird unterstützt!\n"); return 1;}
} catch(AvisynthError err) {
fprintf(stderr, "\nAvisynth error:\n%s\n", err.msg);
return 1;
}
fprintf(stderr, "ping");
return 0;
}
Did I miss something do I have to close/release something?
Would be nice if someone could point me in the right direction. :D
Cu Selur
Works fine, as long as I use a simple script like:
Avisource("test.avi")
but when using a scritp with AudioDub in it like:
video = AviSource("video.avi", false)
audio = wavSource("audio.wav")
return AudioDub(video,audio)
all the infos are reported but, the program does not terminate.
Attached the sourcecode and here's the code I wrote:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "internal.h"
#ifdef _MSC_VER
#define dup _dup
#define popen _popen
#define pclose _pclose
#define fdopen _fdopen
#define setmode _setmode
#else
#include <unistd.h>
#endif
#ifndef INT_MAX
#define INT_MAX 0x7fffffff
#endif
#define MY_VERSION "avsInfo"
#define MAX_FH 10
int __cdecl main(int argc, const char* argv[]){
const char* infile = NULL;
infile = argv[1];
const char *dot = strrchr(infile, '.');
if(!dot || strcmp(".avs", dot))
fprintf(stderr, "%s scheint kein AvisynthFile zu sein\n", infile);
try {
HMODULE avsdll = LoadLibrary("avisynth.dll");
if(!avsdll)
{fprintf(stderr, "avisynth.dll konnte nicht gefunden werden\n"); return 2;}
IScriptEnvironment* (* CreateScriptEnvironment)(int version)
= (IScriptEnvironment*(*)(int)) GetProcAddress(avsdll, "CreateScriptEnvironment");
if(!CreateScriptEnvironment)
{fprintf(stderr, "CreateScriptEnvironment() konnte nicht geladen werden\n"); return 1;}
IScriptEnvironment* env = CreateScriptEnvironment(AVISYNTH_INTERFACE_VERSION);
AVSValue arg(infile);
AVSValue res = env->Invoke("Import", AVSValue(&arg, 1));
if(!res.IsClip())
{fprintf(stderr, "Error: '%s' lieferte keine VideoInfos.\n", infile); return 1;}
PClip clip = res.AsClip();
VideoInfo inf = clip->GetVideoInfo();
fprintf(stderr, "%s:\n Aufloesung: %dx%d, ", infile, inf.width, inf.height);
if(inf.fps_denominator == 1)
fprintf(stderr, "Framerate: %d fps, ", inf.fps_numerator);
else
fprintf(stderr, "Framerate: %d/%d fps, ", inf.fps_numerator, inf.fps_denominator);
fprintf(stderr, "Laenge: %d frames\n", inf.num_frames);
if(inf.audio_samples_per_second != 0){
fprintf(stderr, "Audio:\n Samplerate: %d Hz, ", inf.audio_samples_per_second);
fprintf(stderr, "Anzahl an Channels:%d\n", inf.nchannels);
}
if(!inf.IsYV12())
{fprintf(stderr, "Nur Yv12 Input wird unterstützt!\n"); return 1;}
} catch(AvisynthError err) {
fprintf(stderr, "\nAvisynth error:\n%s\n", err.msg);
return 1;
}
fprintf(stderr, "ping");
return 0;
}
Did I miss something do I have to close/release something?
Would be nice if someone could point me in the right direction. :D
Cu Selur