FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avisynth.c
Go to the documentation of this file.
1 /*
2  * AviSynth/AvxSynth support
3  * Copyright (c) 2012 AvxSynth Team.
4  *
5  * This file is part of FFmpeg
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/internal.h"
22 #include "libavcodec/internal.h"
23 #include "avformat.h"
24 #include "internal.h"
25 #include "config.h"
26 
27 /* Enable function pointer definitions for runtime loading. */
28 #define AVSC_NO_DECLSPEC
29 
30 /* Platform-specific directives for AviSynth vs AvxSynth. */
31 #ifdef _WIN32
32  #include <windows.h>
33  #undef EXTERN_C
35  #define AVISYNTH_LIB "avisynth"
36  #define USING_AVISYNTH
37 #else
38  #include <dlfcn.h>
40  #define AVISYNTH_NAME "libavxsynth"
41  #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
42 
43  #define LoadLibrary(x) dlopen(x, RTLD_NOW | RTLD_LOCAL)
44  #define GetProcAddress dlsym
45  #define FreeLibrary dlclose
46 #endif
47 
48 typedef struct AviSynthLibrary {
49  void *library;
50 #define AVSC_DECLARE_FUNC(name) name ## _func name
51  AVSC_DECLARE_FUNC(avs_bit_blt);
52  AVSC_DECLARE_FUNC(avs_clip_get_error);
53  AVSC_DECLARE_FUNC(avs_create_script_environment);
54  AVSC_DECLARE_FUNC(avs_delete_script_environment);
55  AVSC_DECLARE_FUNC(avs_get_audio);
56  AVSC_DECLARE_FUNC(avs_get_error);
57  AVSC_DECLARE_FUNC(avs_get_frame);
58  AVSC_DECLARE_FUNC(avs_get_version);
59  AVSC_DECLARE_FUNC(avs_get_video_info);
60  AVSC_DECLARE_FUNC(avs_invoke);
61  AVSC_DECLARE_FUNC(avs_release_clip);
62  AVSC_DECLARE_FUNC(avs_release_value);
63  AVSC_DECLARE_FUNC(avs_release_video_frame);
64  AVSC_DECLARE_FUNC(avs_take_clip);
65 #ifdef USING_AVISYNTH
71  AVSC_DECLARE_FUNC(avs_is_yv24);
72  AVSC_DECLARE_FUNC(avs_is_yv16);
73  AVSC_DECLARE_FUNC(avs_is_yv411);
74  AVSC_DECLARE_FUNC(avs_is_y8);
75 #endif
76 #undef AVSC_DECLARE_FUNC
78 
79 typedef struct AviSynthContext {
82  const AVS_VideoInfo *vi;
83 
84  /* avisynth_read_packet_video() iterates over this. */
85  int n_planes;
86  const int *planes;
87 
90  int64_t curr_sample;
91 
92  int error;
93 
94  /* Linked list pointers. */
97 
98 static const int avs_planes_packed[1] = { 0 };
99 static const int avs_planes_grey[1] = { AVS_PLANAR_Y };
100 static const int avs_planes_yuv[3] = { AVS_PLANAR_Y, AVS_PLANAR_U,
101  AVS_PLANAR_V };
102 
103 /* A conflict between C++ global objects, atexit, and dynamic loading requires
104  * us to register our own atexit handler to prevent double freeing. */
106 static int avs_atexit_called = 0;
107 
108 /* Linked list of AviSynthContexts. An atexit handler destroys this list. */
110 
111 static av_cold void avisynth_atexit_handler(void);
112 
114 {
115  avs_library.library = LoadLibrary(AVISYNTH_LIB);
116  if (!avs_library.library)
117  return AVERROR_UNKNOWN;
118 
119 #define LOAD_AVS_FUNC(name, continue_on_fail) \
120  avs_library.name = \
121  (void *)GetProcAddress(avs_library.library, #name); \
122  if (!continue_on_fail && !avs_library.name) \
123  goto fail;
124 
125  LOAD_AVS_FUNC(avs_bit_blt, 0);
126  LOAD_AVS_FUNC(avs_clip_get_error, 0);
127  LOAD_AVS_FUNC(avs_create_script_environment, 0);
128  LOAD_AVS_FUNC(avs_delete_script_environment, 0);
129  LOAD_AVS_FUNC(avs_get_audio, 0);
130  LOAD_AVS_FUNC(avs_get_error, 1); // New to AviSynth 2.6
131  LOAD_AVS_FUNC(avs_get_frame, 0);
132  LOAD_AVS_FUNC(avs_get_version, 0);
133  LOAD_AVS_FUNC(avs_get_video_info, 0);
134  LOAD_AVS_FUNC(avs_invoke, 0);
135  LOAD_AVS_FUNC(avs_release_clip, 0);
136  LOAD_AVS_FUNC(avs_release_value, 0);
137  LOAD_AVS_FUNC(avs_release_video_frame, 0);
138  LOAD_AVS_FUNC(avs_take_clip, 0);
139 #ifdef USING_AVISYNTH
145  LOAD_AVS_FUNC(avs_is_yv24, 1);
146  LOAD_AVS_FUNC(avs_is_yv16, 1);
147  LOAD_AVS_FUNC(avs_is_yv411, 1);
148  LOAD_AVS_FUNC(avs_is_y8, 1);
149 #endif
150 #undef LOAD_AVS_FUNC
151 
152  atexit(avisynth_atexit_handler);
153  return 0;
154 
155 fail:
156  FreeLibrary(avs_library.library);
157  return AVERROR_UNKNOWN;
158 }
159 
160 /* Note that avisynth_context_create and avisynth_context_destroy
161  * do not allocate or free the actual context! That is taken care of
162  * by libavformat. */
164 {
165  AviSynthContext *avs = s->priv_data;
166  int ret;
167 
168  if (!avs_library.library)
169  if (ret = avisynth_load_library())
170  return ret;
171 
172  avs->env = avs_library.avs_create_script_environment(3);
173  if (avs_library.avs_get_error) {
174  const char *error = avs_library.avs_get_error(avs->env);
175  if (error) {
176  av_log(s, AV_LOG_ERROR, "%s\n", error);
177  return AVERROR_UNKNOWN;
178  }
179  }
180 
181  if (!avs_ctx_list) {
182  avs_ctx_list = avs;
183  } else {
184  avs->next = avs_ctx_list;
185  avs_ctx_list = avs;
186  }
187 
188  return 0;
189 }
190 
192 {
193  if (avs_atexit_called)
194  return;
195 
196  if (avs == avs_ctx_list) {
197  avs_ctx_list = avs->next;
198  } else {
200  while (prev->next != avs)
201  prev = prev->next;
202  prev->next = avs->next;
203  }
204 
205  if (avs->clip) {
206  avs_library.avs_release_clip(avs->clip);
207  avs->clip = NULL;
208  }
209  if (avs->env) {
210  avs_library.avs_delete_script_environment(avs->env);
211  avs->env = NULL;
212  }
213 }
214 
216 {
218 
219  while (avs) {
220  AviSynthContext *next = avs->next;
222  avs = next;
223  }
224  FreeLibrary(avs_library.library);
225 
226  avs_atexit_called = 1;
227 }
228 
229 /* Create AVStream from audio and video data. */
231 {
232  AviSynthContext *avs = s->priv_data;
233  int planar = 0; // 0: packed, 1: YUV, 2: Y8
234 
237  st->codecpar->width = avs->vi->width;
238  st->codecpar->height = avs->vi->height;
239 
240  st->avg_frame_rate = (AVRational) { avs->vi->fps_numerator,
241  avs->vi->fps_denominator };
242  st->start_time = 0;
243  st->duration = avs->vi->num_frames;
244  st->nb_frames = avs->vi->num_frames;
245  avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, avs->vi->fps_numerator);
246 
247  switch (avs->vi->pixel_type) {
248 #ifdef USING_AVISYNTH
249  case AVS_CS_YV24:
251  planar = 1;
252  break;
253  case AVS_CS_YV16:
255  planar = 1;
256  break;
257  case AVS_CS_YV411:
259  planar = 1;
260  break;
261  case AVS_CS_Y8:
263  planar = 2;
264  break;
265 #endif
266  case AVS_CS_BGR24:
268  break;
269  case AVS_CS_BGR32:
271  break;
272  case AVS_CS_YUY2:
274  break;
275  case AVS_CS_YV12:
277  planar = 1;
278  break;
279  case AVS_CS_I420: // Is this even used anywhere?
281  planar = 1;
282  break;
283  default:
284  av_log(s, AV_LOG_ERROR,
285  "unknown AviSynth colorspace %d\n", avs->vi->pixel_type);
286  avs->error = 1;
287  return AVERROR_UNKNOWN;
288  }
289 
290  switch (planar) {
291  case 2: // Y8
292  avs->n_planes = 1;
293  avs->planes = avs_planes_grey;
294  break;
295  case 1: // YUV
296  avs->n_planes = 3;
297  avs->planes = avs_planes_yuv;
298  break;
299  default:
300  avs->n_planes = 1;
301  avs->planes = avs_planes_packed;
302  }
303  return 0;
304 }
305 
307 {
308  AviSynthContext *avs = s->priv_data;
309 
312  st->codecpar->channels = avs->vi->nchannels;
313  st->duration = avs->vi->num_audio_samples;
315 
316  switch (avs->vi->sample_type) {
317  case AVS_SAMPLE_INT8:
319  break;
320  case AVS_SAMPLE_INT16:
322  break;
323  case AVS_SAMPLE_INT24:
325  break;
326  case AVS_SAMPLE_INT32:
328  break;
329  case AVS_SAMPLE_FLOAT:
331  break;
332  default:
333  av_log(s, AV_LOG_ERROR,
334  "unknown AviSynth sample type %d\n", avs->vi->sample_type);
335  avs->error = 1;
336  return AVERROR_UNKNOWN;
337  }
338  return 0;
339 }
340 
342 {
343  AviSynthContext *avs = s->priv_data;
344  AVStream *st;
345  int ret;
346  int id = 0;
347 
348  if (avs_has_video(avs->vi)) {
349  st = avformat_new_stream(s, NULL);
350  if (!st)
351  return AVERROR_UNKNOWN;
352  st->id = id++;
353  if (ret = avisynth_create_stream_video(s, st))
354  return ret;
355  }
356  if (avs_has_audio(avs->vi)) {
357  st = avformat_new_stream(s, NULL);
358  if (!st)
359  return AVERROR_UNKNOWN;
360  st->id = id++;
361  if (ret = avisynth_create_stream_audio(s, st))
362  return ret;
363  }
364  return 0;
365 }
366 
368 {
369  AviSynthContext *avs = s->priv_data;
370  AVS_Value arg, val;
371  int ret;
372 #ifdef USING_AVISYNTH
373  char filename_ansi[MAX_PATH * 4];
374  wchar_t filename_wc[MAX_PATH * 4];
375 #endif
376 
377  if (ret = avisynth_context_create(s))
378  return ret;
379 
380 #ifdef USING_AVISYNTH
381  /* Convert UTF-8 to ANSI code page */
382  MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc, MAX_PATH * 4);
383  WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
384  MAX_PATH * 4, NULL, NULL);
385  arg = avs_new_value_string(filename_ansi);
386 #else
387  arg = avs_new_value_string(s->filename);
388 #endif
389  val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
390  if (avs_is_error(val)) {
391  av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val));
392  ret = AVERROR_UNKNOWN;
393  goto fail;
394  }
395  if (!avs_is_clip(val)) {
396  av_log(s, AV_LOG_ERROR, "AviSynth script did not return a clip\n");
397  ret = AVERROR_UNKNOWN;
398  goto fail;
399  }
400 
401  avs->clip = avs_library.avs_take_clip(val, avs->env);
402  avs->vi = avs_library.avs_get_video_info(avs->clip);
403 
404 #ifdef USING_AVISYNTH
405  /* On Windows, FFmpeg supports AviSynth interface version 6 or higher.
406  * This includes AviSynth 2.6 RC1 or higher, and AviSynth+ r1718 or higher,
407  * and excludes 2.5 and the 2.6 alphas. Since AvxSynth identifies itself
408  * as interface version 3 like 2.5.8, this needs to be special-cased. */
409 
410  if (avs_library.avs_get_version(avs->clip) < 6) {
411  av_log(s, AV_LOG_ERROR,
412  "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
413  ret = AVERROR_UNKNOWN;
414  goto fail;
415  }
416 #endif
417 
418  /* Release the AVS_Value as it will go out of scope. */
419  avs_library.avs_release_value(val);
420 
421  if (ret = avisynth_create_stream(s))
422  goto fail;
423 
424  return 0;
425 
426 fail:
428  return ret;
429 }
430 
432  AVPacket *pkt, int *discard)
433 {
434  AviSynthContext *avs = s->priv_data;
435 
436  avs->curr_stream++;
437  avs->curr_stream %= s->nb_streams;
438 
439  *st = s->streams[avs->curr_stream];
440  if ((*st)->discard == AVDISCARD_ALL)
441  *discard = 1;
442  else
443  *discard = 0;
444 
445  return;
446 }
447 
448 /* Copy AviSynth clip data into an AVPacket. */
450  int discard)
451 {
452  AviSynthContext *avs = s->priv_data;
454  unsigned char *dst_p;
455  const unsigned char *src_p;
456  int n, i, plane, rowsize, planeheight, pitch, bits;
457  const char *error;
458 
459  if (avs->curr_frame >= avs->vi->num_frames)
460  return AVERROR_EOF;
461 
462  /* This must happen even if the stream is discarded to prevent desync. */
463  n = avs->curr_frame++;
464  if (discard)
465  return 0;
466 
467 #ifdef USING_AVISYNTH
468  /* Define the bpp values for the new AviSynth 2.6 colorspaces.
469  * Since AvxSynth doesn't have these functions, special-case
470  * it in order to avoid implicit declaration errors. */
471 
472  if (avs_library.avs_is_yv24(avs->vi))
473  bits = 24;
474  else if (avs_library.avs_is_yv16(avs->vi))
475  bits = 16;
476  else if (avs_library.avs_is_yv411(avs->vi))
477  bits = 12;
478  else if (avs_library.avs_is_y8(avs->vi))
479  bits = 8;
480  else
481  bits = avs_library.avs_bits_per_pixel(avs->vi);
482 #else
483  bits = avs_bits_per_pixel(avs->vi);
484 #endif
485 
486  /* Without the cast to int64_t, calculation overflows at about 9k x 9k
487  * resolution. */
488  pkt->size = (((int64_t)avs->vi->width *
489  (int64_t)avs->vi->height) * bits) / 8;
490  if (!pkt->size)
491  return AVERROR_UNKNOWN;
492 
493  if (av_new_packet(pkt, pkt->size) < 0)
494  return AVERROR(ENOMEM);
495 
496  pkt->pts = n;
497  pkt->dts = n;
498  pkt->duration = 1;
499  pkt->stream_index = avs->curr_stream;
500 
501  frame = avs_library.avs_get_frame(avs->clip, n);
502  error = avs_library.avs_clip_get_error(avs->clip);
503  if (error) {
504  av_log(s, AV_LOG_ERROR, "%s\n", error);
505  avs->error = 1;
506  av_packet_unref(pkt);
507  return AVERROR_UNKNOWN;
508  }
509 
510  dst_p = pkt->data;
511  for (i = 0; i < avs->n_planes; i++) {
512  plane = avs->planes[i];
513 #ifdef USING_AVISYNTH
514  src_p = avs_library.avs_get_read_ptr_p(frame, plane);
515  pitch = avs_library.avs_get_pitch_p(frame, plane);
516 
517  rowsize = avs_library.avs_get_row_size_p(frame, plane);
518  planeheight = avs_library.avs_get_height_p(frame, plane);
519 #else
520  src_p = avs_get_read_ptr_p(frame, plane);
521  pitch = avs_get_pitch_p(frame, plane);
522 
523  rowsize = avs_get_row_size_p(frame, plane);
524  planeheight = avs_get_height_p(frame, plane);
525 #endif
526 
527  /* Flip RGB video. */
528  if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) {
529  src_p = src_p + (planeheight - 1) * pitch;
530  pitch = -pitch;
531  }
532 
533  avs_library.avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch,
534  rowsize, planeheight);
535  dst_p += rowsize * planeheight;
536  }
537 
538  avs_library.avs_release_video_frame(frame);
539  return 0;
540 }
541 
543  int discard)
544 {
545  AviSynthContext *avs = s->priv_data;
546  AVRational fps, samplerate;
547  int samples;
548  int64_t n;
549  const char *error;
550 
551  if (avs->curr_sample >= avs->vi->num_audio_samples)
552  return AVERROR_EOF;
553 
554  fps.num = avs->vi->fps_numerator;
555  fps.den = avs->vi->fps_denominator;
556  samplerate.num = avs->vi->audio_samples_per_second;
557  samplerate.den = 1;
558 
559  if (avs_has_video(avs->vi)) {
560  if (avs->curr_frame < avs->vi->num_frames)
561  samples = av_rescale_q(avs->curr_frame, samplerate, fps) -
562  avs->curr_sample;
563  else
564  samples = av_rescale_q(1, samplerate, fps);
565  } else {
566  samples = 1000;
567  }
568 
569  /* After seeking, audio may catch up with video. */
570  if (samples <= 0) {
571  pkt->size = 0;
572  pkt->data = NULL;
573  return 0;
574  }
575 
576  if (avs->curr_sample + samples > avs->vi->num_audio_samples)
577  samples = avs->vi->num_audio_samples - avs->curr_sample;
578 
579  /* This must happen even if the stream is discarded to prevent desync. */
580  n = avs->curr_sample;
581  avs->curr_sample += samples;
582  if (discard)
583  return 0;
584 
585  pkt->size = avs_bytes_per_channel_sample(avs->vi) *
586  samples * avs->vi->nchannels;
587  if (!pkt->size)
588  return AVERROR_UNKNOWN;
589 
590  if (av_new_packet(pkt, pkt->size) < 0)
591  return AVERROR(ENOMEM);
592 
593  pkt->pts = n;
594  pkt->dts = n;
595  pkt->duration = samples;
596  pkt->stream_index = avs->curr_stream;
597 
598  avs_library.avs_get_audio(avs->clip, pkt->data, n, samples);
599  error = avs_library.avs_clip_get_error(avs->clip);
600  if (error) {
601  av_log(s, AV_LOG_ERROR, "%s\n", error);
602  avs->error = 1;
603  av_packet_unref(pkt);
604  return AVERROR_UNKNOWN;
605  }
606  return 0;
607 }
608 
610 {
611  int ret;
612 
613  // Calling library must implement a lock for thread-safe opens.
614  if (ret = avpriv_lock_avformat())
615  return ret;
616 
617  if (ret = avisynth_open_file(s)) {
619  return ret;
620  }
621 
623  return 0;
624 }
625 
627 {
628  AviSynthContext *avs = s->priv_data;
629  AVStream *st;
630  int discard = 0;
631  int ret;
632 
633  if (avs->error)
634  return AVERROR_UNKNOWN;
635 
636  /* If either stream reaches EOF, try to read the other one before
637  * giving up. */
638  avisynth_next_stream(s, &st, pkt, &discard);
639  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
640  ret = avisynth_read_packet_video(s, pkt, discard);
641  if (ret == AVERROR_EOF && avs_has_audio(avs->vi)) {
642  avisynth_next_stream(s, &st, pkt, &discard);
643  return avisynth_read_packet_audio(s, pkt, discard);
644  }
645  } else {
646  ret = avisynth_read_packet_audio(s, pkt, discard);
647  if (ret == AVERROR_EOF && avs_has_video(avs->vi)) {
648  avisynth_next_stream(s, &st, pkt, &discard);
649  return avisynth_read_packet_video(s, pkt, discard);
650  }
651  }
652 
653  return ret;
654 }
655 
657 {
658  if (avpriv_lock_avformat())
659  return AVERROR_UNKNOWN;
660 
663  return 0;
664 }
665 
666 static int avisynth_read_seek(AVFormatContext *s, int stream_index,
667  int64_t timestamp, int flags)
668 {
669  AviSynthContext *avs = s->priv_data;
670  AVStream *st;
671  AVRational fps, samplerate;
672 
673  if (avs->error)
674  return AVERROR_UNKNOWN;
675 
676  fps = (AVRational) { avs->vi->fps_numerator,
677  avs->vi->fps_denominator };
678  samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 };
679 
680  st = s->streams[stream_index];
681  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
682  /* AviSynth frame counts are signed int. */
683  if ((timestamp >= avs->vi->num_frames) ||
684  (timestamp > INT_MAX) ||
685  (timestamp < 0))
686  return AVERROR_EOF;
687  avs->curr_frame = timestamp;
688  if (avs_has_audio(avs->vi))
689  avs->curr_sample = av_rescale_q(timestamp, samplerate, fps);
690  } else {
691  if ((timestamp >= avs->vi->num_audio_samples) || (timestamp < 0))
692  return AVERROR_EOF;
693  /* Force frame granularity for seeking. */
694  if (avs_has_video(avs->vi)) {
695  avs->curr_frame = av_rescale_q(timestamp, fps, samplerate);
696  avs->curr_sample = av_rescale_q(avs->curr_frame, samplerate, fps);
697  } else {
698  avs->curr_sample = timestamp;
699  }
700  }
701 
702  return 0;
703 }
704 
706  .name = "avisynth",
707  .long_name = NULL_IF_CONFIG_SMALL("AviSynth script"),
708  .priv_data_size = sizeof(AviSynthContext),
713  .extensions = "avs",
714 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
const char * s
Definition: avisynth_c.h:631
static int avs_atexit_called
Definition: avisynth.c:106
int avpriv_unlock_avformat(void)
Definition: utils.c:3817
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4404
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3915
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1578
discard all
Definition: avcodec.h:781
static AVPacket pkt
static const int avs_planes_yuv[3]
Definition: avisynth.c:100
Format I/O context.
Definition: avformat.h:1319
uint8_t bits
Definition: crc.c:296
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard)
Definition: avisynth.c:542
#define av_cold
Definition: attributes.h:82
int width
Video only.
Definition: avcodec.h:3981
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1595
int id
Format-specific stream ID.
Definition: avformat.h:883
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4042
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1387
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo *p)
Definition: avisynth_c.h:246
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1577
#define AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define av_log(a,...)
static av_cold int avisynth_read_close(AVFormatContext *s)
Definition: avisynth.c:656
AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:340
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
#define AVISYNTH_LIB
Definition: avisynth.c:41
INT64 num_audio_samples
Definition: avisynth_c.h:231
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:86
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const int * planes
Definition: avisynth.c:86
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3911
const char * arg
Definition: jacosubdec.c:66
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo *p)
Definition: avisynth_c.h:249
AVSC_INLINE int avs_has_video(const AVS_VideoInfo *p)
Definition: avisynth_c.h:240
struct AVS_Clip AVS_Clip
Definition: avisynth_c.h:213
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int discard)
Definition: avisynth.c:449
AVInputFormat ff_avisynth_demuxer
Definition: avisynth.c:705
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:954
int avpriv_lock_avformat(void)
Definition: utils.c:3808
#define fail()
Definition: checkasm.h:81
unsigned fps_numerator
Definition: avisynth_c.h:224
AVS_ScriptEnvironment * env
Definition: avisynth.c:80
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
static AviSynthLibrary avs_library
Definition: avisynth.c:105
AVSC_DECLARE_FUNC(avs_bit_blt)
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avisynth.c:626
common internal API header
AVSC_INLINE int avs_is_clip(AVS_Value v)
Definition: avisynth_c.h:486
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1375
char filename[1024]
input or output filename
Definition: avformat.h:1395
AVSC_INLINE AVS_Value avs_new_value_string(const char *v0)
Definition: avisynth_c.h:520
AVSC_INLINE const char * avs_as_error(AVS_Value v)
Definition: avisynth_c.h:505
AVS_Clip * clip
Definition: avisynth.c:81
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
Definition: avisynth.c:230
static const int avs_planes_grey[1]
Definition: avisynth.c:99
int n
Definition: avisynth_c.h:547
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
#define LoadLibrary(x)
Definition: avisynth.c:43
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:638
AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo *p)
Definition: avxsynth_c.h:221
Stream structure.
Definition: avformat.h:876
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
Definition: avisynth.c:306
static av_cold void avisynth_atexit_handler(void)
Definition: avisynth.c:215
AVSC_INLINE const unsigned char * avs_get_read_ptr_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:384
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:549
AVSC_INLINE int avs_is_error(AVS_Value v)
Definition: avisynth_c.h:492
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:315
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
void * library
Definition: avisynth.c:49
#define LOAD_AVS_FUNC(name, continue_on_fail)
rational number numerator/denominator
Definition: rational.h:43
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo *p)
Definition: avisynth_c.h:308
static int avisynth_create_stream(AVFormatContext *s)
Definition: avisynth.c:341
const AVS_VideoInfo * vi
Definition: avisynth.c:82
static int flags
Definition: cpu.c:47
static int avisynth_open_file(AVFormatContext *s)
Definition: avisynth.c:367
static av_cold int avisynth_load_library(void)
Definition: avisynth.c:113
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:930
int sample_rate
Audio only.
Definition: avcodec.h:4025
Main libavformat public API header.
struct AVS_ScriptEnvironment AVS_ScriptEnvironment
Definition: avisynth_c.h:214
static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avisynth.c:666
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
common internal api header.
static AviSynthContext * avs_ctx_list
Definition: avisynth.c:109
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:923
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:932
int den
denominator
Definition: rational.h:45
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:373
struct AviSynthContext * next
Definition: avisynth.c:95
void * priv_data
Format private data.
Definition: avformat.h:1347
unsigned fps_denominator
Definition: avisynth_c.h:224
int channels
Audio only.
Definition: avcodec.h:4021
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1576
static av_cold int avisynth_context_create(AVFormatContext *s)
Definition: avisynth.c:163
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:660
AVCodecParameters * codecpar
Definition: avformat.h:1006
static const int avs_planes_packed[1]
Definition: avisynth.c:98
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
Definition: avisynth.c:191
int stream_index
Definition: avcodec.h:1579
AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:348
#define FreeLibrary
Definition: avisynth.c:45
static av_cold int avisynth_read_header(AVFormatContext *s)
Definition: avisynth.c:609
This structure stores compressed data.
Definition: avcodec.h:1554
static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pkt, int *discard)
Definition: avisynth.c:431
int64_t curr_sample
Definition: avisynth.c:90
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1570
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo *p)
Definition: avisynth_c.h:243
int audio_samples_per_second
Definition: avisynth_c.h:229