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
61  int64_t last_frame_pts;
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
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 
258 static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
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 
264  // XXX lavf currently makes up frame durations when they are not provided by
265  // the container. As there is no way to reliably distinguish real container
266  // durations from the fake made-up ones, we use heuristics based on whether
267  // the container has timestamps. Eventually lavf should stop making up
268  // durations, then this should be simplified.
269 
270  // prefer frame duration for containers with timestamps
271  if (frame->duration > 0 && (!ts_unreliable || fr_forced))
272  return frame->duration;
273 
274  if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
275  int fields = frame->repeat_pict + 2;
276  AVRational field_rate = av_mul_q(dp->dec_ctx->framerate,
277  (AVRational){ 2, 1 });
278  codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
279  frame->time_base);
280  }
281 
282  // prefer codec-layer duration for containers without timestamps
283  if (codec_duration > 0 && ts_unreliable)
284  return codec_duration;
285 
286  // when timestamps are available, repeat last frame's actual duration
287  // (i.e. pts difference between this and last frame)
288  if (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE &&
289  frame->pts > dp->last_frame_pts)
290  return frame->pts - dp->last_frame_pts;
291 
292  // try frame/codec duration
293  if (frame->duration > 0)
294  return frame->duration;
295  if (codec_duration > 0)
296  return codec_duration;
297 
298  // try average framerate
299  if (dp->framerate_in.num && dp->framerate_in.den) {
300  int64_t d = av_rescale_q(1, av_inv_q(dp->framerate_in),
301  frame->time_base);
302  if (d > 0)
303  return d;
304  }
305 
306  // last resort is last frame's estimated duration, and 1
307  return FFMAX(dp->last_frame_duration_est, 1);
308 }
309 
311 {
312  DecoderPriv *dp = avctx->opaque;
313  AVFrame *output = NULL;
315  int err;
316 
317  if (input->format == output_format) {
318  // Nothing to do.
319  return 0;
320  }
321 
323  if (!output)
324  return AVERROR(ENOMEM);
325 
326  output->format = output_format;
327 
329  if (err < 0) {
330  av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
331  "output frame: %d.\n", err);
332  goto fail;
333  }
334 
336  if (err < 0) {
338  goto fail;
339  }
340 
344 
345  return 0;
346 
347 fail:
349  return err;
350 }
351 
353 {
354 #if FFMPEG_OPT_TOP
356  av_log(dp, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
358  }
359 #endif
360 
361  if (frame->format == dp->hwaccel_pix_fmt) {
362  int err = hwaccel_retrieve_data(dp->dec_ctx, frame);
363  if (err < 0)
364  return err;
365  }
366 
367  frame->pts = frame->best_effort_timestamp;
368 
369  // forced fixed framerate
371  frame->pts = AV_NOPTS_VALUE;
372  frame->duration = 1;
373  frame->time_base = av_inv_q(dp->framerate_in);
374  }
375 
376  // no timestamp available - extrapolate from previous frame duration
377  if (frame->pts == AV_NOPTS_VALUE)
378  frame->pts = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
380 
381  // update timestamp history
383  dp->last_frame_pts = frame->pts;
384  dp->last_frame_tb = frame->time_base;
385 
386  if (debug_ts) {
387  av_log(dp, AV_LOG_INFO,
388  "decoder -> pts:%s pts_time:%s "
389  "pkt_dts:%s pkt_dts_time:%s "
390  "duration:%s duration_time:%s "
391  "keyframe:%d frame_type:%d time_base:%d/%d\n",
392  av_ts2str(frame->pts),
393  av_ts2timestr(frame->pts, &frame->time_base),
394  av_ts2str(frame->pkt_dts),
395  av_ts2timestr(frame->pkt_dts, &frame->time_base),
396  av_ts2str(frame->duration),
397  av_ts2timestr(frame->duration, &frame->time_base),
398  !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type,
399  frame->time_base.num, frame->time_base.den);
400  }
401 
402  if (dp->sar_override.num)
403  frame->sample_aspect_ratio = dp->sar_override;
404 
405  if (dp->apply_cropping) {
406  // lavfi does not require aligned frame data
408  if (ret < 0) {
409  av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
410  return ret;
411  }
412  }
413 
414  return 0;
415 }
416 
417 static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
418 {
419  int ret = AVERROR_BUG;
420  AVSubtitle tmp = {
421  .format = src->format,
422  .start_display_time = src->start_display_time,
423  .end_display_time = src->end_display_time,
424  .num_rects = 0,
425  .rects = NULL,
426  .pts = src->pts
427  };
428 
429  if (!src->num_rects)
430  goto success;
431 
432  if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects))))
433  return AVERROR(ENOMEM);
434 
435  for (int i = 0; i < src->num_rects; i++) {
436  AVSubtitleRect *src_rect = src->rects[i];
437  AVSubtitleRect *dst_rect;
438 
439  if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) {
440  ret = AVERROR(ENOMEM);
441  goto cleanup;
442  }
443 
444  tmp.num_rects++;
445 
446  dst_rect->type = src_rect->type;
447  dst_rect->flags = src_rect->flags;
448 
449  dst_rect->x = src_rect->x;
450  dst_rect->y = src_rect->y;
451  dst_rect->w = src_rect->w;
452  dst_rect->h = src_rect->h;
453  dst_rect->nb_colors = src_rect->nb_colors;
454 
455  if (src_rect->text)
456  if (!(dst_rect->text = av_strdup(src_rect->text))) {
457  ret = AVERROR(ENOMEM);
458  goto cleanup;
459  }
460 
461  if (src_rect->ass)
462  if (!(dst_rect->ass = av_strdup(src_rect->ass))) {
463  ret = AVERROR(ENOMEM);
464  goto cleanup;
465  }
466 
467  for (int j = 0; j < 4; j++) {
468  // SUBTITLE_BITMAP images are special in the sense that they
469  // are like PAL8 images. first pointer to data, second to
470  // palette. This makes the size calculation match this.
471  size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ?
473  src_rect->h * src_rect->linesize[j];
474 
475  if (!src_rect->data[j])
476  continue;
477 
478  if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) {
479  ret = AVERROR(ENOMEM);
480  goto cleanup;
481  }
482  dst_rect->linesize[j] = src_rect->linesize[j];
483  }
484  }
485 
486 success:
487  *dst = tmp;
488 
489  return 0;
490 
491 cleanup:
493 
494  return ret;
495 }
496 
497 static void subtitle_free(void *opaque, uint8_t *data)
498 {
499  AVSubtitle *sub = (AVSubtitle*)data;
500  avsubtitle_free(sub);
501  av_free(sub);
502 }
503 
504 static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
505 {
506  AVBufferRef *buf;
507  AVSubtitle *sub;
508  int ret;
509 
510  if (copy) {
511  sub = av_mallocz(sizeof(*sub));
512  ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
513  if (ret < 0) {
514  av_freep(&sub);
515  return ret;
516  }
517  } else {
518  sub = av_memdup(subtitle, sizeof(*subtitle));
519  if (!sub)
520  return AVERROR(ENOMEM);
521  memset(subtitle, 0, sizeof(*subtitle));
522  }
523 
524  buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
525  subtitle_free, NULL, 0);
526  if (!buf) {
527  avsubtitle_free(sub);
528  av_freep(&sub);
529  return AVERROR(ENOMEM);
530  }
531 
532  frame->buf[0] = buf;
533 
534  return 0;
535 }
536 
538 {
539  const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data;
540  int ret = 0;
541 
543  AVSubtitle *sub_prev = dp->sub_prev[0]->buf[0] ?
544  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
545  int end = 1;
546  if (sub_prev) {
547  end = av_rescale(subtitle->pts - sub_prev->pts,
548  1000, AV_TIME_BASE);
549  if (end < sub_prev->end_display_time) {
550  av_log(dp, AV_LOG_DEBUG,
551  "Subtitle duration reduced from %"PRId32" to %d%s\n",
552  sub_prev->end_display_time, end,
553  end <= 0 ? ", dropping it" : "");
554  sub_prev->end_display_time = end;
555  }
556  }
557 
558  av_frame_unref(dp->sub_prev[1]);
560 
561  frame = dp->sub_prev[0];
562  subtitle = frame->buf[0] ? (AVSubtitle*)frame->buf[0]->data : NULL;
563 
564  FFSWAP(AVFrame*, dp->sub_prev[0], dp->sub_prev[1]);
565 
566  if (end <= 0)
567  return 0;
568  }
569 
570  if (!subtitle)
571  return 0;
572 
573  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
574  if (ret < 0)
576 
577  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
578 }
579 
580 static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
581 {
582  int ret = AVERROR_BUG;
583  AVSubtitle *prev_subtitle = dp->sub_prev[0]->buf[0] ?
584  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
585  AVSubtitle *subtitle;
586 
587  if (!(dp->flags & DECODER_FLAG_FIX_SUB_DURATION) || !prev_subtitle ||
588  !prev_subtitle->num_rects || signal_pts <= prev_subtitle->pts)
589  return 0;
590 
592  ret = subtitle_wrap_frame(dp->sub_heartbeat, prev_subtitle, 1);
593  if (ret < 0)
594  return ret;
595 
596  subtitle = (AVSubtitle*)dp->sub_heartbeat->buf[0]->data;
597  subtitle->pts = signal_pts;
598 
599  return process_subtitle(dp, dp->sub_heartbeat);
600 }
601 
603  AVFrame *frame)
604 {
605  AVPacket *flush_pkt = NULL;
606  AVSubtitle subtitle;
607  int got_output;
608  int ret;
609 
610  if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) {
611  frame->pts = pkt->pts;
612  frame->time_base = pkt->time_base;
613  frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT;
614 
615  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
616  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
617  } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) {
619  AV_TIME_BASE_Q));
620  }
621 
622  if (!pkt) {
623  flush_pkt = av_packet_alloc();
624  if (!flush_pkt)
625  return AVERROR(ENOMEM);
626  }
627 
628  ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output,
629  pkt ? pkt : flush_pkt);
630  av_packet_free(&flush_pkt);
631 
632  if (ret < 0) {
633  av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
634  av_err2str(ret));
635  dp->dec.decode_errors++;
636  return exit_on_error ? ret : 0;
637  }
638 
639  if (!got_output)
640  return pkt ? 0 : AVERROR_EOF;
641 
642  dp->dec.frames_decoded++;
643 
644  // XXX the queue for transferring data to consumers runs
645  // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
646  // inside the frame
647  // eventually, subtitles should be switched to use AVFrames natively
648  ret = subtitle_wrap_frame(frame, &subtitle, 0);
649  if (ret < 0) {
650  avsubtitle_free(&subtitle);
651  return ret;
652  }
653 
654  frame->width = dp->dec_ctx->width;
655  frame->height = dp->dec_ctx->height;
656 
657  return process_subtitle(dp, frame);
658 }
659 
661 {
662  AVCodecContext *dec = dp->dec_ctx;
663  const char *type_desc = av_get_media_type_string(dec->codec_type);
664  int ret;
665 
666  if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
667  return transcode_subtitles(dp, pkt, frame);
668 
669  // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
670  // reason. This seems like a semi-critical bug. Don't trigger EOF, and
671  // skip the packet.
672  if (pkt && pkt->size == 0)
673  return 0;
674 
675  if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
678  }
679 
680  if (pkt) {
681  FrameData *fd = packet_data(pkt);
682  if (!fd)
683  return AVERROR(ENOMEM);
685  }
686 
687  ret = avcodec_send_packet(dec, pkt);
688  if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) {
689  // In particular, we don't expect AVERROR(EAGAIN), because we read all
690  // decoded frames with avcodec_receive_frame() until done.
691  if (ret == AVERROR(EAGAIN)) {
692  av_log(dp, AV_LOG_FATAL, "A decoder returned an unexpected error code. "
693  "This is a bug, please report it.\n");
694  return AVERROR_BUG;
695  }
696  av_log(dp, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n",
697  pkt ? "packet" : "EOF", av_err2str(ret));
698 
699  if (ret != AVERROR_EOF) {
700  dp->dec.decode_errors++;
701  if (!exit_on_error)
702  ret = 0;
703  }
704 
705  return ret;
706  }
707 
708  while (1) {
709  FrameData *fd;
710 
712 
715  update_benchmark("decode_%s %s", type_desc, dp->parent_name);
716 
717  if (ret == AVERROR(EAGAIN)) {
718  av_assert0(pkt); // should never happen during flushing
719  return 0;
720  } else if (ret == AVERROR_EOF) {
721  return ret;
722  } else if (ret < 0) {
723  av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
724  dp->dec.decode_errors++;
725 
726  if (exit_on_error)
727  return ret;
728 
729  continue;
730  }
731 
732  if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
734  "corrupt decoded frame\n");
735  if (exit_on_error)
736  return AVERROR_INVALIDDATA;
737  }
738 
739  fd = frame_data(frame);
740  if (!fd) {
742  return AVERROR(ENOMEM);
743  }
744  fd->dec.pts = frame->pts;
745  fd->dec.tb = dec->pkt_timebase;
746  fd->dec.frame_num = dec->frame_num - 1;
748 
750 
751  frame->time_base = dec->pkt_timebase;
752 
753  if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
754  dp->dec.samples_decoded += frame->nb_samples;
755 
756  audio_ts_process(dp, frame);
757  } else {
759  if (ret < 0) {
760  av_log(dp, AV_LOG_FATAL,
761  "Error while processing the decoded data\n");
762  return ret;
763  }
764  }
765 
766  dp->dec.frames_decoded++;
767 
768  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
769  if (ret < 0) {
771  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
772  }
773  }
774 }
775 
776 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
777  const DecoderOpts *o, AVFrame *param_out);
778 
780 {
781  DecoderOpts o;
782  const FrameData *fd;
783  char name[16];
784 
785  if (!pkt->opaque_ref)
786  return AVERROR_BUG;
787  fd = (FrameData *)pkt->opaque_ref->data;
788 
789  if (!fd->par_enc)
790  return AVERROR_BUG;
791 
792  memset(&o, 0, sizeof(o));
793 
794  o.par = fd->par_enc;
795  o.time_base = pkt->time_base;
796 
797  o.codec = dp->standalone_init.codec;
798  if (!o.codec)
800  if (!o.codec) {
802 
803  av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n",
804  desc ? desc->name : "?");
806  }
807 
808  snprintf(name, sizeof(name), "dec%d", dp->index);
809  o.name = name;
810 
811  return dec_open(dp, &dp->standalone_init.opts, &o, NULL);
812 }
813 
814 static void dec_thread_set_name(const DecoderPriv *dp)
815 {
816  char name[16] = "dec";
817 
818  if (dp->index >= 0)
819  av_strlcatf(name, sizeof(name), "%d", dp->index);
820  else if (dp->parent_name)
821  av_strlcat(name, dp->parent_name, sizeof(name));
822 
823  if (dp->dec_ctx)
824  av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name);
825 
827 }
828 
830 {
831  av_packet_free(&dt->pkt);
832  av_frame_free(&dt->frame);
833 
834  memset(dt, 0, sizeof(*dt));
835 }
836 
838 {
839  memset(dt, 0, sizeof(*dt));
840 
841  dt->frame = av_frame_alloc();
842  if (!dt->frame)
843  goto fail;
844 
845  dt->pkt = av_packet_alloc();
846  if (!dt->pkt)
847  goto fail;
848 
849  return 0;
850 
851 fail:
852  dec_thread_uninit(dt);
853  return AVERROR(ENOMEM);
854 }
855 
856 static int decoder_thread(void *arg)
857 {
858  DecoderPriv *dp = arg;
859  DecThreadContext dt;
860  int ret = 0, input_status = 0;
861 
862  ret = dec_thread_init(&dt);
863  if (ret < 0)
864  goto finish;
865 
867 
868  while (!input_status) {
869  int flush_buffers, have_data;
870 
871  input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt);
872  have_data = input_status >= 0 &&
873  (dt.pkt->buf || dt.pkt->side_data_elems ||
874  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT ||
875  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION);
876  flush_buffers = input_status >= 0 && !have_data;
877  if (!have_data)
878  av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n",
879  flush_buffers ? "flush" : "EOF");
880 
881  // this is a standalone decoder that has not been initialized yet
882  if (!dp->dec_ctx) {
883  if (flush_buffers)
884  continue;
885  if (input_status < 0) {
886  av_log(dp, AV_LOG_ERROR,
887  "Cannot initialize a standalone decoder\n");
888  ret = input_status;
889  goto finish;
890  }
891 
892  ret = dec_standalone_open(dp, dt.pkt);
893  if (ret < 0)
894  goto finish;
895  }
896 
897  ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame);
898 
899  av_packet_unref(dt.pkt);
900  av_frame_unref(dt.frame);
901 
902  // AVERROR_EOF - EOF from the decoder
903  // AVERROR_EXIT - EOF from the scheduler
904  // we treat them differently when flushing
905  if (ret == AVERROR_EXIT) {
906  ret = AVERROR_EOF;
907  flush_buffers = 0;
908  }
909 
910  if (ret == AVERROR_EOF) {
911  av_log(dp, AV_LOG_VERBOSE, "Decoder returned EOF, %s\n",
912  flush_buffers ? "resetting" : "finishing");
913 
914  if (!flush_buffers)
915  break;
916 
917  /* report last frame duration to the scheduler */
918  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
920  dt.pkt->time_base = dp->last_frame_tb;
921  }
922 
924  } else if (ret < 0) {
925  av_log(dp, AV_LOG_ERROR, "Error processing packet in decoder: %s\n",
926  av_err2str(ret));
927  break;
928  }
929  }
930 
931  // EOF is normal thread termination
932  if (ret == AVERROR_EOF)
933  ret = 0;
934 
935  // on success send EOF timestamp to our downstreams
936  if (ret >= 0) {
937  float err_rate;
938 
939  av_frame_unref(dt.frame);
940 
941  dt.frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF;
944  dt.frame->time_base = dp->last_frame_tb;
945 
946  ret = sch_dec_send(dp->sch, dp->sch_idx, dt.frame);
947  if (ret < 0 && ret != AVERROR_EOF) {
948  av_log(dp, AV_LOG_FATAL,
949  "Error signalling EOF timestamp: %s\n", av_err2str(ret));
950  goto finish;
951  }
952  ret = 0;
953 
954  err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
955  dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
956  if (err_rate > max_error_rate) {
957  av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
958  err_rate, max_error_rate);
960  } else if (err_rate)
961  av_log(dp, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
962  }
963 
964 finish:
965  dec_thread_uninit(&dt);
966 
967  return ret;
968 }
969 
971 {
972  DecoderPriv *dp = s->opaque;
973  const enum AVPixelFormat *p;
974 
975  for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
977  const AVCodecHWConfig *config = NULL;
978 
979  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
980  break;
981 
982  if (dp->hwaccel_id == HWACCEL_GENERIC ||
983  dp->hwaccel_id == HWACCEL_AUTO) {
984  for (int i = 0;; i++) {
985  config = avcodec_get_hw_config(s->codec, i);
986  if (!config)
987  break;
988  if (!(config->methods &
990  continue;
991  if (config->pix_fmt == *p)
992  break;
993  }
994  }
995  if (config && config->device_type == dp->hwaccel_device_type) {
996  dp->hwaccel_pix_fmt = *p;
997  break;
998  }
999  }
1000 
1001  return *p;
1002 }
1003 
1005 {
1006  const AVCodecHWConfig *config;
1007  HWDevice *dev;
1008  for (int i = 0;; i++) {
1009  config = avcodec_get_hw_config(codec, i);
1010  if (!config)
1011  return NULL;
1013  continue;
1014  dev = hw_device_get_by_type(config->device_type);
1015  if (dev)
1016  return dev;
1017  }
1018 }
1019 
1021  const AVCodec *codec,
1022  const char *hwaccel_device)
1023 {
1024  const AVCodecHWConfig *config;
1025  enum AVHWDeviceType type;
1026  HWDevice *dev = NULL;
1027  int err, auto_device = 0;
1028 
1029  if (hwaccel_device) {
1030  dev = hw_device_get_by_name(hwaccel_device);
1031  if (!dev) {
1032  if (dp->hwaccel_id == HWACCEL_AUTO) {
1033  auto_device = 1;
1034  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1035  type = dp->hwaccel_device_type;
1036  err = hw_device_init_from_type(type, hwaccel_device,
1037  &dev);
1038  } else {
1039  // This will be dealt with by API-specific initialisation
1040  // (using hwaccel_device), so nothing further needed here.
1041  return 0;
1042  }
1043  } else {
1044  if (dp->hwaccel_id == HWACCEL_AUTO) {
1045  dp->hwaccel_device_type = dev->type;
1046  } else if (dp->hwaccel_device_type != dev->type) {
1047  av_log(dp, AV_LOG_ERROR, "Invalid hwaccel device "
1048  "specified for decoder: device %s of type %s is not "
1049  "usable with hwaccel %s.\n", dev->name,
1052  return AVERROR(EINVAL);
1053  }
1054  }
1055  } else {
1056  if (dp->hwaccel_id == HWACCEL_AUTO) {
1057  auto_device = 1;
1058  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1059  type = dp->hwaccel_device_type;
1060  dev = hw_device_get_by_type(type);
1061 
1062  // When "-qsv_device device" is used, an internal QSV device named
1063  // as "__qsv_device" is created. Another QSV device is created too
1064  // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices
1065  // if both "-qsv_device device" and "-init_hw_device qsv=name:device"
1066  // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL.
1067  // To keep back-compatibility with the removed ad-hoc libmfx setup code,
1068  // call hw_device_get_by_name("__qsv_device") to select the internal QSV
1069  // device.
1070  if (!dev && type == AV_HWDEVICE_TYPE_QSV)
1071  dev = hw_device_get_by_name("__qsv_device");
1072 
1073  if (!dev)
1074  err = hw_device_init_from_type(type, NULL, &dev);
1075  } else {
1076  dev = hw_device_match_by_codec(codec);
1077  if (!dev) {
1078  // No device for this codec, but not using generic hwaccel
1079  // and therefore may well not need one - ignore.
1080  return 0;
1081  }
1082  }
1083  }
1084 
1085  if (auto_device) {
1086  if (!avcodec_get_hw_config(codec, 0)) {
1087  // Decoder does not support any hardware devices.
1088  return 0;
1089  }
1090  for (int i = 0; !dev; i++) {
1091  config = avcodec_get_hw_config(codec, i);
1092  if (!config)
1093  break;
1094  type = config->device_type;
1095  dev = hw_device_get_by_type(type);
1096  if (dev) {
1097  av_log(dp, AV_LOG_INFO, "Using auto "
1098  "hwaccel type %s with existing device %s.\n",
1100  }
1101  }
1102  for (int i = 0; !dev; i++) {
1103  config = avcodec_get_hw_config(codec, i);
1104  if (!config)
1105  break;
1106  type = config->device_type;
1107  // Try to make a new device of this type.
1108  err = hw_device_init_from_type(type, hwaccel_device,
1109  &dev);
1110  if (err < 0) {
1111  // Can't make a device of this type.
1112  continue;
1113  }
1114  if (hwaccel_device) {
1115  av_log(dp, AV_LOG_INFO, "Using auto "
1116  "hwaccel type %s with new device created "
1117  "from %s.\n", av_hwdevice_get_type_name(type),
1118  hwaccel_device);
1119  } else {
1120  av_log(dp, AV_LOG_INFO, "Using auto "
1121  "hwaccel type %s with new default device.\n",
1123  }
1124  }
1125  if (dev) {
1126  dp->hwaccel_device_type = type;
1127  } else {
1128  av_log(dp, AV_LOG_INFO, "Auto hwaccel "
1129  "disabled: no device found.\n");
1130  dp->hwaccel_id = HWACCEL_NONE;
1131  return 0;
1132  }
1133  }
1134 
1135  if (!dev) {
1136  av_log(dp, AV_LOG_ERROR, "No device available "
1137  "for decoder: device type %s needed for codec %s.\n",
1139  return err;
1140  }
1141 
1143  if (!dp->dec_ctx->hw_device_ctx)
1144  return AVERROR(ENOMEM);
1145 
1146  return 0;
1147 }
1148 
1149 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
1150  const DecoderOpts *o, AVFrame *param_out)
1151 {
1152  const AVCodec *codec = o->codec;
1153  int ret;
1154 
1155  dp->flags = o->flags;
1156  dp->log_parent = o->log_parent;
1157 
1158  dp->dec.type = codec->type;
1159  dp->framerate_in = o->framerate;
1160 
1161  dp->hwaccel_id = o->hwaccel_id;
1164 
1165  snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
1166 
1167  dp->parent_name = av_strdup(o->name ? o->name : "");
1168  if (!dp->parent_name)
1169  return AVERROR(ENOMEM);
1170 
1171  if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
1173  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
1174  dp->sub_prev[i] = av_frame_alloc();
1175  if (!dp->sub_prev[i])
1176  return AVERROR(ENOMEM);
1177  }
1178  dp->sub_heartbeat = av_frame_alloc();
1179  if (!dp->sub_heartbeat)
1180  return AVERROR(ENOMEM);
1181  }
1182 
1184 
1185  dp->dec_ctx = avcodec_alloc_context3(codec);
1186  if (!dp->dec_ctx)
1187  return AVERROR(ENOMEM);
1188 
1190  if (ret < 0) {
1191  av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1192  return ret;
1193  }
1194 
1195  dp->dec_ctx->opaque = dp;
1196  dp->dec_ctx->get_format = get_format;
1197  dp->dec_ctx->pkt_timebase = o->time_base;
1198 
1199  if (!av_dict_get(*dec_opts, "threads", NULL, 0))
1200  av_dict_set(dec_opts, "threads", "auto", 0);
1201 
1203  if (ret < 0) {
1204  av_log(dp, AV_LOG_ERROR,
1205  "Hardware device setup failed for decoder: %s\n",
1206  av_err2str(ret));
1207  return ret;
1208  }
1209 
1211  if (ret < 0) {
1212  av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
1213  av_err2str(ret));
1214  return ret;
1215  }
1216  ret = check_avoptions(*dec_opts);
1217  if (ret < 0)
1218  return ret;
1219 
1221  if (o->flags & DECODER_FLAG_BITEXACT)
1223 
1224  // we apply cropping outselves
1226  dp->dec_ctx->apply_cropping = 0;
1227 
1228  if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
1229  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
1230  av_err2str(ret));
1231  return ret;
1232  }
1233 
1234  if (dp->dec_ctx->hw_device_ctx) {
1235  // Update decoder extra_hw_frames option to account for the
1236  // frames held in queues inside the ffmpeg utility. This is
1237  // called after avcodec_open2() because the user-set value of
1238  // extra_hw_frames becomes valid in there, and we need to add
1239  // this on top of it.
1240  int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
1241  if (dp->dec_ctx->extra_hw_frames >= 0)
1242  dp->dec_ctx->extra_hw_frames += extra_frames;
1243  else
1244  dp->dec_ctx->extra_hw_frames = extra_frames;
1245  }
1246 
1249 
1250  if (param_out) {
1251  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1252  param_out->format = dp->dec_ctx->sample_fmt;
1253  param_out->sample_rate = dp->dec_ctx->sample_rate;
1254 
1255  ret = av_channel_layout_copy(&param_out->ch_layout, &dp->dec_ctx->ch_layout);
1256  if (ret < 0)
1257  return ret;
1258  } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1259  param_out->format = dp->dec_ctx->pix_fmt;
1260  param_out->width = dp->dec_ctx->width;
1261  param_out->height = dp->dec_ctx->height;
1263  param_out->colorspace = dp->dec_ctx->colorspace;
1264  param_out->color_range = dp->dec_ctx->color_range;
1265  }
1266 
1267  param_out->time_base = dp->dec_ctx->pkt_timebase;
1268  }
1269 
1270  return 0;
1271 }
1272 
1273 int dec_init(Decoder **pdec, Scheduler *sch,
1274  AVDictionary **dec_opts, const DecoderOpts *o,
1275  AVFrame *param_out)
1276 {
1277  DecoderPriv *dp;
1278  int ret;
1279 
1280  *pdec = NULL;
1281 
1282  ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
1283  if (ret < 0)
1284  return ret;
1285 
1286  ret = dec_open(dp, dec_opts, o, param_out);
1287  if (ret < 0)
1288  goto fail;
1289 
1290  *pdec = &dp->dec;
1291 
1292  return dp->sch_idx;
1293 fail:
1294  dec_free((Decoder**)&dp);
1295  return ret;
1296 }
1297 
1298 int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
1299 {
1300  DecoderPriv *dp;
1301 
1302  OutputFile *of;
1303  OutputStream *ost;
1304  int of_index, ost_index;
1305  char *p;
1306 
1307  unsigned enc_idx;
1308  int ret;
1309 
1310  ret = dec_alloc(&dp, sch, 0);
1311  if (ret < 0)
1312  return ret;
1313 
1314  dp->index = nb_decoders;
1315 
1317  if (ret < 0) {
1318  dec_free((Decoder **)&dp);
1319  return ret;
1320  }
1321 
1322  decoders[nb_decoders - 1] = (Decoder *)dp;
1323 
1324  of_index = strtol(arg, &p, 0);
1325  if (of_index < 0 || of_index >= nb_output_files) {
1326  av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg);
1327  return AVERROR(EINVAL);
1328  }
1329  of = output_files[of_index];
1330 
1331  ost_index = strtol(p + 1, NULL, 0);
1332  if (ost_index < 0 || ost_index >= of->nb_streams) {
1333  av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg);
1334  return AVERROR(EINVAL);
1335  }
1336  ost = of->streams[ost_index];
1337 
1338  if (!ost->enc) {
1339  av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg);
1340  return AVERROR(EINVAL);
1341  }
1342 
1343  dp->dec.type = ost->type;
1344 
1345  ret = enc_loopback(ost->enc);
1346  if (ret < 0)
1347  return ret;
1348  enc_idx = ret;
1349 
1350  ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC(dp->sch_idx));
1351  if (ret < 0)
1352  return ret;
1353 
1354  ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0);
1355  if (ret < 0)
1356  return ret;
1357 
1358  if (o->codec_names.nb_opt) {
1359  const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str;
1361  if (!dp->standalone_init.codec) {
1362  av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name);
1364  }
1365  }
1366 
1367  return 0;
1368 }
1369 
1371 {
1372  DecoderPriv *dp = dp_from_dec(d);
1373  char name[16];
1374 
1375  snprintf(name, sizeof(name), "dec%d", dp->index);
1376  opts->name = av_strdup(name);
1377  if (!opts->name)
1378  return AVERROR(ENOMEM);
1379 
1380  return dp->sch_idx;
1381 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:522
DecoderPriv::last_frame_tb
AVRational last_frame_tb
Definition: ffmpeg_dec.c:63
AVSubtitle
Definition: avcodec.h:2227
Decoder::subtitle_header
const uint8_t * subtitle_header
Definition: ffmpeg.h:385
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:427
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:649
AVCodec
AVCodec.
Definition: codec.h:187
copy_av_subtitle
static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
Definition: ffmpeg_dec.c:417
fix_sub_duration_heartbeat
static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
Definition: ffmpeg_dec.c:580
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:1370
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:630
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:358
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:353
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:829
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
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
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
AVSubtitleRect
Definition: avcodec.h:2200
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2231
hw_device_match_by_codec
static HWDevice * hw_device_match_by_codec(const AVCodec *codec)
Definition: ffmpeg_dec.c:1004
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:349
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:365
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:837
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:368
DecoderPriv::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:42
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1891
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2212
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:355
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:932
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:1062
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:637
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:621
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:371
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:560
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:389
fail
#define fail()
Definition: checkasm.h:179
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:970
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2201
DecoderPriv::log_parent
void * log_parent
Definition: ffmpeg_dec.c:76
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:362
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:496
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
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:134
OptionsContext
Definition: ffmpeg.h:123
FrameData::tb
AVRational tb
Definition: ffmpeg.h:640
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:390
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2224
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:393
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:932
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:1298
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:310
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:278
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:119
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:504
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:2202
InputFilter
Definition: ffmpeg.h:309
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:696
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:1574
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:2233
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:370
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:549
AVSubtitleRect::text
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:2217
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:507
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:2203
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:1020
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:1001
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:391
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:709
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1961
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:1149
AVCodec::type
enum AVMediaType type
Definition: codec.h:200
Decoder
Definition: ffmpeg.h:380
dec_thread_set_name
static void dec_thread_set_name(const DecoderPriv *dp)
Definition: ffmpeg_dec.c:814
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:602
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:1890
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2211
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:647
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:142
time.h
InputFilterOptions
Definition: ffmpeg.h:244
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:344
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:620
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:973
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:525
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:1520
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1273
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:121
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
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: ffmpeg.c:485
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:452
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2230
AVSubtitleRect::type
enum AVSubtitleType type
Definition: avcodec.h:2215
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:523
FrameData::pts
int64_t pts
Definition: ffmpeg.h:639
DecoderPriv::codec
const AVCodec * codec
Definition: ffmpeg_dec.c:82
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:118
video_frame_process
static int video_frame_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:352
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:2183
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
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:302
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:83
AVSubtitleRect::flags
int flags
Definition: avcodec.h:2214
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:677
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:517
process_subtitle
static int process_subtitle(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:537
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:645
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:2205
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:1923
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:660
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:373
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:633
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:606
tb
#define tb
Definition: regdef.h:68
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
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:1497
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:2030
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:2204
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:364
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:351
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:108
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:386
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:465
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:838
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:440
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
DecoderOpts::flags
int flags
Definition: ffmpeg.h:359
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:75
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:346
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:364
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:856
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:501
Decoder::class
const AVClass * class
Definition: ffmpeg.h:381
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:383
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:464
d
d
Definition: ffmpeg_filter.c:424
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_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:377
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:334
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:497
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3734
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:369
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:568
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:536
dec_standalone_open
static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt)
Definition: ffmpeg_dec.c:779
OutputFile
Definition: ffmpeg.h:613
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
DecoderOpts::name
char * name
Definition: ffmpeg.h:361