FFmpeg
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  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/internal.h"
24 
25 #include "libavcodec/internal.h"
26 
27 #include "avformat.h"
28 #include "internal.h"
29 #include "config.h"
30 
31 /* Enable function pointer definitions for runtime loading. */
32 #define AVSC_NO_DECLSPEC
33 
34 /* Platform-specific directives for AviSynth vs AvxSynth. */
35 #ifdef _WIN32
36  #include "compat/w32dlfcn.h"
37  #undef EXTERN_C
39  #define AVISYNTH_LIB "avisynth"
40  #define USING_AVISYNTH
41 #else
42  #include <dlfcn.h>
44  #define AVISYNTH_NAME "libavxsynth"
45  #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
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_planar_rgb);
72  AVSC_DECLARE_FUNC(avs_is_planar_rgba);
73 #endif
74 #undef AVSC_DECLARE_FUNC
76 
77 typedef struct AviSynthContext {
80  const AVS_VideoInfo *vi;
81 
82  /* avisynth_read_packet_video() iterates over this. */
83  int n_planes;
84  const int *planes;
85 
88  int64_t curr_sample;
89 
90  int error;
91 
92  /* Linked list pointers. */
95 
96 static const int avs_planes_packed[1] = { 0 };
97 static const int avs_planes_grey[1] = { AVS_PLANAR_Y };
98 static const int avs_planes_yuv[3] = { AVS_PLANAR_Y, AVS_PLANAR_U,
99  AVS_PLANAR_V };
100 #ifdef USING_AVISYNTH
101 static const int avs_planes_rgb[3] = { AVS_PLANAR_G, AVS_PLANAR_B,
102  AVS_PLANAR_R };
103 static const int avs_planes_yuva[4] = { AVS_PLANAR_Y, AVS_PLANAR_U,
105 static const int avs_planes_rgba[4] = { AVS_PLANAR_G, AVS_PLANAR_B,
107 #endif
108 
109 /* A conflict between C++ global objects, atexit, and dynamic loading requires
110  * us to register our own atexit handler to prevent double freeing. */
112 static int avs_atexit_called = 0;
113 
114 /* Linked list of AviSynthContexts. An atexit handler destroys this list. */
116 
117 static av_cold void avisynth_atexit_handler(void);
118 
120 {
121  avs_library.library = dlopen(AVISYNTH_LIB, RTLD_NOW | RTLD_LOCAL);
122  if (!avs_library.library)
123  return AVERROR_UNKNOWN;
124 
125 #define LOAD_AVS_FUNC(name, continue_on_fail) \
126  avs_library.name = (name ## _func) \
127  dlsym(avs_library.library, #name); \
128  if (!continue_on_fail && !avs_library.name) \
129  goto fail;
130 
131  LOAD_AVS_FUNC(avs_bit_blt, 0);
132  LOAD_AVS_FUNC(avs_clip_get_error, 0);
133  LOAD_AVS_FUNC(avs_create_script_environment, 0);
134  LOAD_AVS_FUNC(avs_delete_script_environment, 0);
135  LOAD_AVS_FUNC(avs_get_audio, 0);
136  LOAD_AVS_FUNC(avs_get_error, 1); // New to AviSynth 2.6
137  LOAD_AVS_FUNC(avs_get_frame, 0);
138  LOAD_AVS_FUNC(avs_get_version, 0);
139  LOAD_AVS_FUNC(avs_get_video_info, 0);
140  LOAD_AVS_FUNC(avs_invoke, 0);
141  LOAD_AVS_FUNC(avs_release_clip, 0);
142  LOAD_AVS_FUNC(avs_release_value, 0);
143  LOAD_AVS_FUNC(avs_release_video_frame, 0);
144  LOAD_AVS_FUNC(avs_take_clip, 0);
145 #ifdef USING_AVISYNTH
151  LOAD_AVS_FUNC(avs_is_planar_rgb, 1);
152  LOAD_AVS_FUNC(avs_is_planar_rgba, 1);
153 #endif
154 #undef LOAD_AVS_FUNC
155 
156  atexit(avisynth_atexit_handler);
157  return 0;
158 
159 fail:
160  dlclose(avs_library.library);
161  return AVERROR_UNKNOWN;
162 }
163 
164 /* Note that avisynth_context_create and avisynth_context_destroy
165  * do not allocate or free the actual context! That is taken care of
166  * by libavformat. */
168 {
169  AviSynthContext *avs = s->priv_data;
170  int ret;
171 
172  if (!avs_library.library)
173  if (ret = avisynth_load_library())
174  return ret;
175 
176  avs->env = avs_library.avs_create_script_environment(3);
177  if (avs_library.avs_get_error) {
178  const char *error = avs_library.avs_get_error(avs->env);
179  if (error) {
180  av_log(s, AV_LOG_ERROR, "%s\n", error);
181  return AVERROR_UNKNOWN;
182  }
183  }
184 
185  if (!avs_ctx_list) {
186  avs_ctx_list = avs;
187  } else {
188  avs->next = avs_ctx_list;
189  avs_ctx_list = avs;
190  }
191 
192  return 0;
193 }
194 
196 {
197  if (avs_atexit_called)
198  return;
199 
200  if (avs == avs_ctx_list) {
201  avs_ctx_list = avs->next;
202  } else {
204  while (prev->next != avs)
205  prev = prev->next;
206  prev->next = avs->next;
207  }
208 
209  if (avs->clip) {
210  avs_library.avs_release_clip(avs->clip);
211  avs->clip = NULL;
212  }
213  if (avs->env) {
214  avs_library.avs_delete_script_environment(avs->env);
215  avs->env = NULL;
216  }
217 }
218 
220 {
222 
223  while (avs) {
224  AviSynthContext *next = avs->next;
226  avs = next;
227  }
228  dlclose(avs_library.library);
229 
230  avs_atexit_called = 1;
231 }
232 
233 /* Create AVStream from audio and video data. */
235 {
236  AviSynthContext *avs = s->priv_data;
237  int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: Planar RGBA
238 
241  st->codecpar->width = avs->vi->width;
242  st->codecpar->height = avs->vi->height;
243 
244  st->avg_frame_rate = (AVRational) { avs->vi->fps_numerator,
245  avs->vi->fps_denominator };
246  st->start_time = 0;
247  st->duration = avs->vi->num_frames;
248  st->nb_frames = avs->vi->num_frames;
249  avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, avs->vi->fps_numerator);
250 
251  switch (avs->vi->pixel_type) {
252 #ifdef USING_AVISYNTH
253  /* 10~16-bit YUV pix_fmts (AviSynth+) */
254  case AVS_CS_YUV444P10:
256  planar = 1;
257  break;
258  case AVS_CS_YUV422P10:
260  planar = 1;
261  break;
262  case AVS_CS_YUV420P10:
264  planar = 1;
265  break;
266  case AVS_CS_YUV444P12:
268  planar = 1;
269  break;
270  case AVS_CS_YUV422P12:
272  planar = 1;
273  break;
274  case AVS_CS_YUV420P12:
276  planar = 1;
277  break;
278  case AVS_CS_YUV444P14:
280  planar = 1;
281  break;
282  case AVS_CS_YUV422P14:
284  planar = 1;
285  break;
286  case AVS_CS_YUV420P14:
288  planar = 1;
289  break;
290  case AVS_CS_YUV444P16:
292  planar = 1;
293  break;
294  case AVS_CS_YUV422P16:
296  planar = 1;
297  break;
298  case AVS_CS_YUV420P16:
300  planar = 1;
301  break;
302  /* 8~16-bit YUV pix_fmts with Alpha (AviSynth+) */
303  case AVS_CS_YUVA444:
305  planar = 4;
306  break;
307  case AVS_CS_YUVA422:
309  planar = 4;
310  break;
311  case AVS_CS_YUVA420:
313  planar = 4;
314  break;
315  case AVS_CS_YUVA444P10:
317  planar = 4;
318  break;
319  case AVS_CS_YUVA422P10:
321  planar = 4;
322  break;
323  case AVS_CS_YUVA420P10:
325  planar = 4;
326  break;
327  case AVS_CS_YUVA422P12:
329  planar = 4;
330  break;
331  case AVS_CS_YUVA444P16:
333  planar = 4;
334  break;
335  case AVS_CS_YUVA422P16:
337  planar = 4;
338  break;
339  case AVS_CS_YUVA420P16:
341  planar = 4;
342  break;
343  /* Planar RGB pix_fmts (AviSynth+) */
344  case AVS_CS_RGBP:
346  planar = 3;
347  break;
348  case AVS_CS_RGBP10:
350  planar = 3;
351  break;
352  case AVS_CS_RGBP12:
354  planar = 3;
355  break;
356  case AVS_CS_RGBP14:
358  planar = 3;
359  break;
360  case AVS_CS_RGBP16:
362  planar = 3;
363  break;
364  /* Single precision floating point Planar RGB (AviSynth+) */
365  case AVS_CS_RGBPS:
367  planar = 3;
368  break;
369  /* Planar RGB pix_fmts with Alpha (AviSynth+) */
370  case AVS_CS_RGBAP:
372  planar = 5;
373  break;
374  case AVS_CS_RGBAP10:
376  planar = 5;
377  break;
378  case AVS_CS_RGBAP12:
380  planar = 5;
381  break;
382  case AVS_CS_RGBAP16:
384  planar = 5;
385  break;
386  /* Single precision floating point Planar RGB with Alpha (AviSynth+) */
387  case AVS_CS_RGBAPS:
389  planar = 5;
390  break;
391  /* 10~16-bit gray pix_fmts (AviSynth+) */
392  case AVS_CS_Y10:
394  planar = 2;
395  break;
396  case AVS_CS_Y12:
398  planar = 2;
399  break;
400  case AVS_CS_Y14:
402  planar = 2;
403  break;
404  case AVS_CS_Y16:
406  planar = 2;
407  break;
408  /* Single precision floating point gray (AviSynth+) */
409  case AVS_CS_Y32:
411  planar = 2;
412  break;
413  /* pix_fmts added in AviSynth 2.6 */
414  case AVS_CS_YV24:
416  planar = 1;
417  break;
418  case AVS_CS_YV16:
420  planar = 1;
421  break;
422  case AVS_CS_YV411:
424  planar = 1;
425  break;
426  case AVS_CS_Y8:
428  planar = 2;
429  break;
430  /* 16-bit packed RGB pix_fmts (AviSynth+) */
431  case AVS_CS_BGR48:
433  break;
434  case AVS_CS_BGR64:
436  break;
437 #endif
438  /* AviSynth 2.5 and AvxSynth pix_fmts */
439  case AVS_CS_BGR24:
441  break;
442  case AVS_CS_BGR32:
444  break;
445  case AVS_CS_YUY2:
447  break;
448  case AVS_CS_YV12:
450  planar = 1;
451  break;
452  case AVS_CS_I420: // Is this even used anywhere?
454  planar = 1;
455  break;
456  default:
458  "unknown AviSynth colorspace %d\n", avs->vi->pixel_type);
459  avs->error = 1;
460  return AVERROR_UNKNOWN;
461  }
462 
463  switch (planar) {
464 #ifdef USING_AVISYNTH
465  case 5: // Planar RGB + Alpha
466  avs->n_planes = 4;
467  avs->planes = avs_planes_rgba;
468  break;
469  case 4: // YUV + Alpha
470  avs->n_planes = 4;
471  avs->planes = avs_planes_yuva;
472  break;
473  case 3: // Planar RGB
474  avs->n_planes = 3;
475  avs->planes = avs_planes_rgb;
476  break;
477 #endif
478  case 2: // Y8
479  avs->n_planes = 1;
480  avs->planes = avs_planes_grey;
481  break;
482  case 1: // YUV
483  avs->n_planes = 3;
484  avs->planes = avs_planes_yuv;
485  break;
486  default:
487  avs->n_planes = 1;
488  avs->planes = avs_planes_packed;
489  }
490  return 0;
491 }
492 
494 {
495  AviSynthContext *avs = s->priv_data;
496 
499  st->codecpar->channels = avs->vi->nchannels;
500  st->duration = avs->vi->num_audio_samples;
502 
503  switch (avs->vi->sample_type) {
504  case AVS_SAMPLE_INT8:
506  break;
507  case AVS_SAMPLE_INT16:
509  break;
510  case AVS_SAMPLE_INT24:
512  break;
513  case AVS_SAMPLE_INT32:
515  break;
516  case AVS_SAMPLE_FLOAT:
518  break;
519  default:
521  "unknown AviSynth sample type %d\n", avs->vi->sample_type);
522  avs->error = 1;
523  return AVERROR_UNKNOWN;
524  }
525  return 0;
526 }
527 
529 {
530  AviSynthContext *avs = s->priv_data;
531  AVStream *st;
532  int ret;
533  int id = 0;
534 
535  if (avs_has_video(avs->vi)) {
536  st = avformat_new_stream(s, NULL);
537  if (!st)
538  return AVERROR_UNKNOWN;
539  st->id = id++;
541  return ret;
542  }
543  if (avs_has_audio(avs->vi)) {
544  st = avformat_new_stream(s, NULL);
545  if (!st)
546  return AVERROR_UNKNOWN;
547  st->id = id++;
549  return ret;
550  }
551  return 0;
552 }
553 
555 {
556  AviSynthContext *avs = s->priv_data;
557  AVS_Value arg, val;
558  int ret;
559 #ifdef USING_AVISYNTH
560  char filename_ansi[MAX_PATH * 4];
561  wchar_t filename_wc[MAX_PATH * 4];
562 #endif
563 
565  return ret;
566 
567 #ifdef USING_AVISYNTH
568  /* Convert UTF-8 to ANSI code page */
569  MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc, MAX_PATH * 4);
570  WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
571  MAX_PATH * 4, NULL, NULL);
572  arg = avs_new_value_string(filename_ansi);
573 #else
574  arg = avs_new_value_string(s->filename);
575 #endif
576  val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
577  if (avs_is_error(val)) {
578  av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val));
580  goto fail;
581  }
582  if (!avs_is_clip(val)) {
583  av_log(s, AV_LOG_ERROR, "AviSynth script did not return a clip\n");
585  goto fail;
586  }
587 
588  avs->clip = avs_library.avs_take_clip(val, avs->env);
589  avs->vi = avs_library.avs_get_video_info(avs->clip);
590 
591 #ifdef USING_AVISYNTH
592  /* On Windows, FFmpeg supports AviSynth interface version 6 or higher.
593  * This includes AviSynth 2.6 RC1 or higher, and AviSynth+ r1718 or higher,
594  * and excludes 2.5 and the 2.6 alphas. Since AvxSynth identifies itself
595  * as interface version 3 like 2.5.8, this needs to be special-cased. */
596 
597  if (avs_library.avs_get_version(avs->clip) < 6) {
599  "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
601  goto fail;
602  }
603 #endif
604 
605  /* Release the AVS_Value as it will go out of scope. */
606  avs_library.avs_release_value(val);
607 
609  goto fail;
610 
611  return 0;
612 
613 fail:
615  return ret;
616 }
617 
619  AVPacket *pkt, int *discard)
620 {
621  AviSynthContext *avs = s->priv_data;
622 
623  avs->curr_stream++;
624  avs->curr_stream %= s->nb_streams;
625 
626  *st = s->streams[avs->curr_stream];
627  if ((*st)->discard == AVDISCARD_ALL)
628  *discard = 1;
629  else
630  *discard = 0;
631 
632  return;
633 }
634 
635 /* Copy AviSynth clip data into an AVPacket. */
637  int discard)
638 {
639  AviSynthContext *avs = s->priv_data;
641  unsigned char *dst_p;
642  const unsigned char *src_p;
643  int n, i, plane, rowsize, planeheight, pitch, bits;
644  const char *error;
645  int avsplus av_unused;
646 
647  if (avs->curr_frame >= avs->vi->num_frames)
648  return AVERROR_EOF;
649 
650  /* This must happen even if the stream is discarded to prevent desync. */
651  n = avs->curr_frame++;
652  if (discard)
653  return 0;
654 
655 #ifdef USING_AVISYNTH
656  /* Detect whether we're using AviSynth 2.6 or AviSynth+ by
657  * looking for whether avs_is_planar_rgb exists. */
658  if (GetProcAddress(avs_library.library, "avs_is_planar_rgb") == NULL)
659  avsplus = 0;
660  else
661  avsplus = 1;
662 
663  /* avs_bits_per_pixel changed to AVSC_API with AviSynth 2.6, which
664  * requires going through avs_library, while AvxSynth has it under
665  * the older AVSC_INLINE type, so special-case this. */
666 
667  bits = avs_library.avs_bits_per_pixel(avs->vi);
668 #else
669  bits = avs_bits_per_pixel(avs->vi);
670 #endif
671 
672  /* Without the cast to int64_t, calculation overflows at about 9k x 9k
673  * resolution. */
674  pkt->size = (((int64_t)avs->vi->width *
675  (int64_t)avs->vi->height) * bits) / 8;
676  if (!pkt->size)
677  return AVERROR_UNKNOWN;
678 
679  if (av_new_packet(pkt, pkt->size) < 0)
680  return AVERROR(ENOMEM);
681 
682  pkt->pts = n;
683  pkt->dts = n;
684  pkt->duration = 1;
685  pkt->stream_index = avs->curr_stream;
686 
687  frame = avs_library.avs_get_frame(avs->clip, n);
688  error = avs_library.avs_clip_get_error(avs->clip);
689  if (error) {
690  av_log(s, AV_LOG_ERROR, "%s\n", error);
691  avs->error = 1;
693  return AVERROR_UNKNOWN;
694  }
695 
696  dst_p = pkt->data;
697  for (i = 0; i < avs->n_planes; i++) {
698  plane = avs->planes[i];
699 #ifdef USING_AVISYNTH
700  src_p = avs_library.avs_get_read_ptr_p(frame, plane);
701  pitch = avs_library.avs_get_pitch_p(frame, plane);
702 
703  rowsize = avs_library.avs_get_row_size_p(frame, plane);
704  planeheight = avs_library.avs_get_height_p(frame, plane);
705 #else
706  src_p = avs_get_read_ptr_p(frame, plane);
707  pitch = avs_get_pitch_p(frame, plane);
708 
709  rowsize = avs_get_row_size_p(frame, plane);
710  planeheight = avs_get_height_p(frame, plane);
711 #endif
712 
713  /* Flip RGB video. */
714  if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) {
715  src_p = src_p + (planeheight - 1) * pitch;
716  pitch = -pitch;
717  }
718 
719 #ifdef USING_AVISYNTH
720  /* Flip Planar RGB video */
721  if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) ||
722  avs_library.avs_is_planar_rgba(avs->vi))) {
723  src_p = src_p + (planeheight - 1) * pitch;
724  pitch = -pitch;
725  }
726 #endif
727 
728  avs_library.avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch,
729  rowsize, planeheight);
730  dst_p += rowsize * planeheight;
731  }
732 
733  avs_library.avs_release_video_frame(frame);
734  return 0;
735 }
736 
738  int discard)
739 {
740  AviSynthContext *avs = s->priv_data;
741  AVRational fps, samplerate;
742  int samples;
743  int64_t n;
744  const char *error;
745 
746  if (avs->curr_sample >= avs->vi->num_audio_samples)
747  return AVERROR_EOF;
748 
749  fps.num = avs->vi->fps_numerator;
750  fps.den = avs->vi->fps_denominator;
751  samplerate.num = avs->vi->audio_samples_per_second;
752  samplerate.den = 1;
753 
754  if (avs_has_video(avs->vi)) {
755  if (avs->curr_frame < avs->vi->num_frames)
756  samples = av_rescale_q(avs->curr_frame, samplerate, fps) -
757  avs->curr_sample;
758  else
759  samples = av_rescale_q(1, samplerate, fps);
760  } else {
761  samples = 1000;
762  }
763 
764  /* After seeking, audio may catch up with video. */
765  if (samples <= 0) {
766  pkt->size = 0;
767  pkt->data = NULL;
768  return 0;
769  }
770 
771  if (avs->curr_sample + samples > avs->vi->num_audio_samples)
772  samples = avs->vi->num_audio_samples - avs->curr_sample;
773 
774  /* This must happen even if the stream is discarded to prevent desync. */
775  n = avs->curr_sample;
776  avs->curr_sample += samples;
777  if (discard)
778  return 0;
779 
781  samples * avs->vi->nchannels;
782  if (!pkt->size)
783  return AVERROR_UNKNOWN;
784 
785  if (av_new_packet(pkt, pkt->size) < 0)
786  return AVERROR(ENOMEM);
787 
788  pkt->pts = n;
789  pkt->dts = n;
790  pkt->duration = samples;
791  pkt->stream_index = avs->curr_stream;
792 
793  avs_library.avs_get_audio(avs->clip, pkt->data, n, samples);
794  error = avs_library.avs_clip_get_error(avs->clip);
795  if (error) {
796  av_log(s, AV_LOG_ERROR, "%s\n", error);
797  avs->error = 1;
799  return AVERROR_UNKNOWN;
800  }
801  return 0;
802 }
803 
805 {
806  int ret;
807 
808  // Calling library must implement a lock for thread-safe opens.
809  if (ret = ff_lock_avformat())
810  return ret;
811 
812  if (ret = avisynth_open_file(s)) {
814  return ret;
815  }
816 
818  return 0;
819 }
820 
822 {
823  AviSynthContext *avs = s->priv_data;
824  AVStream *st;
825  int discard = 0;
826  int ret;
827 
828  if (avs->error)
829  return AVERROR_UNKNOWN;
830 
831  /* If either stream reaches EOF, try to read the other one before
832  * giving up. */
833  avisynth_next_stream(s, &st, pkt, &discard);
834  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
835  ret = avisynth_read_packet_video(s, pkt, discard);
836  if (ret == AVERROR_EOF && avs_has_audio(avs->vi)) {
837  avisynth_next_stream(s, &st, pkt, &discard);
838  return avisynth_read_packet_audio(s, pkt, discard);
839  }
840  } else {
841  ret = avisynth_read_packet_audio(s, pkt, discard);
842  if (ret == AVERROR_EOF && avs_has_video(avs->vi)) {
843  avisynth_next_stream(s, &st, pkt, &discard);
844  return avisynth_read_packet_video(s, pkt, discard);
845  }
846  }
847 
848  return ret;
849 }
850 
852 {
853  if (ff_lock_avformat())
854  return AVERROR_UNKNOWN;
855 
856  avisynth_context_destroy(s->priv_data);
858  return 0;
859 }
860 
861 static int avisynth_read_seek(AVFormatContext *s, int stream_index,
862  int64_t timestamp, int flags)
863 {
864  AviSynthContext *avs = s->priv_data;
865  AVStream *st;
866  AVRational fps, samplerate;
867 
868  if (avs->error)
869  return AVERROR_UNKNOWN;
870 
871  fps = (AVRational) { avs->vi->fps_numerator,
872  avs->vi->fps_denominator };
873  samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 };
874 
875  st = s->streams[stream_index];
876  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
877  /* AviSynth frame counts are signed int. */
878  if ((timestamp >= avs->vi->num_frames) ||
879  (timestamp > INT_MAX) ||
880  (timestamp < 0))
881  return AVERROR_EOF;
882  avs->curr_frame = timestamp;
883  if (avs_has_audio(avs->vi))
884  avs->curr_sample = av_rescale_q(timestamp, samplerate, fps);
885  } else {
886  if ((timestamp >= avs->vi->num_audio_samples) || (timestamp < 0))
887  return AVERROR_EOF;
888  /* Force frame granularity for seeking. */
889  if (avs_has_video(avs->vi)) {
890  avs->curr_frame = av_rescale_q(timestamp, fps, samplerate);
891  avs->curr_sample = av_rescale_q(avs->curr_frame, samplerate, fps);
892  } else {
893  avs->curr_sample = timestamp;
894  }
895  }
896 
897  return 0;
898 }
899 
901  .name = "avisynth",
902  .long_name = NULL_IF_CONFIG_SMALL("AviSynth script"),
903  .priv_data_size = sizeof(AviSynthContext),
908  .extensions = "avs",
909 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: avcodec.h:463
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:430
AVS_SAMPLE_INT24
@ AVS_SAMPLE_INT24
Definition: avisynth_c.h:73
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:409
AVS_CS_YUVA422P16
@ AVS_CS_YUVA422P16
Definition: avisynth_c.h:230
AVS_VideoInfo::sample_type
int sample_type
Definition: avisynth_c.h:343
avisynth_c.h
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4480
avisynth_atexit_handler
static av_cold void avisynth_atexit_handler(void)
Definition: avisynth.c:219
AVS_CS_RGBAPS
@ AVS_CS_RGBAPS
Definition: avisynth_c.h:210
AVS_CS_YV24
@ AVS_CS_YV24
Definition: avisynth_c.h:153
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
avisynth_load_library
static av_cold int avisynth_load_library(void)
Definition: avisynth.c:119
AVS_CS_YV12
@ AVS_CS_YV12
Definition: avisynth_c.h:155
ff_avisynth_demuxer
AVInputFormat ff_avisynth_demuxer
Definition: avisynth.c:900
avs_is_error
AVSC_INLINE int avs_is_error(AVS_Value v)
Definition: avisynth_c.h:706
n
int n
Definition: avisynth_c.h:760
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
avs_get_row_size_p
AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:348
avisynth_read_seek
static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avisynth.c:861
avisynth_read_packet
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avisynth.c:821
AVS_CS_YUV444P12
@ AVS_CS_YUV444P12
Definition: avisynth_c.h:170
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: avcodec.h:231
av_unused
#define av_unused
Definition: attributes.h:125
AviSynthContext::curr_sample
int64_t curr_sample
Definition: avisynth.c:88
avs_is_rgb
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo *p)
Definition: avisynth_c.h:359
AVS_PLANAR_U
@ AVS_PLANAR_U
Definition: avisynth_c.h:78
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:429
avs_atexit_called
static int avs_atexit_called
Definition: avisynth.c:112
internal.h
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:424
AviSynthLibrary::library
void * library
Definition: avisynth.c:49
avs_planes_yuv
static const int avs_planes_yuv[3]
Definition: avisynth.c:98
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:943
avs_get_read_ptr_p
const AVSC_INLINE unsigned char * avs_get_read_ptr_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:384
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
AVS_CS_YUVA444P16
@ AVS_CS_YUVA444P16
Definition: avisynth_c.h:229
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1495
AVS_CS_RGBP14
@ AVS_CS_RGBP14
Definition: avisynth_c.h:200
avs_get_height_p
AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:373
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:425
AviSynthContext::curr_stream
int curr_stream
Definition: avisynth.c:86
AVS_CS_YUVA420P10
@ AVS_CS_YUVA420P10
Definition: avisynth_c.h:219
ff_unlock_avformat
int ff_unlock_avformat(void)
Definition: utils.c:88
AVS_SAMPLE_INT32
@ AVS_SAMPLE_INT32
Definition: avisynth_c.h:74
AviSynthLibrary
Definition: avisynth.c:48
AVS_CS_YUV422P10
@ AVS_CS_YUV422P10
Definition: avisynth_c.h:166
AVS_CS_YUVA422P12
@ AVS_CS_YUVA422P12
Definition: avisynth_c.h:222
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:4063
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:405
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
AVS_CS_YUV444P16
@ AVS_CS_YUV444P16
Definition: avisynth_c.h:180
fail
#define fail()
Definition: checkasm.h:120
avs_new_value_string
AVSC_INLINE AVS_Value avs_new_value_string(const char *v0)
Definition: avisynth_c.h:731
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:403
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:431
plane
int plane
Definition: avisynth_c.h:384
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
AVS_CS_YUV422P16
@ AVS_CS_YUV422P16
Definition: avisynth_c.h:181
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:371
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:919
AVISYNTH_LIB
#define AVISYNTH_LIB
Definition: avisynth.c:45
AVRational::num
int num
Numerator.
Definition: rational.h:59
avisynth_create_stream_video
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
Definition: avisynth.c:234
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
AVS_CS_RGBP12
@ AVS_CS_RGBP12
Definition: avisynth_c.h:199
AVS_CS_BGR64
@ AVS_CS_BGR64
Definition: avisynth_c.h:193
AVS_CS_YUV444P10
@ AVS_CS_YUV444P10
Definition: avisynth_c.h:165
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVInputFormat
Definition: avformat.h:640
av_cold
#define av_cold
Definition: attributes.h:84
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:399
AVS_CS_Y32
@ AVS_CS_Y32
Definition: avisynth_c.h:189
AVS_PLANAR_V
@ AVS_PLANAR_V
Definition: avisynth_c.h:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:407
AVS_CS_YUVA420P16
@ AVS_CS_YUVA420P16
Definition: avisynth_c.h:231
planar
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
Definition: audioconvert.c:226
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVS_VideoInfo::nchannels
int nchannels
Definition: avisynth_c.h:345
av_new_packet
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
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:408
LOAD_AVS_FUNC
#define LOAD_AVS_FUNC(name, continue_on_fail)
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:400
AVS_VideoInfo
Definition: avisynth_c.h:335
AVS_CS_RGBAP16
@ AVS_CS_RGBAP16
Definition: avisynth_c.h:209
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
avisynth_read_close
static av_cold int avisynth_read_close(AVFormatContext *s)
Definition: avisynth.c:851
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVS_CS_YUV444P14
@ AVS_CS_YUV444P14
Definition: avisynth_c.h:175
AVCodecParameters::width
int width
Video only.
Definition: avcodec.h:4023
bits
uint8_t bits
Definition: vp3data.h:202
avs_get_pitch_p
AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame *p, int plane)
Definition: avxsynth_c.h:340
avs_ctx_list
static AviSynthContext * avs_ctx_list
Definition: avisynth.c:115
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:398
avs_is_rgb24
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo *p)
Definition: avisynth_c.h:362
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:370
AviSynthContext::error
int error
Definition: avisynth.c:90
av_rescale_q
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
AVS_ScriptEnvironment
struct AVS_ScriptEnvironment AVS_ScriptEnvironment
Definition: avisynth_c.h:327
avisynth_next_stream
static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pkt, int *discard)
Definition: avisynth.c:618
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:419
arg
const char * arg
Definition: jacosubdec.c:66
AVS_CS_YV16
@ AVS_CS_YV16
Definition: avisynth_c.h:154
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:368
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:811
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
AVS_VideoInfo::num_audio_samples
INT64 num_audio_samples
Definition: avisynth_c.h:344
AviSynthContext::env
AVS_ScriptEnvironment * env
Definition: avisynth.c:78
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:406
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
AviSynthContext::planes
const int * planes
Definition: avisynth.c:84
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:378
NULL
#define NULL
Definition: coverity.c:32
AVS_CS_YUVA422P10
@ AVS_CS_YUVA422P10
Definition: avisynth_c.h:218
AVS_CS_RGBAP12
@ AVS_CS_RGBAP12
Definition: avisynth_c.h:207
avisynth_context_destroy
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
Definition: avisynth.c:195
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
avisynth_read_packet_audio
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard)
Definition: avisynth.c:737
AVS_CS_RGBP
@ AVS_CS_RGBP
Definition: avisynth_c.h:197
avs_bytes_per_channel_sample
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo *p)
Definition: avisynth_c.h:432
avisynth_read_header
static av_cold int avisynth_read_header(AVFormatContext *s)
Definition: avisynth.c:804
AVS_PLANAR_G
@ AVS_PLANAR_G
Definition: avisynth_c.h:86
AVS_PLANAR_B
@ AVS_PLANAR_B
Definition: avisynth_c.h:87
avs_library
static AviSynthLibrary avs_library
Definition: avisynth.c:111
AVS_CS_Y10
@ AVS_CS_Y10
Definition: avisynth_c.h:168
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
AVS_CS_RGBAP10
@ AVS_CS_RGBAP10
Definition: avisynth_c.h:206
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AVS_CS_YUV420P16
@ AVS_CS_YUV420P16
Definition: avisynth_c.h:182
AVS_PLANAR_A
@ AVS_PLANAR_A
Definition: avisynth_c.h:84
AVS_CS_Y16
@ AVS_CS_Y16
Definition: avisynth_c.h:183
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: avcodec.h:4067
error
static void error(const char *err)
Definition: target_dec_fuzzer.c:61
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:921
AviSynthContext::clip
AVS_Clip * clip
Definition: avisynth.c:79
AVS_VideoInfo::pixel_type
int pixel_type
Definition: avisynth_c.h:340
AVS_CS_YUV422P12
@ AVS_CS_YUV422P12
Definition: avisynth_c.h:171
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: avcodec.h:475
AVS_Value
Definition: avisynth_c.h:672
AVPacket::size
int size
Definition: avcodec.h:1478
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
avisynth_read_packet_video
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int discard)
Definition: avisynth.c:636
avisynth_create_stream
static int avisynth_create_stream(AVFormatContext *s)
Definition: avisynth.c:528
AviSynthContext
Definition: avisynth.c:77
AVS_CS_BGR32
@ AVS_CS_BGR32
Definition: avisynth_c.h:147
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:416
avpriv_set_pts_info
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:4910
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
AVS_SAMPLE_INT16
@ AVS_SAMPLE_INT16
Definition: avisynth_c.h:72
AVS_CS_YUVA444
@ AVS_CS_YUVA444
Definition: avisynth_c.h:213
ff_lock_avformat
int ff_lock_avformat(void)
Definition: utils.c:83
avs_bits_per_pixel
AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo *p)
Definition: avxsynth_c.h:221
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
AVS_CS_RGBPS
@ AVS_CS_RGBPS
Definition: avisynth_c.h:202
val
const char const char void * val
Definition: avisynth_c.h:863
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: avcodec.h:1476
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:360
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:426
attributes.h
avs_has_video
AVSC_INLINE int avs_has_video(const AVS_VideoInfo *p)
Definition: avisynth_c.h:353
AVS_PLANAR_R
@ AVS_PLANAR_R
Definition: avisynth_c.h:85
avs_as_error
const AVSC_INLINE char * avs_as_error(AVS_Value v)
Definition: avisynth_c.h:716
AviSynthContext::curr_frame
int curr_frame
Definition: avisynth.c:87
avs_planes_grey
static const int avs_planes_grey[1]
Definition: avisynth.c:97
AVS_CS_YUV422P14
@ AVS_CS_YUV422P14
Definition: avisynth_c.h:176
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:382
AVS_VideoInfo::width
int width
Definition: avisynth_c.h:336
AVS_CS_YUV420P12
@ AVS_CS_YUV420P12
Definition: avisynth_c.h:172
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
AVS_VideoInfo::height
int height
Definition: avisynth_c.h:336
internal.h
AVCodecParameters::height
int height
Definition: avcodec.h:4024
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:404
AVS_CS_Y12
@ AVS_CS_Y12
Definition: avisynth_c.h:173
AVS_CS_I420
@ AVS_CS_I420
Definition: avisynth_c.h:156
avisynth_create_stream_audio
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
Definition: avisynth.c:493
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:877
AVS_VideoInfo::fps_numerator
unsigned fps_numerator
Definition: avisynth_c.h:337
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:870
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVS_VideoInfo::fps_denominator
unsigned fps_denominator
Definition: avisynth_c.h:337
avs_has_audio
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo *p)
Definition: avisynth_c.h:356
avformat.h
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:396
avs_is_clip
AVSC_INLINE int avs_is_clip(AVS_Value v)
Definition: avisynth_c.h:700
AVS_CS_YV411
@ AVS_CS_YV411
Definition: avisynth_c.h:158
AVS_CS_YUY2
@ AVS_CS_YUY2
Definition: avisynth_c.h:148
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVRational::den
int den
Denominator.
Definition: rational.h:60
config.h
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:427
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:417
AVS_CS_YUV420P10
@ AVS_CS_YUV420P10
Definition: avisynth_c.h:167
AVS_CS_BGR48
@ AVS_CS_BGR48
Definition: avisynth_c.h:192
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
AVS_CS_RGBP16
@ AVS_CS_RGBP16
Definition: avisynth_c.h:201
AVS_CS_BGR24
@ AVS_CS_BGR24
Definition: avisynth_c.h:146
AVS_VideoFrame
Definition: avisynth_c.h:567
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: avcodec.h:471
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: avcodec.h:468
AVS_CS_YUV420P14
@ AVS_CS_YUV420P14
Definition: avisynth_c.h:177
AVCodecParameters::format
int format
Definition: avcodec.h:3981
AviSynthContext::n_planes
int n_planes
Definition: avisynth.c:83
AviSynthContext::vi
const AVS_VideoInfo * vi
Definition: avisynth.c:80
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
AVS_SAMPLE_FLOAT
@ AVS_SAMPLE_FLOAT
Definition: avisynth_c.h:75
AviSynthContext::next
struct AviSynthContext * next
Definition: avisynth.c:93
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AviSynthLibrary::AVSC_DECLARE_FUNC
AVSC_DECLARE_FUNC(avs_bit_blt)
AV_CODEC_ID_PCM_F32LE
@ AV_CODEC_ID_PCM_F32LE
Definition: avcodec.h:484
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVS_CS_Y8
@ AVS_CS_Y8
Definition: avisynth_c.h:160
AVS_CS_YUVA420
@ AVS_CS_YUVA420
Definition: avisynth_c.h:215
avisynth_context_create
static av_cold int avisynth_context_create(AVFormatContext *s)
Definition: avisynth.c:167
AVS_CS_Y14
@ AVS_CS_Y14
Definition: avisynth_c.h:178
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:397
avisynth_open_file
static int avisynth_open_file(AVFormatContext *s)
Definition: avisynth.c:554
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:909
AVS_SAMPLE_INT8
@ AVS_SAMPLE_INT8
Definition: avisynth_c.h:71
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:369
AVS_CS_YUVA444P10
@ AVS_CS_YUVA444P10
Definition: avisynth_c.h:217
AVS_CS_YUVA422
@ AVS_CS_YUVA422
Definition: avisynth_c.h:214
AVS_PLANAR_Y
@ AVS_PLANAR_Y
Definition: avisynth_c.h:77
avs_planes_packed
static const int avs_planes_packed[1]
Definition: avisynth.c:96
AVS_VideoInfo::num_frames
int num_frames
Definition: avisynth_c.h:338
avxsynth_c.h
AVS_Clip
struct AVS_Clip AVS_Clip
Definition: avisynth_c.h:326
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:395
w32dlfcn.h
AVS_CS_RGBAP
@ AVS_CS_RGBAP
Definition: avisynth_c.h:205
AVS_VideoInfo::audio_samples_per_second
int audio_samples_per_second
Definition: avisynth_c.h:342
AVS_CS_RGBP10
@ AVS_CS_RGBP10
Definition: avisynth_c.h:198