-
Notifications
You must be signed in to change notification settings - Fork 3
/
avisynthUtil.h
88 lines (68 loc) · 2.22 KB
/
avisynthUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
* This file is part of AvsVCEh264.
* Contains functions for working with avisynth
*
* AvsVCEh264 inspired by avs2pipe by Chris Beswick
*
* Copyright (C) 2013 David González García <[email protected]>
*******************************************************************************/
#include <stdio.h>
#include "avisynth_c.h"
AVS_ScriptEnvironment *env;
AVS_Clip *clip;
const AVS_VideoInfo *info = 0;
AVS_Clip* avisynth_filter(AVS_Clip *clip, AVS_ScriptEnvironment *env, const char *filter)
{
AVS_Value val_clip, val_array, val_return;
val_clip = avs_new_value_clip(clip);
avs_release_clip(clip);
val_array = avs_new_value_array(&val_clip, 1);
val_return = avs_invoke(env, filter, val_array, 0);
clip = avs_take_clip(val_return, env);
avs_release_value(val_array);
avs_release_value(val_clip);
avs_release_value(val_return);
return clip;
}
AVS_Clip* avisynth_source(char *file, AVS_ScriptEnvironment *env)
{
AVS_Clip *clip;
AVS_Value val_string, val_array, val_return;
val_string = avs_new_value_string(file);
val_array = avs_new_value_array(&val_string, 1);
val_return = avs_invoke(env, "Import", val_array, 0);
avs_release_value(val_array);
avs_release_value(val_string);
if (!avs_is_clip(val_return))
{
fprintf(stderr, "avs files return value is not a clip.\n");
return 0;
}
clip = avs_take_clip(val_return, env);
avs_release_value(val_return);
return clip;
}
bool AVS_Init(char *inFile)
{
env = avs_create_script_environment(AVISYNTH_INTERFACE_VERSION);
clip = avisynth_source(inFile, env);
info = avs_get_video_info(clip);
if (!avs_has_video(info))
{
fprintf(stderr, "Clip has no video.\n");
return false;
}
// ensure video is yv12
if (avs_has_video(info) && !avs_is_yv12(info))
{
fprintf(stderr, "Converting video to yv12.\n");
clip = avisynth_filter(clip, env, "ConvertToYV12");
info = avs_get_video_info(clip);
if (!avs_is_yv12(info))
{
fprintf(stderr, "Failed to convert video to yv12.\n");
return false;
}
}
return true;
}