FFmpeg
ffmpeg_dec.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/avassert.h"
20 #include "libavutil/avstring.h"
21 #include "libavutil/dict.h"
22 #include "libavutil/error.h"
23 #include "libavutil/log.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/pixfmt.h"
28 #include "libavutil/time.h"
29 #include "libavutil/timestamp.h"
30 
31 #include "libavcodec/avcodec.h"
32 #include "libavcodec/codec.h"
33 
34 #include "ffmpeg.h"
35 
36 typedef struct DecoderPriv {
38 
40 
43 
44  // override output video sample aspect ratio with this value
46 
48 
49  // a combination of DECODER_FLAG_*, provided to dec_open()
50  int flags;
52 
57 
58  // pts/estimated duration of the last decoded frame
59  // * in decoder timebase for video,
60  // * in last_frame_tb (may change during decoding) for audio
66 
67  /* previous decoded subtitles */
70 
72  unsigned sch_idx;
73 
74  // this decoder's index in decoders or -1
75  int index;
76  void *log_parent;
77  char log_name[32];
78  char *parent_name;
79 
80  struct {
82  const AVCodec *codec;
84 } DecoderPriv;
85 
87 {
88  return (DecoderPriv*)d;
89 }
90 
91 // data that is local to the decoder thread and not visible outside of it
92 typedef struct DecThreadContext {
96 
97 void dec_free(Decoder **pdec)
98 {
99  Decoder *dec = *pdec;
100  DecoderPriv *dp;
101 
102  if (!dec)
103  return;
104  dp = dp_from_dec(dec);
105 
107 
108  av_frame_free(&dp->frame);
109  av_packet_free(&dp->pkt);
110 
112 
113  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++)
114  av_frame_free(&dp->sub_prev[i]);
116 
117  av_freep(&dp->parent_name);
118 
119  av_freep(pdec);
120 }
121 
122 static const char *dec_item_name(void *obj)
123 {
124  const DecoderPriv *dp = obj;
125 
126  return dp->log_name;
127 }
128 
129 static const AVClass dec_class = {
130  .class_name = "Decoder",
131  .version = LIBAVUTIL_VERSION_INT,
132  .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
133  .item_name = dec_item_name,
134 };
135 
136 static int decoder_thread(void *arg);
137 
138 static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
139 {
140  DecoderPriv *dp;
141  int ret = 0;
142 
143  *pdec = NULL;
144 
145  dp = av_mallocz(sizeof(*dp));
146  if (!dp)
147  return AVERROR(ENOMEM);
148 
149  dp->frame = av_frame_alloc();
150  if (!dp->frame)
151  goto fail;
152 
153  dp->pkt = av_packet_alloc();
154  if (!dp->pkt)
155  goto fail;
156 
157  dp->index = -1;
158  dp->dec.class = &dec_class;
161  dp->last_frame_tb = (AVRational){ 1, 1 };
163 
164  ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts);
165  if (ret < 0)
166  goto fail;
167  dp->sch = sch;
168  dp->sch_idx = ret;
169 
170  *pdec = dp;
171 
172  return 0;
173 fail:
174  dec_free((Decoder**)&dp);
175  return ret >= 0 ? AVERROR(ENOMEM) : ret;
176 }
177 
179  const AVFrame *frame)
180 {
181  const int prev = dp->last_frame_tb.den;
182  const int sr = frame->sample_rate;
183 
184  AVRational tb_new;
185  int64_t gcd;
186 
187  if (frame->sample_rate == dp->last_frame_sample_rate)
188  goto finish;
189 
190  gcd = av_gcd(prev, sr);
191 
192  if (prev / gcd >= INT_MAX / sr) {
194  "Audio timestamps cannot be represented exactly after "
195  "sample rate change: %d -> %d\n", prev, sr);
196 
197  // LCM of 192000, 44100, allows to represent all common samplerates
198  tb_new = (AVRational){ 1, 28224000 };
199  } else
200  tb_new = (AVRational){ 1, prev / gcd * sr };
201 
202  // keep the frame timebase if it is strictly better than
203  // the samplerate-defined one
204  if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den &&
205  !(frame->time_base.den % tb_new.den))
206  tb_new = frame->time_base;
207 
210  dp->last_frame_tb, tb_new);
212  dp->last_frame_tb, tb_new);
213 
214  dp->last_frame_tb = tb_new;
215  dp->last_frame_sample_rate = frame->sample_rate;
216 
217 finish:
218  return dp->last_frame_tb;
219 }
220 
222 {
223  AVRational tb_filter = (AVRational){1, frame->sample_rate};
224  AVRational tb;
225  int64_t pts_pred;
226 
227  // on samplerate change, choose a new internal timebase for timestamp
228  // generation that can represent timestamps from all the samplerates
229  // seen so far
230  tb = audio_samplerate_update(dp, frame);
231  pts_pred = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
233 
234  if (frame->pts == AV_NOPTS_VALUE) {
235  frame->pts = pts_pred;
236  frame->time_base = tb;
237  } else if (dp->last_frame_pts != AV_NOPTS_VALUE &&
238  frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base,
239  AV_ROUND_UP)) {
240  // there was a gap in timestamps, reset conversion state
242  }
243 
244  frame->pts = av_rescale_delta(frame->time_base, frame->pts,
245  tb, frame->nb_samples,
247 
248  dp->last_frame_pts = frame->pts;
249  dp->last_frame_duration_est = av_rescale_q(frame->nb_samples,
250  tb_filter, tb);
251 
252  // finally convert to filtering timebase
253  frame->pts = av_rescale_q(frame->pts, tb, tb_filter);
254  frame->duration = frame->nb_samples;
255  frame->time_base = tb_filter;
256 }
257 
259 {
260  const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
261  const int fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
262  int64_t codec_duration = 0;
263  // difference between this and last frame's timestamps
264  const int64_t ts_diff =
265  (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE) ?
266  frame->pts - dp->last_frame_pts : -1;
267 
268  // XXX lavf currently makes up frame durations when they are not provided by
269  // the container. As there is no way to reliably distinguish real container
270  // durations from the fake made-up ones, we use heuristics based on whether
271  // the container has timestamps. Eventually lavf should stop making up
272  // durations, then this should be simplified.
273 
274  // frame duration is unreliable (typically guessed by lavf) when it is equal
275  // to 1 and the actual duration of the last frame is more than 2x larger
276  const int duration_unreliable = frame->duration == 1 && ts_diff > 2 * frame->duration;
277 
278  // prefer frame duration for containers with timestamps
279  if (fr_forced ||
280  (frame->duration > 0 && !ts_unreliable && !duration_unreliable))
281  return frame->duration;
282 
283  if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
284  int fields = frame->repeat_pict + 2;
285  AVRational field_rate = av_mul_q(dp->dec_ctx->framerate,
286  (AVRational){ 2, 1 });
287  codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
288  frame->time_base);
289  }
290 
291  // prefer codec-layer duration for containers without timestamps
292  if (codec_duration > 0 && ts_unreliable)
293  return codec_duration;
294 
295  // when timestamps are available, repeat last frame's actual duration
296  // (i.e. pts difference between this and last frame)
297  if (ts_diff > 0)
298  return ts_diff;
299 
300  // try frame/codec duration
301  if (frame->duration > 0)
302  return frame->duration;
303  if (codec_duration > 0)
304  return codec_duration;
305 
306  // try average framerate
307  if (dp->framerate_in.num && dp->framerate_in.den) {
309  frame->time_base);
310  if (d > 0)
311  return d;
312  }
313 
314  // last resort is last frame's estimated duration, and 1
315  return FFMAX(dp->last_frame_duration_est, 1);
316 }
317 
319 {
320  DecoderPriv *dp = avctx->opaque;
321  AVFrame *output = NULL;
323  int err;
324 
325  if (input->format == output_format) {
326  // Nothing to do.
327  return 0;
328  }
329 
331  if (!output)
332  return AVERROR(ENOMEM);
333 
334  output->format = output_format;
335 
337  if (err < 0) {
338  av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
339  "output frame: %d.\n", err);
340  goto fail;
341  }
342 
344  if (err < 0) {
346  goto fail;
347  }
348 
352 
353  return 0;
354 
355 fail:
357  return err;
358 }
359 
361 {
362 #if FFMPEG_OPT_TOP
364  av_log(dp, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
366  }
367 #endif
368 
369  if (frame->format == dp->hwaccel_pix_fmt) {
370  int err = hwaccel_retrieve_data(dp->dec_ctx, frame);
371  if (err < 0)
372  return err;
373  }
374 
375  frame->pts = frame->best_effort_timestamp;
376 
377  // forced fixed framerate
379  frame->pts = AV_NOPTS_VALUE;
380  frame->duration = 1;
381  frame->time_base = av_inv_q(dp->framerate_in);
382  }
383 
384  // no timestamp available - extrapolate from previous frame duration
385  if (frame->pts == AV_NOPTS_VALUE)
386  frame->pts = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
388 
389  // update timestamp history
391  dp->last_frame_pts = frame->pts;
392  dp->last_frame_tb = frame->time_base;
393 
394  if (debug_ts) {
395  av_log(dp, AV_LOG_INFO,
396  "decoder -> pts:%s pts_time:%s "
397  "pkt_dts:%s pkt_dts_time:%s "
398  "duration:%s duration_time:%s "
399  "keyframe:%d frame_type:%d time_base:%d/%d\n",
400  av_ts2str(frame->pts),
401  av_ts2timestr(frame->pts, &frame->time_base),
402  av_ts2str(frame->pkt_dts),
403  av_ts2timestr(frame->pkt_dts, &frame->time_base),
404  av_ts2str(frame->duration),
405  av_ts2timestr(frame->duration, &frame->time_base),
406  !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type,
407  frame->time_base.num, frame->time_base.den);
408  }
409 
410  if (dp->sar_override.num)
411  frame->sample_aspect_ratio = dp->sar_override;
412 
413  if (dp->apply_cropping) {
414  // lavfi does not require aligned frame data
416  if (ret < 0) {
417  av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
418  return ret;
419  }
420  }
421 
422  return 0;
423 }
424 
425 static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
426 {
427  int ret = AVERROR_BUG;
428  AVSubtitle tmp = {
429  .format = src->format,
430  .start_display_time = src->start_display_time,
431  .end_display_time = src->end_display_time,
432  .num_rects = 0,
433  .rects = NULL,
434  .pts = src->pts
435  };
436 
437  if (!src->num_rects)
438  goto success;
439 
440  if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects))))
441  return AVERROR(ENOMEM);
442 
443  for (int i = 0; i < src->num_rects; i++) {
444  AVSubtitleRect *src_rect = src->rects[i];
445  AVSubtitleRect *dst_rect;
446 
447  if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) {
448  ret = AVERROR(ENOMEM);
449  goto cleanup;
450  }
451 
452  tmp.num_rects++;
453 
454  dst_rect->type = src_rect->type;
455  dst_rect->flags = src_rect->flags;
456 
457  dst_rect->x = src_rect->x;
458  dst_rect->y = src_rect->y;
459  dst_rect->w = src_rect->w;
460  dst_rect->h = src_rect->h;
461  dst_rect->nb_colors = src_rect->nb_colors;
462 
463  if (src_rect->text)
464  if (!(dst_rect->text = av_strdup(src_rect->text))) {
465  ret = AVERROR(ENOMEM);
466  goto cleanup;
467  }
468 
469  if (src_rect->ass)
470  if (!(dst_rect->ass = av_strdup(src_rect->ass))) {
471  ret = AVERROR(ENOMEM);
472  goto cleanup;
473  }
474 
475  for (int j = 0; j < 4; j++) {
476  // SUBTITLE_BITMAP images are special in the sense that they
477  // are like PAL8 images. first pointer to data, second to
478  // palette. This makes the size calculation match this.
479  size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ?
481  src_rect->h * src_rect->linesize[j];
482 
483  if (!src_rect->data[j])
484  continue;
485 
486  if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) {
487  ret = AVERROR(ENOMEM);
488  goto cleanup;
489  }
490  dst_rect->linesize[j] = src_rect->linesize[j];
491  }
492  }
493 
494 success:
495  *dst = tmp;
496 
497  return 0;
498 
499 cleanup:
501 
502  return ret;
503 }
504 
505 static void subtitle_free(void *opaque, uint8_t *data)
506 {
507  AVSubtitle *sub = (AVSubtitle*)data;
508  avsubtitle_free(sub);
509  av_free(sub);
510 }
511 
512 static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
513 {
514  AVBufferRef *buf;
515  AVSubtitle *sub;
516  int ret;
517 
518  if (copy) {
519  sub = av_mallocz(sizeof(*sub));
520  ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
521  if (ret < 0) {
522  av_freep(&sub);
523  return ret;
524  }
525  } else {
526  sub = av_memdup(subtitle, sizeof(*subtitle));
527  if (!sub)
528  return AVERROR(ENOMEM);
529  memset(subtitle, 0, sizeof(*subtitle));
530  }
531 
532  buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
533  subtitle_free, NULL, 0);
534  if (!buf) {
535  avsubtitle_free(sub);
536  av_freep(&sub);
537  return AVERROR(ENOMEM);
538  }
539 
540  frame->buf[0] = buf;
541 
542  return 0;
543 }
544 
546 {
547  const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data;
548  int ret = 0;
549 
551  AVSubtitle *sub_prev = dp->sub_prev[0]->buf[0] ?
552  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
553  int end = 1;
554  if (sub_prev) {
555  end = av_rescale(subtitle->pts - sub_prev->pts,
556  1000, AV_TIME_BASE);
557  if (end < sub_prev->end_display_time) {
558  av_log(dp, AV_LOG_DEBUG,
559  "Subtitle duration reduced from %"PRId32" to %d%s\n",
560  sub_prev->end_display_time, end,
561  end <= 0 ? ", dropping it" : "");
562  sub_prev->end_display_time = end;
563  }
564  }
565 
566  av_frame_unref(dp->sub_prev[1]);
568 
569  frame = dp->sub_prev[0];
570  subtitle = frame->buf[0] ? (AVSubtitle*)frame->buf[0]->data : NULL;
571 
572  FFSWAP(AVFrame*, dp->sub_prev[0], dp->sub_prev[1]);
573 
574  if (end <= 0)
575  return 0;
576  }
577 
578  if (!subtitle)
579  return 0;
580 
581  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
582  if (ret < 0)
584 
585  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
586 }
587 
588 static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
589 {
590  int ret = AVERROR_BUG;
591  AVSubtitle *prev_subtitle = dp->sub_prev[0]->buf[0] ?
592  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
593  AVSubtitle *subtitle;
594 
595  if (!(dp->flags & DECODER_FLAG_FIX_SUB_DURATION) || !prev_subtitle ||
596  !prev_subtitle->num_rects || signal_pts <= prev_subtitle->pts)
597  return 0;
598 
600  ret = subtitle_wrap_frame(dp->sub_heartbeat, prev_subtitle, 1);
601  if (ret < 0)
602  return ret;
603 
604  subtitle = (AVSubtitle*)dp->sub_heartbeat->buf[0]->data;
605  subtitle->pts = signal_pts;
606 
607  return process_subtitle(dp, dp->sub_heartbeat);
608 }
609 
611  AVFrame *frame)
612 {
613  AVPacket *flush_pkt = NULL;
614  AVSubtitle subtitle;
615  int got_output;
616  int ret;
617 
618  if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) {
619  frame->pts = pkt->pts;
620  frame->time_base = pkt->time_base;
621  frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT;
622 
623  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
624  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
625  } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) {
627  AV_TIME_BASE_Q));
628  }
629 
630  if (!pkt) {
631  flush_pkt = av_packet_alloc();
632  if (!flush_pkt)
633  return AVERROR(ENOMEM);
634  }
635 
636  ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output,
637  pkt ? pkt : flush_pkt);
638  av_packet_free(&flush_pkt);
639 
640  if (ret < 0) {
641  av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
642  av_err2str(ret));
643  dp->dec.decode_errors++;
644  return exit_on_error ? ret : 0;
645  }
646 
647  if (!got_output)
648  return pkt ? 0 : AVERROR_EOF;
649 
650  dp->dec.frames_decoded++;
651 
652  // XXX the queue for transferring data to consumers runs
653  // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
654  // inside the frame
655  // eventually, subtitles should be switched to use AVFrames natively
656  ret = subtitle_wrap_frame(frame, &subtitle, 0);
657  if (ret < 0) {
658  avsubtitle_free(&subtitle);
659  return ret;
660  }
661 
662  frame->width = dp->dec_ctx->width;
663  frame->height = dp->dec_ctx->height;
664 
665  return process_subtitle(dp, frame);
666 }
667 
669 {
670  AVCodecContext *dec = dp->dec_ctx;
671  const char *type_desc = av_get_media_type_string(dec->codec_type);
672  int ret;
673 
674  if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
675  return transcode_subtitles(dp, pkt, frame);
676 
677  // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
678  // reason. This seems like a semi-critical bug. Don't trigger EOF, and
679  // skip the packet.
680  if (pkt && pkt->size == 0)
681  return 0;
682 
683  if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
686  }
687 
688  if (pkt) {
689  FrameData *fd = packet_data(pkt);
690  if (!fd)
691  return AVERROR(ENOMEM);
693  }
694 
695  ret = avcodec_send_packet(dec, pkt);
696  if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) {
697  // In particular, we don't expect AVERROR(EAGAIN), because we read all
698  // decoded frames with avcodec_receive_frame() until done.
699  if (ret == AVERROR(EAGAIN)) {
700  av_log(dp, AV_LOG_FATAL, "A decoder returned an unexpected error code. "
701  "This is a bug, please report it.\n");
702  return AVERROR_BUG;
703  }
704  av_log(dp, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n",
705  pkt ? "packet" : "EOF", av_err2str(ret));
706 
707  if (ret != AVERROR_EOF) {
708  dp->dec.decode_errors++;
709  if (!exit_on_error)
710  ret = 0;
711  }
712 
713  return ret;
714  }
715 
716  while (1) {
717  FrameData *fd;
718 
720 
723  update_benchmark("decode_%s %s", type_desc, dp->parent_name);
724 
725  if (ret == AVERROR(EAGAIN)) {
726  av_assert0(pkt); // should never happen during flushing
727  return 0;
728  } else if (ret == AVERROR_EOF) {
729  return ret;
730  } else if (ret < 0) {
731  av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
732  dp->dec.decode_errors++;
733 
734  if (exit_on_error)
735  return ret;
736 
737  continue;
738  }
739 
740  if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
742  "corrupt decoded frame\n");
743  if (exit_on_error)
744  return AVERROR_INVALIDDATA;
745  }
746 
747  fd = frame_data(frame);
748  if (!fd) {
750  return AVERROR(ENOMEM);
751  }
752  fd->dec.pts = frame->pts;
753  fd->dec.tb = dec->pkt_timebase;
754  fd->dec.frame_num = dec->frame_num - 1;
756 
758 
759  frame->time_base = dec->pkt_timebase;
760 
761  if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
762  dp->dec.samples_decoded += frame->nb_samples;
763 
764  audio_ts_process(dp, frame);
765  } else {
767  if (ret < 0) {
768  av_log(dp, AV_LOG_FATAL,
769  "Error while processing the decoded data\n");
770  return ret;
771  }
772  }
773 
774  dp->dec.frames_decoded++;
775 
776  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
777  if (ret < 0) {
779  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
780  }
781  }
782 }
783 
784 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
785  const DecoderOpts *o, AVFrame *param_out);
786 
788 {
789  DecoderOpts o;
790  const FrameData *fd;
791  char name[16];
792 
793  if (!pkt->opaque_ref)
794  return AVERROR_BUG;
795  fd = (FrameData *)pkt->opaque_ref->data;
796 
797  if (!fd->par_enc)
798  return AVERROR_BUG;
799 
800  memset(&o, 0, sizeof(o));
801 
802  o.par = fd->par_enc;
803  o.time_base = pkt->time_base;
804 
805  o.codec = dp->standalone_init.codec;
806  if (!o.codec)
808  if (!o.codec) {
810 
811  av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n",
812  desc ? desc->name : "?");
814  }
815 
816  snprintf(name, sizeof(name), "dec%d", dp->index);
817  o.name = name;
818 
819  return dec_open(dp, &dp->standalone_init.opts, &o, NULL);
820 }
821 
822 static void dec_thread_set_name(const DecoderPriv *dp)
823 {
824  char name[16] = "dec";
825 
826  if (dp->index >= 0)
827  av_strlcatf(name, sizeof(name), "%d", dp->index);
828  else if (dp->parent_name)
829  av_strlcat(name, dp->parent_name, sizeof(name));
830 
831  if (dp->dec_ctx)
832  av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name);
833 
835 }
836 
838 {
839  av_packet_free(&dt->pkt);
840  av_frame_free(&dt->frame);
841 
842  memset(dt, 0, sizeof(*dt));
843 }
844 
846 {
847  memset(dt, 0, sizeof(*dt));
848 
849  dt->frame = av_frame_alloc();
850  if (!dt->frame)
851  goto fail;
852 
853  dt->pkt = av_packet_alloc();
854  if (!dt->pkt)
855  goto fail;
856 
857  return 0;
858 
859 fail:
860  dec_thread_uninit(dt);
861  return AVERROR(ENOMEM);
862 }
863 
864 static int decoder_thread(void *arg)
865 {
866  DecoderPriv *dp = arg;
867  DecThreadContext dt;
868  int ret = 0, input_status = 0;
869 
870  ret = dec_thread_init(&dt);
871  if (ret < 0)
872  goto finish;
873 
875 
876  while (!input_status) {
877  int flush_buffers, have_data;
878 
879  input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt);
880  have_data = input_status >= 0 &&
881  (dt.pkt->buf || dt.pkt->side_data_elems ||
882  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT ||
883  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION);
884  flush_buffers = input_status >= 0 && !have_data;
885  if (!have_data)
886  av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n",
887  flush_buffers ? "flush" : "EOF");
888 
889  // this is a standalone decoder that has not been initialized yet
890  if (!dp->dec_ctx) {
891  if (flush_buffers)
892  continue;
893  if (input_status < 0) {
894  av_log(dp, AV_LOG_ERROR,
895  "Cannot initialize a standalone decoder\n");
896  ret = input_status;
897  goto finish;
898  }
899 
900  ret = dec_standalone_open(dp, dt.pkt);
901  if (ret < 0)
902  goto finish;
903  }
904 
905  ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame);
906 
907  av_packet_unref(dt.pkt);
908  av_frame_unref(dt.frame);
909 
910  // AVERROR_EOF - EOF from the decoder
911  // AVERROR_EXIT - EOF from the scheduler
912  // we treat them differently when flushing
913  if (ret == AVERROR_EXIT) {
914  ret = AVERROR_EOF;
915  flush_buffers = 0;
916  }
917 
918  if (ret == AVERROR_EOF) {
919  av_log(dp, AV_LOG_VERBOSE, "Decoder returned EOF, %s\n",
920  flush_buffers ? "resetting" : "finishing");
921 
922  if (!flush_buffers)
923  break;
924 
925  /* report last frame duration to the scheduler */
926  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
928  dt.pkt->time_base = dp->last_frame_tb;
929  }
930 
932  } else if (ret < 0) {
933  av_log(dp, AV_LOG_ERROR, "Error processing packet in decoder: %s\n",
934  av_err2str(ret));
935  break;
936  }
937  }
938 
939  // EOF is normal thread termination
940  if (ret == AVERROR_EOF)
941  ret = 0;
942 
943  // on success send EOF timestamp to our downstreams
944  if (ret >= 0) {
945  float err_rate;
946 
947  av_frame_unref(dt.frame);
948 
949  dt.frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF;
952  dt.frame->time_base = dp->last_frame_tb;
953 
954  ret = sch_dec_send(dp->sch, dp->sch_idx, dt.frame);
955  if (ret < 0 && ret != AVERROR_EOF) {
956  av_log(dp, AV_LOG_FATAL,
957  "Error signalling EOF timestamp: %s\n", av_err2str(ret));
958  goto finish;
959  }
960  ret = 0;
961 
962  err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
963  dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
964  if (err_rate > max_error_rate) {
965  av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
966  err_rate, max_error_rate);
968  } else if (err_rate)
969  av_log(dp, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
970  }
971 
972 finish:
973  dec_thread_uninit(&dt);
974 
975  return ret;
976 }
977 
979 {
980  DecoderPriv *dp = s->opaque;
981  const enum AVPixelFormat *p;
982 
983  for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
985  const AVCodecHWConfig *config = NULL;
986 
987  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
988  break;
989 
990  if (dp->hwaccel_id == HWACCEL_GENERIC ||
991  dp->hwaccel_id == HWACCEL_AUTO) {
992  for (int i = 0;; i++) {
993  config = avcodec_get_hw_config(s->codec, i);
994  if (!config)
995  break;
996  if (!(config->methods &
998  continue;
999  if (config->pix_fmt == *p)
1000  break;
1001  }
1002  }
1003  if (config && config->device_type == dp->hwaccel_device_type) {
1004  dp->hwaccel_pix_fmt = *p;
1005  break;
1006  }
1007  }
1008 
1009  return *p;
1010 }
1011 
1013 {
1014  const AVCodecHWConfig *config;
1015  HWDevice *dev;
1016  for (int i = 0;; i++) {
1017  config = avcodec_get_hw_config(codec, i);
1018  if (!config)
1019  return NULL;
1021  continue;
1022  dev = hw_device_get_by_type(config->device_type);
1023  if (dev)
1024  return dev;
1025  }
1026 }
1027 
1029  const AVCodec *codec,
1030  const char *hwaccel_device)
1031 {
1032  const AVCodecHWConfig *config;
1033  enum AVHWDeviceType type;
1034  HWDevice *dev = NULL;
1035  int err, auto_device = 0;
1036 
1037  if (hwaccel_device) {
1038  dev = hw_device_get_by_name(hwaccel_device);
1039  if (!dev) {
1040  if (dp->hwaccel_id == HWACCEL_AUTO) {
1041  auto_device = 1;
1042  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1043  type = dp->hwaccel_device_type;
1044  err = hw_device_init_from_type(type, hwaccel_device,
1045  &dev);
1046  } else {
1047  // This will be dealt with by API-specific initialisation
1048  // (using hwaccel_device), so nothing further needed here.
1049  return 0;
1050  }
1051  } else {
1052  if (dp->hwaccel_id == HWACCEL_AUTO) {
1053  dp->hwaccel_device_type = dev->type;
1054  } else if (dp->hwaccel_device_type != dev->type) {
1055  av_log(dp, AV_LOG_ERROR, "Invalid hwaccel device "
1056  "specified for decoder: device %s of type %s is not "
1057  "usable with hwaccel %s.\n", dev->name,
1060  return AVERROR(EINVAL);
1061  }
1062  }
1063  } else {
1064  if (dp->hwaccel_id == HWACCEL_AUTO) {
1065  auto_device = 1;
1066  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1067  type = dp->hwaccel_device_type;
1068  dev = hw_device_get_by_type(type);
1069 
1070  // When "-qsv_device device" is used, an internal QSV device named
1071  // as "__qsv_device" is created. Another QSV device is created too
1072  // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices
1073  // if both "-qsv_device device" and "-init_hw_device qsv=name:device"
1074  // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL.
1075  // To keep back-compatibility with the removed ad-hoc libmfx setup code,
1076  // call hw_device_get_by_name("__qsv_device") to select the internal QSV
1077  // device.
1078  if (!dev && type == AV_HWDEVICE_TYPE_QSV)
1079  dev = hw_device_get_by_name("__qsv_device");
1080 
1081  if (!dev)
1082  err = hw_device_init_from_type(type, NULL, &dev);
1083  } else {
1084  dev = hw_device_match_by_codec(codec);
1085  if (!dev) {
1086  // No device for this codec, but not using generic hwaccel
1087  // and therefore may well not need one - ignore.
1088  return 0;
1089  }
1090  }
1091  }
1092 
1093  if (auto_device) {
1094  if (!avcodec_get_hw_config(codec, 0)) {
1095  // Decoder does not support any hardware devices.
1096  return 0;
1097  }
1098  for (int i = 0; !dev; i++) {
1099  config = avcodec_get_hw_config(codec, i);
1100  if (!config)
1101  break;
1102  type = config->device_type;
1103  dev = hw_device_get_by_type(type);
1104  if (dev) {
1105  av_log(dp, AV_LOG_INFO, "Using auto "
1106  "hwaccel type %s with existing device %s.\n",
1108  }
1109  }
1110  for (int i = 0; !dev; i++) {
1111  config = avcodec_get_hw_config(codec, i);
1112  if (!config)
1113  break;
1114  type = config->device_type;
1115  // Try to make a new device of this type.
1116  err = hw_device_init_from_type(type, hwaccel_device,
1117  &dev);
1118  if (err < 0) {
1119  // Can't make a device of this type.
1120  continue;
1121  }
1122  if (hwaccel_device) {
1123  av_log(dp, AV_LOG_INFO, "Using auto "
1124  "hwaccel type %s with new device created "
1125  "from %s.\n", av_hwdevice_get_type_name(type),
1126  hwaccel_device);
1127  } else {
1128  av_log(dp, AV_LOG_INFO, "Using auto "
1129  "hwaccel type %s with new default device.\n",
1131  }
1132  }
1133  if (dev) {
1134  dp->hwaccel_device_type = type;
1135  } else {
1136  av_log(dp, AV_LOG_INFO, "Auto hwaccel "
1137  "disabled: no device found.\n");
1138  dp->hwaccel_id = HWACCEL_NONE;
1139  return 0;
1140  }
1141  }
1142 
1143  if (!dev) {
1144  av_log(dp, AV_LOG_ERROR, "No device available "
1145  "for decoder: device type %s needed for codec %s.\n",
1147  return err;
1148  }
1149 
1151  if (!dp->dec_ctx->hw_device_ctx)
1152  return AVERROR(ENOMEM);
1153 
1154  return 0;
1155 }
1156 
1157 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
1158  const DecoderOpts *o, AVFrame *param_out)
1159 {
1160  const AVCodec *codec = o->codec;
1161  int ret;
1162 
1163  dp->flags = o->flags;
1164  dp->log_parent = o->log_parent;
1165 
1166  dp->dec.type = codec->type;
1167  dp->framerate_in = o->framerate;
1168 
1169  dp->hwaccel_id = o->hwaccel_id;
1172 
1173  snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
1174 
1175  dp->parent_name = av_strdup(o->name ? o->name : "");
1176  if (!dp->parent_name)
1177  return AVERROR(ENOMEM);
1178 
1179  if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
1181  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
1182  dp->sub_prev[i] = av_frame_alloc();
1183  if (!dp->sub_prev[i])
1184  return AVERROR(ENOMEM);
1185  }
1186  dp->sub_heartbeat = av_frame_alloc();
1187  if (!dp->sub_heartbeat)
1188  return AVERROR(ENOMEM);
1189  }
1190 
1192 
1193  dp->dec_ctx = avcodec_alloc_context3(codec);
1194  if (!dp->dec_ctx)
1195  return AVERROR(ENOMEM);
1196 
1198  if (ret < 0) {
1199  av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1200  return ret;
1201  }
1202 
1203  dp->dec_ctx->opaque = dp;
1204  dp->dec_ctx->get_format = get_format;
1205  dp->dec_ctx->pkt_timebase = o->time_base;
1206 
1207  if (!av_dict_get(*dec_opts, "threads", NULL, 0))
1208  av_dict_set(dec_opts, "threads", "auto", 0);
1209 
1211  if (ret < 0) {
1212  av_log(dp, AV_LOG_ERROR,
1213  "Hardware device setup failed for decoder: %s\n",
1214  av_err2str(ret));
1215  return ret;
1216  }
1217 
1219  if (ret < 0) {
1220  av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
1221  av_err2str(ret));
1222  return ret;
1223  }
1224  ret = check_avoptions(*dec_opts);
1225  if (ret < 0)
1226  return ret;
1227 
1229  if (o->flags & DECODER_FLAG_BITEXACT)
1231 
1232  // we apply cropping outselves
1234  dp->dec_ctx->apply_cropping = 0;
1235 
1236  if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
1237  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
1238  av_err2str(ret));
1239  return ret;
1240  }
1241 
1242  if (dp->dec_ctx->hw_device_ctx) {
1243  // Update decoder extra_hw_frames option to account for the
1244  // frames held in queues inside the ffmpeg utility. This is
1245  // called after avcodec_open2() because the user-set value of
1246  // extra_hw_frames becomes valid in there, and we need to add
1247  // this on top of it.
1248  int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
1249  if (dp->dec_ctx->extra_hw_frames >= 0)
1250  dp->dec_ctx->extra_hw_frames += extra_frames;
1251  else
1252  dp->dec_ctx->extra_hw_frames = extra_frames;
1253  }
1254 
1257 
1258  if (param_out) {
1259  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1260  param_out->format = dp->dec_ctx->sample_fmt;
1261  param_out->sample_rate = dp->dec_ctx->sample_rate;
1262 
1263  ret = av_channel_layout_copy(&param_out->ch_layout, &dp->dec_ctx->ch_layout);
1264  if (ret < 0)
1265  return ret;
1266  } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1267  param_out->format = dp->dec_ctx->pix_fmt;
1268  param_out->width = dp->dec_ctx->width;
1269  param_out->height = dp->dec_ctx->height;
1271  param_out->colorspace = dp->dec_ctx->colorspace;
1272  param_out->color_range = dp->dec_ctx->color_range;
1273  }
1274 
1275  param_out->time_base = dp->dec_ctx->pkt_timebase;
1276  }
1277 
1278  return 0;
1279 }
1280 
1281 int dec_init(Decoder **pdec, Scheduler *sch,
1282  AVDictionary **dec_opts, const DecoderOpts *o,
1283  AVFrame *param_out)
1284 {
1285  DecoderPriv *dp;
1286  int ret;
1287 
1288  *pdec = NULL;
1289 
1290  ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
1291  if (ret < 0)
1292  return ret;
1293 
1294  ret = dec_open(dp, dec_opts, o, param_out);
1295  if (ret < 0)
1296  goto fail;
1297 
1298  *pdec = &dp->dec;
1299 
1300  return dp->sch_idx;
1301 fail:
1302  dec_free((Decoder**)&dp);
1303  return ret;
1304 }
1305 
1306 int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
1307 {
1308  DecoderPriv *dp;
1309 
1310  OutputFile *of;
1311  OutputStream *ost;
1312  int of_index, ost_index;
1313  char *p;
1314 
1315  unsigned enc_idx;
1316  int ret;
1317 
1318  ret = dec_alloc(&dp, sch, 0);
1319  if (ret < 0)
1320  return ret;
1321 
1322  dp->index = nb_decoders;
1323 
1325  if (ret < 0) {
1326  dec_free((Decoder **)&dp);
1327  return ret;
1328  }
1329 
1330  decoders[nb_decoders - 1] = (Decoder *)dp;
1331 
1332  of_index = strtol(arg, &p, 0);
1333  if (of_index < 0 || of_index >= nb_output_files) {
1334  av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg);
1335  return AVERROR(EINVAL);
1336  }
1337  of = output_files[of_index];
1338 
1339  ost_index = strtol(p + 1, NULL, 0);
1340  if (ost_index < 0 || ost_index >= of->nb_streams) {
1341  av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg);
1342  return AVERROR(EINVAL);
1343  }
1344  ost = of->streams[ost_index];
1345 
1346  if (!ost->enc) {
1347  av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg);
1348  return AVERROR(EINVAL);
1349  }
1350 
1351  dp->dec.type = ost->type;
1352 
1353  ret = enc_loopback(ost->enc);
1354  if (ret < 0)
1355  return ret;
1356  enc_idx = ret;
1357 
1358  ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC(dp->sch_idx));
1359  if (ret < 0)
1360  return ret;
1361 
1362  ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0);
1363  if (ret < 0)
1364  return ret;
1365 
1366  if (o->codec_names.nb_opt) {
1367  const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str;
1369  if (!dp->standalone_init.codec) {
1370  av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name);
1372  }
1373  }
1374 
1375  return 0;
1376 }
1377 
1379 {
1380  DecoderPriv *dp = dp_from_dec(d);
1381  char name[16];
1382 
1383  snprintf(name, sizeof(name), "dec%d", dp->index);
1384  opts->name = av_strdup(name);
1385  if (!opts->name)
1386  return AVERROR(ENOMEM);
1387 
1388  return dp->sch_idx;
1389 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:605
DecoderPriv::last_frame_tb
AVRational last_frame_tb
Definition: ffmpeg_dec.c:63
AVSubtitle
Definition: avcodec.h:2232
Decoder::subtitle_header
const uint8_t * subtitle_header
Definition: ffmpeg.h:399
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:428
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:134
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:668
AVCodec
AVCodec.
Definition: codec.h:187
copy_av_subtitle
static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
Definition: ffmpeg_dec.c:425
fix_sub_duration_heartbeat
static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
Definition: ffmpeg_dec.c:588
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:653
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
dec_filter_add
int dec_filter_add(Decoder *d, InputFilter *ifilter, InputFilterOptions *opts)
Definition: ffmpeg_dec.c:1378
dec_class
static const AVClass dec_class
Definition: ffmpeg_dec.c:129
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
opt.h
AVCodecContext::get_format
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition: avcodec.h:787
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
FrameData
Definition: ffmpeg.h:649
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1479
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
DecoderPriv::last_frame_duration_est
int64_t last_frame_duration_est
Definition: ffmpeg_dec.c:62
DecoderOpts
Definition: ffmpeg.h:372
audio_samplerate_update
static AVRational audio_samplerate_update(DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:178
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:367
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
LATENCY_PROBE_DEC_POST
@ LATENCY_PROBE_DEC_POST
Definition: ffmpeg.h:101
DecoderPriv::last_frame_pts
int64_t last_frame_pts
Definition: ffmpeg_dec.c:61
dec_thread_uninit
static void dec_thread_uninit(DecThreadContext *dt)
Definition: ffmpeg_dec.c:837
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
dec_alloc
static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
Definition: ffmpeg_dec.c:138
int64_t
long long int64_t
Definition: coverity.c:34
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
AVSubtitleRect
Definition: avcodec.h:2205
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2236
hw_device_match_by_codec
static HWDevice * hw_device_match_by_codec(const AVCodec *codec)
Definition: ffmpeg_dec.c:1012
DecThreadContext::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:94
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:522
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:664
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
cleanup
static av_cold void cleanup(FlashSV2Context *s)
Definition: flashsv2enc.c:130
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:486
AVFrame::width
int width
Definition: frame.h:446
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:363
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:379
dec_item_name
static const char * dec_item_name(void *obj)
Definition: ffmpeg_dec.c:122
dec_thread_init
static int dec_thread_init(DecThreadContext *dt)
Definition: ffmpeg_dec.c:845
DecoderPriv::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg_dec.c:55
DecoderPriv::sub_prev
AVFrame * sub_prev[2]
Definition: ffmpeg_dec.c:68
DecoderPriv::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg_dec.c:56
data
const char data[16]
Definition: mxf.c:148
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:382
DecoderPriv::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:42
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1896
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2217
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
DecoderPriv::index
int index
Definition: ffmpeg_dec.c:75
DecoderPriv::sub_heartbeat
AVFrame * sub_heartbeat
Definition: ffmpeg_dec.c:69
AVDictionary
Definition: dict.c:34
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
HWDevice
Definition: ffmpeg.h:109
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
DECODER_FLAG_BITEXACT
@ DECODER_FLAG_BITEXACT
Definition: ffmpeg.h:369
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:587
DecoderPriv::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg_dec.c:54
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
tf_sess_config.config
config
Definition: tf_sess_config.py:33
enc_loopback
int enc_loopback(Encoder *enc)
Definition: ffmpeg_enc.c:922
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:97
DEFAULT_FRAME_THREAD_QUEUE_SIZE
#define DEFAULT_FRAME_THREAD_QUEUE_SIZE
Default size of a frame thread queue.
Definition: ffmpeg_sched.h:250
av_frame_apply_cropping
int av_frame_apply_cropping(AVFrame *frame, int flags)
Crop the given video AVFrame according to its crop_left/crop_top/crop_right/ crop_bottom fields.
Definition: frame.c:1064
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:638
FrameData::frame_num
uint64_t frame_num
Definition: ffmpeg.h:656
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:640
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
DecoderPriv::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg_dec.c:39
DecoderPriv::apply_cropping
int apply_cropping
Definition: ffmpeg_dec.c:51
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:385
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:69
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:299
finish
static void finish(void)
Definition: movenc.c:373
FRAME_OPAQUE_SUB_HEARTBEAT
@ FRAME_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:88
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:454
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:569
DecoderPriv
Definition: ffmpeg_dec.c:36
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:124
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:403
fail
#define fail()
Definition: checkasm.h:188
sch_dec_send
int sch_dec_send(Scheduler *sch, unsigned dec_idx, AVFrame *frame)
Called by decoder tasks to send a decoded frame downstream.
Definition: ffmpeg_sched.c:2174
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
get_format
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
Definition: ffmpeg_dec.c:978
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2206
DecoderPriv::log_parent
void * log_parent
Definition: ffmpeg_dec.c:76
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:376
DecoderPriv::dec
Decoder dec
Definition: ffmpeg_dec.c:37
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
update_benchmark
void update_benchmark(const char *fmt,...)
Definition: ffmpeg.c:527
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:775
SCH_ENC
#define SCH_ENC(encoder)
Definition: ffmpeg_sched.h:120
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
OptionsContext
Definition: ffmpeg.h:123
FrameData::tb
AVRational tb
Definition: ffmpeg.h:659
codec.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
DecoderPriv::parent_name
char * parent_name
Definition: ffmpeg_dec.c:78
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:404
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2229
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:397
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:975
avassert.h
DecThreadContext
Definition: ffmpeg_dec.c:92
DecoderPriv::log_name
char log_name[32]
Definition: ffmpeg_dec.c:77
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
dec_create
int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
Create a standalone decoder.
Definition: ffmpeg_dec.c:1306
DecoderPriv::frame
AVFrame * frame
Definition: ffmpeg_dec.c:41
hwaccel_retrieve_data
static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
Definition: ffmpeg_dec.c:318
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:341
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:179
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
DecThreadContext::frame
AVFrame * frame
Definition: ffmpeg_dec.c:93
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:84
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:144
subtitle_wrap_frame
static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
Definition: ffmpeg_dec.c:512
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVSubtitleRect::y
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2207
InputFilter
Definition: ffmpeg.h:323
avcodec_receive_frame
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
Definition: avcodec.c:702
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1579
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
FrameData::dec
struct FrameData::@4 dec
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
max_error_rate
float max_error_rate
Definition: ffmpeg_opt.c:74
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2238
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:384
DecoderPriv::last_filter_in_rescale_delta
int64_t last_filter_in_rescale_delta
Definition: ffmpeg_dec.c:64
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:112
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:558
AVSubtitleRect::text
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:2222
av_rescale_delta
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)
Rescale a timestamp while preserving known durations.
Definition: mathematics.c:168
arg
const char * arg
Definition: jacosubdec.c:67
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
if
if(ret)
Definition: filter_design.txt:179
opts
AVDictionary * opts
Definition: movenc.c:51
audio_ts_process
static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:221
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:516
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
AVSubtitleRect::w
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:2208
hw_device_setup_for_decode
static int hw_device_setup_for_decode(DecoderPriv *dp, const AVCodec *codec, const char *hwaccel_device)
Definition: ffmpeg_dec.c:1028
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
avcodec_find_decoder_by_name
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:1033
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:405
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:711
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1966
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
DecoderPriv::framerate_in
AVRational framerate_in
Definition: ffmpeg_dec.c:47
dec_open
static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1157
AVCodec::type
enum AVMediaType type
Definition: codec.h:200
Decoder
Definition: ffmpeg.h:394
dec_thread_set_name
static void dec_thread_set_name(const DecoderPriv *dp)
Definition: ffmpeg_dec.c:822
hw_device_init_from_type
int hw_device_init_from_type(enum AVHWDeviceType type, const char *device, HWDevice **dev_out)
Definition: ffmpeg_hw.c:243
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
transcode_subtitles
static int transcode_subtitles(DecoderPriv *dp, const AVPacket *pkt, AVFrame *frame)
Definition: ffmpeg_dec.c:610
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVCodecContext::subtitle_header_size
int subtitle_header_size
Header containing style information for text subtitles.
Definition: avcodec.h:1895
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2216
sch_add_dec
int sch_add_dec(Scheduler *sch, SchThreadFunc func, void *ctx, int send_end_ts)
Add a decoder to the scheduler.
Definition: ffmpeg_sched.c:721
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:666
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:143
time.h
InputFilterOptions
Definition: ffmpeg.h:246
DecoderPriv::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg_dec.c:53
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:358
DecoderPriv::last_frame_sample_rate
int last_frame_sample_rate
Definition: ffmpeg_dec.c:65
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:639
error.h
Scheduler
Definition: ffmpeg_sched.c:269
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1005
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
AVPacket::size
int size
Definition: packet.h:534
DecoderPriv::sch
Scheduler * sch
Definition: ffmpeg_dec.c:71
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1524
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1281
output_files
OutputFile ** output_files
Definition: ffmpeg.c:107
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:573
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:551
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:501
HWDevice::device_ref
AVBufferRef * device_ref
Definition: ffmpeg.h:112
hw_device_get_by_type
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
Definition: ffmpeg_hw.c:28
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:461
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:453
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2235
AVSubtitleRect::type
enum AVSubtitleType type
Definition: avcodec.h:2220
LATENCY_PROBE_DEC_PRE
@ LATENCY_PROBE_DEC_PRE
Definition: ffmpeg.h:100
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:532
FrameData::pts
int64_t pts
Definition: ffmpeg.h:658
DecoderPriv::codec
const AVCodec * codec
Definition: ffmpeg_dec.c:82
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:178
video_frame_process
static int video_frame_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:360
SCH_DEC
#define SCH_DEC(decoder)
Definition: ffmpeg_sched.h:117
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
decoders
Decoder ** decoders
Definition: ffmpeg.c:113
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
nb_decoders
int nb_decoders
Definition: ffmpeg.c:114
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2188
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:83
AVSubtitleRect::flags
int flags
Definition: avcodec.h:2219
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:720
video_duration_estimate
static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:258
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:526
process_subtitle
static int process_subtitle(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:545
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:664
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:621
AVSubtitleRect::nb_colors
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:2210
OptionsContext::codec_names
SpecifierOptList codec_names
Definition: ffmpeg.h:132
av_opt_set_dict2
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition: opt.c:1928
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
packet_decode
static int packet_decode(DecoderPriv *dp, AVPacket *pkt, AVFrame *frame)
Definition: ffmpeg_dec.c:668
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:387
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:70
FRAME_OPAQUE_EOF
@ FRAME_OPAQUE_EOF
Definition: ffmpeg.h:89
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:635
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:608
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AV_FRAME_CROP_UNALIGNED
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition: frame.h:999
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1501
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
nb_output_files
int nb_output_files
Definition: ffmpeg.c:108
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:897
avcodec.h
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2035
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
AVSubtitleRect::h
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:2209
pixfmt.h
sch_dec_receive
int sch_dec_receive(Scheduler *sch, unsigned dec_idx, AVPacket *pkt)
Called by decoder tasks to receive a packet for decoding.
Definition: ffmpeg_sched.c:2098
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
avcodec_flush_buffers
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
Definition: avcodec.c:365
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
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
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:95
DecoderPriv::flags
int flags
Definition: ffmpeg_dec.c:50
AVCodecContext::opaque
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:487
DECODER_FLAG_TOP_FIELD_FIRST
@ DECODER_FLAG_TOP_FIELD_FIRST
Definition: ffmpeg.h:365
HWAccelID
HWAccelID
Definition: ffmpeg.h:81
dict.h
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:481
av_hwframe_transfer_data
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition: hwcontext.c:433
DecoderPriv::sar_override
AVRational sar_override
Definition: ffmpeg_dec.c:45
AV_HWDEVICE_TYPE_QSV
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFrame::height
int height
Definition: frame.h:446
DecoderPriv::opts
AVDictionary * opts
Definition: ffmpeg_dec.c:81
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:94
HWDevice::name
const char * name
Definition: ffmpeg.h:110
dp_from_dec
static DecoderPriv * dp_from_dec(Decoder *d)
Definition: ffmpeg_dec.c:86
AVRational::den
int den
Denominator.
Definition: rational.h:60
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:168
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
output_format
static char * output_format
Definition: ffprobe.c:150
Decoder::subtitle_header_size
int subtitle_header_size
Definition: ffmpeg.h:400
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:530
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:82
avcodec_get_hw_config
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:833
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:444
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
DecoderOpts::flags
int flags
Definition: ffmpeg.h:373
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:453
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
SpecifierOpt::u
union SpecifierOpt::@0 u
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:360
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:378
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
decoder_thread
static int decoder_thread(void *arg)
Definition: ffmpeg_dec.c:864
FFMPEG_ERROR_RATE_EXCEEDED
#define FFMPEG_ERROR_RATE_EXCEEDED
Definition: ffmpeg.h:63
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:510
Decoder::class
const AVClass * class
Definition: ffmpeg.h:395
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
HWDevice::type
enum AVHWDeviceType type
Definition: ffmpeg.h:111
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:237
Decoder::type
enum AVMediaType type
Definition: ffmpeg.h:397
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:465
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
timestamp.h
OutputStream
Definition: mux.c:53
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:313
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:391
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
AVCodecHWConfig
Definition: codec.h:345
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
subtitle_free
static void subtitle_free(void *opaque, uint8_t *data)
Definition: ffmpeg_dec.c:505
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3735
DecoderPriv::sch_idx
unsigned sch_idx
Definition: ffmpeg_dec.c:72
avstring.h
hw_device_get_by_name
HWDevice * hw_device_get_by_name(const char *name)
Definition: ffmpeg_hw.c:42
snprintf
#define snprintf
Definition: snprintf.h:34
PKT_OPAQUE_FIX_SUB_DURATION
@ PKT_OPAQUE_FIX_SUB_DURATION
Definition: ffmpeg.h:95
DecoderPriv::standalone_init
struct DecoderPriv::@5 standalone_init
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:383
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:642
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:577
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:545
dec_standalone_open
static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt)
Definition: ffmpeg_dec.c:787
OutputFile
Definition: ffmpeg.h:632
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
DecoderOpts::name
char * name
Definition: ffmpeg.h:375