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