#include #include #include #include #include "avisynth_c.h" typedef unsigned char byte; int main(int argc, const char * argv[]) { if (argc != 2) {puts("Need Source Video"); return 2;} AVS_ScriptEnvironment * env = avs_create_script_environment(AVISYNTH_INTERFACE_VERSION); AVS_Value arg0 = avs_new_value_string(argv[1]); AVS_Value args = avs_new_value_array(&arg0, 1); AVS_Value res = avs_invoke(env, "avisource", args, 0); if (avs_is_error(res)) { fputs(avs_as_string(res),stderr); fputc('\n', stderr); return 1;} arg0 = res; res = avs_invoke(env, "ConvertToYV12", args, 0); AVS_Clip * clip = avs_take_clip(res, env); avs_release_value(res); const AVS_VideoInfo * inf = avs_get_video_info(clip); FILE * out = fopen("y:\\res.yuv", "wb"); int out_fn = fileno(out); fputs("YUV4MPEG2 ", out); fprintf(out, "W%d ", inf->width); fprintf(out, "H%d ", inf->height); fprintf(out, "F%d:%d ", inf->fps_numerator, inf->fps_denominator); fputs("\n", out); fflush(out); for (int i = 0; i != inf->num_frames; ++i) { fprintf(stderr, "FRAME %d\n", i); fflush(stderr); AVS_VideoFrame * f = avs_get_frame(clip, i); write(out_fn, "FRAME \n", 7); const byte * d = avs_get_read_ptr(f); int pitch = avs_get_pitch(f); for (int y = 0; y != inf->height; ++y, d += pitch) write(out_fn, d, inf->width); d = avs_get_read_ptr_p(f, AVS_PLANAR_U); pitch = avs_get_pitch_p(f, AVS_PLANAR_U); for (int y = 0; y != inf->height/2; ++y, d += pitch) write(out_fn, d, inf->width/2); d = avs_get_read_ptr_p(f, AVS_PLANAR_V); pitch = avs_get_pitch_p(f, AVS_PLANAR_V); for (int y = 0; y != inf->height/2; ++y, d += pitch) write(out_fn, d, inf->width/2); avs_release_frame(f); } fclose(out); return 0; }