Avisynth 3.0 C Interface

Version:
0.1
Author:
Vincent Torri < vtorri at univ-evry dot fr >
Date:
2006

Summary

Introduction

Avisynth 3.0 is a powerful frameserver for Windows and Linux. It aims at editing and processing videos in a non linear manner. It is written in C++, but a C API is provided, for those who do not like this language.

This document presents the complete C API and a general presentation on how to use it

Presentation

This API has been used (and actually written) for the test application that is provided with avisynth. It is usually sufficient for the most common use of avisynth when writing a program, that is: reading a script.

The general use of this API is:

It is then easy to create an input for programs like x264 or gstreamer. We now give two usefull examples of the use of this API.

How to get informations of a clip

As mentioned above, it is sufficient to get an environment, a clip, the AVS_VideoInfo of this clip, and use the API to get inforations about the clip:

#include <stdio.h>

int
main (int argc, char *argv[])
{
  Avs_Environment *p_env;
  Avs_Clip        *p_clip;
  AVS_VideoInfo   *p_vi;

  if (argc < 2) {
    printf ("Usage: %s file.avs\n", argv[0]);
    return 0;
  }

  p_env = avs_environment_new (1000000);
  if (!p_env)
    goto quit;

  p_clip = avs_clip_new_from_file (argv[1]);
  if (!p_clip)
    goto free_env;

  p_vi = avs_clip_videoinfo_get (p_clip);
  if (!p_vi)
    goto free_clip;

  if (avs_videoinfo_has_video (p_vi) {
    AVS_ColorSpace *p_csp;

    printf ("size.........: %dx%d\n",
            avs_videoinfo_width_get (p_vi),
            avs_videoinfo_height_get (p_vi));
    printf ("frame count..: %d\n",
            avs_videoinfo_framecount_get (p_vi));
    printf ("frame ratet..: %d/%d\n",
            avs_videoinfo_fps_numerator_get (p_vi),
            avs_videoinfo_fps_denominator_get (p_vi));
    p_csp = avs_videoinfo_colorspace_get (p_vi);
    if (p_csp) {
      printf ("colorspace...: ");
      switch (avs_colorspace_id_get (p_csp)) {
      case I_RGB32:
        printf ("RGB32\n");
        break;
      case I_YV12:
        printf ("YV12\n");
        break;
      default:
        printf ("Other (too lazy to list all of them)\n");
        break;
      }
      avs_colorspace_delete (p_csp);
    }
  }
  else {
    printf ("No video stream\n");
  }

  avs_videoinfo_delete (p_vi);
 free_clip:
  avs_clip_delete (p_clip);
 free_env:
  avs_environment_delete (p_env);
 quit:
  return 0;
}

How to get raw data of a video stream

Again, it is sufficient to get an environment, a clip, the AVS_VideoFrame of a plane of this clip, and use the API to get the raw data of the plane. We suppose here that the colorspace of the video stream is RGB32:

#include <stdio.h>

int
main (int argc, char *argv[])
{
  Avs_Environment *p_env;
  Avs_Clip        *p_clip;
  AVS_VideoInfo   *p_vi;
  AVS_VideoFrame  *p_vf;

  if (argc < 2) {
    printf ("Usage: %s file.avs\n", argv[0]);
    return 0;
  }

  p_env = avs_environment_new (1000000);
  if (!p_env)
    goto quit;

  p_clip = avs_clip_new_from_file (argv[1]);
  if (!p_clip)
    goto free_env;

  p_vi = avs_clip_videoinfo_get (p_clip);
  if (!p_vi)
    goto free_clip;

  p_vf = avs_clip_videoframe_get (p_clip);
  if (!p_vf)
    goto free_videoinfo;

  if (avs_videoinfo_has_video (p_vi) {
    AVS_ColorSpace *p_csp;
    unsigned char  *data = NULL;

    p_csp = avs_videoinfo_colorspace_get (p_vi);
    if (p_csp) {
      if (avs_colorspace_id_get (p_csp) == I_RGB32) {
        data = avs_videoframe_plane_get ('~');

        avs_colorspace_delete (p_csp);
      }
    }
  }
  else {
    printf ("No video stream\n");
  }

  avs_videoframe_delete (p_vf);
 free_videoinfo:
  avs_videoinfo_delete (p_vi);
 free_clip:
  avs_clip_delete (p_clip);
 free_env:
  avs_environment_delete (p_env);
 quit:
  return 0;
}

API


Generated on Sun Jul 30 18:46:52 2006 for Avisynth by  doxygen 1.4.7