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/pixdesc.h"
25 #include "libavutil/pixfmt.h"
26 #include "libavutil/time.h"
27 #include "libavutil/timestamp.h"
28 
29 #include "libavcodec/avcodec.h"
30 #include "libavcodec/codec.h"
31 
32 #include "libavfilter/buffersrc.h"
33 
34 #include "ffmpeg.h"
35 #include "ffmpeg_utils.h"
36 #include "thread_queue.h"
37 
38 typedef struct DecoderPriv {
40 
42 
45 
46  // override output video sample aspect ratio with this value
48 
50 
51  // a combination of DECODER_FLAG_*, provided to dec_open()
52  int flags;
53 
58 
59  // pts/estimated duration of the last decoded frame
60  // * in decoder timebase for video,
61  // * in last_frame_tb (may change during decoding) for audio
62  int64_t last_frame_pts;
67 
68  /* previous decoded subtitles */
71 
73  unsigned sch_idx;
74 
75  // this decoder's index in decoders or -1
76  int index;
77  void *log_parent;
78  char log_name[32];
79  char *parent_name;
80 
81  struct {
83  const AVCodec *codec;
85 } DecoderPriv;
86 
88 {
89  return (DecoderPriv*)d;
90 }
91 
92 // data that is local to the decoder thread and not visible outside of it
93 typedef struct DecThreadContext {
97 
98 void dec_free(Decoder **pdec)
99 {
100  Decoder *dec = *pdec;
101  DecoderPriv *dp;
102 
103  if (!dec)
104  return;
105  dp = dp_from_dec(dec);
106 
108 
109  av_frame_free(&dp->frame);
110  av_packet_free(&dp->pkt);
111 
113 
114  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++)
115  av_frame_free(&dp->sub_prev[i]);
117 
118  av_freep(&dp->parent_name);
119 
120  av_freep(pdec);
121 }
122 
123 static const char *dec_item_name(void *obj)
124 {
125  const DecoderPriv *dp = obj;
126 
127  return dp->log_name;
128 }
129 
130 static const AVClass dec_class = {
131  .class_name = "Decoder",
132  .version = LIBAVUTIL_VERSION_INT,
133  .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
134  .item_name = dec_item_name,
135 };
136 
137 static int decoder_thread(void *arg);
138 
139 static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
140 {
141  DecoderPriv *dp;
142  int ret = 0;
143 
144  *pdec = NULL;
145 
146  dp = av_mallocz(sizeof(*dp));
147  if (!dp)
148  return AVERROR(ENOMEM);
149 
150  dp->frame = av_frame_alloc();
151  if (!dp->frame)
152  goto fail;
153 
154  dp->pkt = av_packet_alloc();
155  if (!dp->pkt)
156  goto fail;
157 
158  dp->index = -1;
159  dp->dec.class = &dec_class;
162  dp->last_frame_tb = (AVRational){ 1, 1 };
164 
165  ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts);
166  if (ret < 0)
167  goto fail;
168  dp->sch = sch;
169  dp->sch_idx = ret;
170 
171  *pdec = dp;
172 
173  return 0;
174 fail:
175  dec_free((Decoder**)&dp);
176  return ret >= 0 ? AVERROR(ENOMEM) : ret;
177 }
178 
180  const AVFrame *frame)
181 {
182  const int prev = dp->last_frame_tb.den;
183  const int sr = frame->sample_rate;
184 
185  AVRational tb_new;
186  int64_t gcd;
187 
189  goto finish;
190 
191  gcd = av_gcd(prev, sr);
192 
193  if (prev / gcd >= INT_MAX / sr) {
195  "Audio timestamps cannot be represented exactly after "
196  "sample rate change: %d -> %d\n", prev, sr);
197 
198  // LCM of 192000, 44100, allows to represent all common samplerates
199  tb_new = (AVRational){ 1, 28224000 };
200  } else
201  tb_new = (AVRational){ 1, prev / gcd * sr };
202 
203  // keep the frame timebase if it is strictly better than
204  // the samplerate-defined one
205  if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den &&
206  !(frame->time_base.den % tb_new.den))
207  tb_new = frame->time_base;
208 
211  dp->last_frame_tb, tb_new);
213  dp->last_frame_tb, tb_new);
214 
215  dp->last_frame_tb = tb_new;
217 
218 finish:
219  return dp->last_frame_tb;
220 }
221 
223 {
224  AVRational tb_filter = (AVRational){1, frame->sample_rate};
225  AVRational tb;
226  int64_t pts_pred;
227 
228  // on samplerate change, choose a new internal timebase for timestamp
229  // generation that can represent timestamps from all the samplerates
230  // seen so far
232  pts_pred = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
234 
235  if (frame->pts == AV_NOPTS_VALUE) {
236  frame->pts = pts_pred;
237  frame->time_base = tb;
238  } else if (dp->last_frame_pts != AV_NOPTS_VALUE &&
239  frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base,
240  AV_ROUND_UP)) {
241  // there was a gap in timestamps, reset conversion state
243  }
244 
246  tb, frame->nb_samples,
248 
249  dp->last_frame_pts = frame->pts;
251  tb_filter, tb);
252 
253  // finally convert to filtering timebase
254  frame->pts = av_rescale_q(frame->pts, tb, tb_filter);
256  frame->time_base = tb_filter;
257 }
258 
259 static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
260 {
261  const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
262  const int fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
263  int64_t codec_duration = 0;
264 
265  // XXX lavf currently makes up frame durations when they are not provided by
266  // the container. As there is no way to reliably distinguish real container
267  // durations from the fake made-up ones, we use heuristics based on whether
268  // the container has timestamps. Eventually lavf should stop making up
269  // durations, then this should be simplified.
270 
271  // prefer frame duration for containers with timestamps
272  if (frame->duration > 0 && (!ts_unreliable || fr_forced))
273  return frame->duration;
274 
275  if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
276  int fields = frame->repeat_pict + 2;
277  AVRational field_rate = av_mul_q(dp->dec_ctx->framerate,
278  (AVRational){ 2, 1 });
279  codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
280  frame->time_base);
281  }
282 
283  // prefer codec-layer duration for containers without timestamps
284  if (codec_duration > 0 && ts_unreliable)
285  return codec_duration;
286 
287  // when timestamps are available, repeat last frame's actual duration
288  // (i.e. pts difference between this and last frame)
290  frame->pts > dp->last_frame_pts)
291  return frame->pts - dp->last_frame_pts;
292 
293  // try frame/codec duration
294  if (frame->duration > 0)
295  return frame->duration;
296  if (codec_duration > 0)
297  return codec_duration;
298 
299  // try average framerate
300  if (dp->framerate_in.num && dp->framerate_in.den) {
301  int64_t d = av_rescale_q(1, av_inv_q(dp->framerate_in),
302  frame->time_base);
303  if (d > 0)
304  return d;
305  }
306 
307  // last resort is last frame's estimated duration, and 1
308  return FFMAX(dp->last_frame_duration_est, 1);
309 }
310 
312 {
313  DecoderPriv *dp = avctx->opaque;
314  AVFrame *output = NULL;
316  int err;
317 
318  if (input->format == output_format) {
319  // Nothing to do.
320  return 0;
321  }
322 
324  if (!output)
325  return AVERROR(ENOMEM);
326 
327  output->format = output_format;
328 
330  if (err < 0) {
331  av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
332  "output frame: %d.\n", err);
333  goto fail;
334  }
335 
337  if (err < 0) {
339  goto fail;
340  }
341 
345 
346  return 0;
347 
348 fail:
350  return err;
351 }
352 
354 {
355 #if FFMPEG_OPT_TOP
357  av_log(dp, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
359  }
360 #endif
361 
362  if (frame->format == dp->hwaccel_pix_fmt) {
363  int err = hwaccel_retrieve_data(dp->dec_ctx, frame);
364  if (err < 0)
365  return err;
366  }
367 
369 
370  // forced fixed framerate
373  frame->duration = 1;
375  }
376 
377  // no timestamp available - extrapolate from previous frame duration
378  if (frame->pts == AV_NOPTS_VALUE)
379  frame->pts = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
381 
382  // update timestamp history
384  dp->last_frame_pts = frame->pts;
386 
387  if (debug_ts) {
388  av_log(dp, AV_LOG_INFO,
389  "decoder -> pts:%s pts_time:%s "
390  "pkt_dts:%s pkt_dts_time:%s "
391  "duration:%s duration_time:%s "
392  "keyframe:%d frame_type:%d time_base:%d/%d\n",
393  av_ts2str(frame->pts),
401  }
402 
403  if (dp->sar_override.num)
405 
406  return 0;
407 }
408 
409 static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
410 {
411  int ret = AVERROR_BUG;
412  AVSubtitle tmp = {
413  .format = src->format,
414  .start_display_time = src->start_display_time,
415  .end_display_time = src->end_display_time,
416  .num_rects = 0,
417  .rects = NULL,
418  .pts = src->pts
419  };
420 
421  if (!src->num_rects)
422  goto success;
423 
424  if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects))))
425  return AVERROR(ENOMEM);
426 
427  for (int i = 0; i < src->num_rects; i++) {
428  AVSubtitleRect *src_rect = src->rects[i];
429  AVSubtitleRect *dst_rect;
430 
431  if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) {
432  ret = AVERROR(ENOMEM);
433  goto cleanup;
434  }
435 
436  tmp.num_rects++;
437 
438  dst_rect->type = src_rect->type;
439  dst_rect->flags = src_rect->flags;
440 
441  dst_rect->x = src_rect->x;
442  dst_rect->y = src_rect->y;
443  dst_rect->w = src_rect->w;
444  dst_rect->h = src_rect->h;
445  dst_rect->nb_colors = src_rect->nb_colors;
446 
447  if (src_rect->text)
448  if (!(dst_rect->text = av_strdup(src_rect->text))) {
449  ret = AVERROR(ENOMEM);
450  goto cleanup;
451  }
452 
453  if (src_rect->ass)
454  if (!(dst_rect->ass = av_strdup(src_rect->ass))) {
455  ret = AVERROR(ENOMEM);
456  goto cleanup;
457  }
458 
459  for (int j = 0; j < 4; j++) {
460  // SUBTITLE_BITMAP images are special in the sense that they
461  // are like PAL8 images. first pointer to data, second to
462  // palette. This makes the size calculation match this.
463  size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ?
465  src_rect->h * src_rect->linesize[j];
466 
467  if (!src_rect->data[j])
468  continue;
469 
470  if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) {
471  ret = AVERROR(ENOMEM);
472  goto cleanup;
473  }
474  dst_rect->linesize[j] = src_rect->linesize[j];
475  }
476  }
477 
478 success:
479  *dst = tmp;
480 
481  return 0;
482 
483 cleanup:
485 
486  return ret;
487 }
488 
489 static void subtitle_free(void *opaque, uint8_t *data)
490 {
491  AVSubtitle *sub = (AVSubtitle*)data;
492  avsubtitle_free(sub);
493  av_free(sub);
494 }
495 
496 static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
497 {
498  AVBufferRef *buf;
499  AVSubtitle *sub;
500  int ret;
501 
502  if (copy) {
503  sub = av_mallocz(sizeof(*sub));
504  ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
505  if (ret < 0) {
506  av_freep(&sub);
507  return ret;
508  }
509  } else {
510  sub = av_memdup(subtitle, sizeof(*subtitle));
511  if (!sub)
512  return AVERROR(ENOMEM);
513  memset(subtitle, 0, sizeof(*subtitle));
514  }
515 
516  buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
517  subtitle_free, NULL, 0);
518  if (!buf) {
519  avsubtitle_free(sub);
520  av_freep(&sub);
521  return AVERROR(ENOMEM);
522  }
523 
524  frame->buf[0] = buf;
525 
526  return 0;
527 }
528 
530 {
531  const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data;
532  int ret = 0;
533 
535  AVSubtitle *sub_prev = dp->sub_prev[0]->buf[0] ?
536  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
537  int end = 1;
538  if (sub_prev) {
539  end = av_rescale(subtitle->pts - sub_prev->pts,
540  1000, AV_TIME_BASE);
541  if (end < sub_prev->end_display_time) {
542  av_log(dp, AV_LOG_DEBUG,
543  "Subtitle duration reduced from %"PRId32" to %d%s\n",
544  sub_prev->end_display_time, end,
545  end <= 0 ? ", dropping it" : "");
546  sub_prev->end_display_time = end;
547  }
548  }
549 
550  av_frame_unref(dp->sub_prev[1]);
552 
553  frame = dp->sub_prev[0];
554  subtitle = frame->buf[0] ? (AVSubtitle*)frame->buf[0]->data : NULL;
555 
556  FFSWAP(AVFrame*, dp->sub_prev[0], dp->sub_prev[1]);
557 
558  if (end <= 0)
559  return 0;
560  }
561 
562  if (!subtitle)
563  return 0;
564 
565  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
566  if (ret < 0)
568 
569  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
570 }
571 
572 static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
573 {
574  int ret = AVERROR_BUG;
575  AVSubtitle *prev_subtitle = dp->sub_prev[0]->buf[0] ?
576  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
577  AVSubtitle *subtitle;
578 
579  if (!(dp->flags & DECODER_FLAG_FIX_SUB_DURATION) || !prev_subtitle ||
580  !prev_subtitle->num_rects || signal_pts <= prev_subtitle->pts)
581  return 0;
582 
584  ret = subtitle_wrap_frame(dp->sub_heartbeat, prev_subtitle, 1);
585  if (ret < 0)
586  return ret;
587 
588  subtitle = (AVSubtitle*)dp->sub_heartbeat->buf[0]->data;
589  subtitle->pts = signal_pts;
590 
591  return process_subtitle(dp, dp->sub_heartbeat);
592 }
593 
595  AVFrame *frame)
596 {
597  AVPacket *flush_pkt = NULL;
598  AVSubtitle subtitle;
599  int got_output;
600  int ret;
601 
602  if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) {
603  frame->pts = pkt->pts;
605  frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT;
606 
607  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
608  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
609  } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) {
611  AV_TIME_BASE_Q));
612  }
613 
614  if (!pkt) {
615  flush_pkt = av_packet_alloc();
616  if (!flush_pkt)
617  return AVERROR(ENOMEM);
618  }
619 
620  ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output,
621  pkt ? pkt : flush_pkt);
622  av_packet_free(&flush_pkt);
623 
624  if (ret < 0) {
625  av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
626  av_err2str(ret));
627  dp->dec.decode_errors++;
628  return exit_on_error ? ret : 0;
629  }
630 
631  if (!got_output)
632  return pkt ? 0 : AVERROR_EOF;
633 
634  dp->dec.frames_decoded++;
635 
636  // XXX the queue for transferring data to consumers runs
637  // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
638  // inside the frame
639  // eventually, subtitles should be switched to use AVFrames natively
640  ret = subtitle_wrap_frame(frame, &subtitle, 0);
641  if (ret < 0) {
642  avsubtitle_free(&subtitle);
643  return ret;
644  }
645 
646  frame->width = dp->dec_ctx->width;
647  frame->height = dp->dec_ctx->height;
648 
649  return process_subtitle(dp, frame);
650 }
651 
653 {
654  AVCodecContext *dec = dp->dec_ctx;
655  const char *type_desc = av_get_media_type_string(dec->codec_type);
656  int ret;
657 
658  if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
659  return transcode_subtitles(dp, pkt, frame);
660 
661  // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
662  // reason. This seems like a semi-critical bug. Don't trigger EOF, and
663  // skip the packet.
664  if (pkt && pkt->size == 0)
665  return 0;
666 
667  if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
670  }
671 
672  if (pkt) {
673  FrameData *fd = packet_data(pkt);
674  if (!fd)
675  return AVERROR(ENOMEM);
677  }
678 
679  ret = avcodec_send_packet(dec, pkt);
680  if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) {
681  // In particular, we don't expect AVERROR(EAGAIN), because we read all
682  // decoded frames with avcodec_receive_frame() until done.
683  if (ret == AVERROR(EAGAIN)) {
684  av_log(dp, AV_LOG_FATAL, "A decoder returned an unexpected error code. "
685  "This is a bug, please report it.\n");
686  return AVERROR_BUG;
687  }
688  av_log(dp, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n",
689  pkt ? "packet" : "EOF", av_err2str(ret));
690 
691  if (ret != AVERROR_EOF) {
692  dp->dec.decode_errors++;
693  if (!exit_on_error)
694  ret = 0;
695  }
696 
697  return ret;
698  }
699 
700  while (1) {
701  FrameData *fd;
702 
704 
707  update_benchmark("decode_%s %s", type_desc, dp->parent_name);
708 
709  if (ret == AVERROR(EAGAIN)) {
710  av_assert0(pkt); // should never happen during flushing
711  return 0;
712  } else if (ret == AVERROR_EOF) {
713  return ret;
714  } else if (ret < 0) {
715  av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
716  dp->dec.decode_errors++;
717 
718  if (exit_on_error)
719  return ret;
720 
721  continue;
722  }
723 
726  "corrupt decoded frame\n");
727  if (exit_on_error)
728  return AVERROR_INVALIDDATA;
729  }
730 
731  fd = frame_data(frame);
732  if (!fd) {
734  return AVERROR(ENOMEM);
735  }
736  fd->dec.pts = frame->pts;
737  fd->dec.tb = dec->pkt_timebase;
738  fd->dec.frame_num = dec->frame_num - 1;
740 
742 
743  frame->time_base = dec->pkt_timebase;
744 
745  if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
747 
748  audio_ts_process(dp, frame);
749  } else {
751  if (ret < 0) {
752  av_log(dp, AV_LOG_FATAL,
753  "Error while processing the decoded data\n");
754  return ret;
755  }
756  }
757 
758  dp->dec.frames_decoded++;
759 
760  ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
761  if (ret < 0) {
763  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
764  }
765  }
766 }
767 
768 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
769  const DecoderOpts *o, AVFrame *param_out);
770 
772 {
773  DecoderOpts o;
774  const FrameData *fd;
775  char name[16];
776 
777  if (!pkt->opaque_ref)
778  return AVERROR_BUG;
779  fd = (FrameData *)pkt->opaque_ref->data;
780 
781  if (!fd->par_enc)
782  return AVERROR_BUG;
783 
784  memset(&o, 0, sizeof(o));
785 
786  o.par = fd->par_enc;
787  o.time_base = pkt->time_base;
788 
789  o.codec = dp->standalone_init.codec;
790  if (!o.codec)
792  if (!o.codec) {
794 
795  av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n",
796  desc ? desc->name : "?");
798  }
799 
800  snprintf(name, sizeof(name), "dec%d", dp->index);
801  o.name = name;
802 
803  return dec_open(dp, &dp->standalone_init.opts, &o, NULL);
804 }
805 
806 static void dec_thread_set_name(const DecoderPriv *dp)
807 {
808  char name[16] = "dec";
809 
810  if (dp->index >= 0)
811  av_strlcatf(name, sizeof(name), "%d", dp->index);
812  else if (dp->parent_name)
813  av_strlcat(name, dp->parent_name, sizeof(name));
814 
815  if (dp->dec_ctx)
816  av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name);
817 
819 }
820 
822 {
823  av_packet_free(&dt->pkt);
824  av_frame_free(&dt->frame);
825 
826  memset(dt, 0, sizeof(*dt));
827 }
828 
830 {
831  memset(dt, 0, sizeof(*dt));
832 
833  dt->frame = av_frame_alloc();
834  if (!dt->frame)
835  goto fail;
836 
837  dt->pkt = av_packet_alloc();
838  if (!dt->pkt)
839  goto fail;
840 
841  return 0;
842 
843 fail:
844  dec_thread_uninit(dt);
845  return AVERROR(ENOMEM);
846 }
847 
848 static int decoder_thread(void *arg)
849 {
850  DecoderPriv *dp = arg;
851  DecThreadContext dt;
852  int ret = 0, input_status = 0;
853 
854  ret = dec_thread_init(&dt);
855  if (ret < 0)
856  goto finish;
857 
859 
860  while (!input_status) {
861  int flush_buffers, have_data;
862 
863  input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt);
864  have_data = input_status >= 0 &&
865  (dt.pkt->buf || dt.pkt->side_data_elems ||
866  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT ||
867  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION);
868  flush_buffers = input_status >= 0 && !have_data;
869  if (!have_data)
870  av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n",
871  flush_buffers ? "flush" : "EOF");
872 
873  // this is a standalone decoder that has not been initialized yet
874  if (!dp->dec_ctx) {
875  if (flush_buffers)
876  continue;
877  if (input_status < 0) {
878  av_log(dp, AV_LOG_ERROR,
879  "Cannot initialize a standalone decoder\n");
880  ret = input_status;
881  goto finish;
882  }
883 
884  ret = dec_standalone_open(dp, dt.pkt);
885  if (ret < 0)
886  goto finish;
887  }
888 
889  ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame);
890 
891  av_packet_unref(dt.pkt);
892  av_frame_unref(dt.frame);
893 
894  // AVERROR_EOF - EOF from the decoder
895  // AVERROR_EXIT - EOF from the scheduler
896  // we treat them differently when flushing
897  if (ret == AVERROR_EXIT) {
898  ret = AVERROR_EOF;
899  flush_buffers = 0;
900  }
901 
902  if (ret == AVERROR_EOF) {
903  av_log(dp, AV_LOG_VERBOSE, "Decoder returned EOF, %s\n",
904  flush_buffers ? "resetting" : "finishing");
905 
906  if (!flush_buffers)
907  break;
908 
909  /* report last frame duration to the scheduler */
910  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
912  dt.pkt->time_base = dp->last_frame_tb;
913  }
914 
916  } else if (ret < 0) {
917  av_log(dp, AV_LOG_ERROR, "Error processing packet in decoder: %s\n",
918  av_err2str(ret));
919  break;
920  }
921  }
922 
923  // EOF is normal thread termination
924  if (ret == AVERROR_EOF)
925  ret = 0;
926 
927  // on success send EOF timestamp to our downstreams
928  if (ret >= 0) {
929  float err_rate;
930 
931  av_frame_unref(dt.frame);
932 
933  dt.frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF;
936  dt.frame->time_base = dp->last_frame_tb;
937 
938  ret = sch_dec_send(dp->sch, dp->sch_idx, dt.frame);
939  if (ret < 0 && ret != AVERROR_EOF) {
940  av_log(dp, AV_LOG_FATAL,
941  "Error signalling EOF timestamp: %s\n", av_err2str(ret));
942  goto finish;
943  }
944  ret = 0;
945 
946  err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
947  dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
948  if (err_rate > max_error_rate) {
949  av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
950  err_rate, max_error_rate);
952  } else if (err_rate)
953  av_log(dp, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
954  }
955 
956 finish:
957  dec_thread_uninit(&dt);
958 
959  return ret;
960 }
961 
963 {
964  DecoderPriv *dp = s->opaque;
965  const enum AVPixelFormat *p;
966 
967  for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
969  const AVCodecHWConfig *config = NULL;
970 
971  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
972  break;
973 
974  if (dp->hwaccel_id == HWACCEL_GENERIC ||
975  dp->hwaccel_id == HWACCEL_AUTO) {
976  for (int i = 0;; i++) {
977  config = avcodec_get_hw_config(s->codec, i);
978  if (!config)
979  break;
980  if (!(config->methods &
982  continue;
983  if (config->pix_fmt == *p)
984  break;
985  }
986  }
987  if (config && config->device_type == dp->hwaccel_device_type) {
988  dp->hwaccel_pix_fmt = *p;
989  break;
990  }
991  }
992 
993  return *p;
994 }
995 
997 {
998  const AVCodecHWConfig *config;
999  HWDevice *dev;
1000  for (int i = 0;; i++) {
1001  config = avcodec_get_hw_config(codec, i);
1002  if (!config)
1003  return NULL;
1005  continue;
1006  dev = hw_device_get_by_type(config->device_type);
1007  if (dev)
1008  return dev;
1009  }
1010 }
1011 
1013  const AVCodec *codec,
1014  const char *hwaccel_device)
1015 {
1016  const AVCodecHWConfig *config;
1017  enum AVHWDeviceType type;
1018  HWDevice *dev = NULL;
1019  int err, auto_device = 0;
1020 
1021  if (hwaccel_device) {
1022  dev = hw_device_get_by_name(hwaccel_device);
1023  if (!dev) {
1024  if (dp->hwaccel_id == HWACCEL_AUTO) {
1025  auto_device = 1;
1026  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1027  type = dp->hwaccel_device_type;
1028  err = hw_device_init_from_type(type, hwaccel_device,
1029  &dev);
1030  } else {
1031  // This will be dealt with by API-specific initialisation
1032  // (using hwaccel_device), so nothing further needed here.
1033  return 0;
1034  }
1035  } else {
1036  if (dp->hwaccel_id == HWACCEL_AUTO) {
1037  dp->hwaccel_device_type = dev->type;
1038  } else if (dp->hwaccel_device_type != dev->type) {
1039  av_log(dp, AV_LOG_ERROR, "Invalid hwaccel device "
1040  "specified for decoder: device %s of type %s is not "
1041  "usable with hwaccel %s.\n", dev->name,
1044  return AVERROR(EINVAL);
1045  }
1046  }
1047  } else {
1048  if (dp->hwaccel_id == HWACCEL_AUTO) {
1049  auto_device = 1;
1050  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1051  type = dp->hwaccel_device_type;
1052  dev = hw_device_get_by_type(type);
1053 
1054  // When "-qsv_device device" is used, an internal QSV device named
1055  // as "__qsv_device" is created. Another QSV device is created too
1056  // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices
1057  // if both "-qsv_device device" and "-init_hw_device qsv=name:device"
1058  // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL.
1059  // To keep back-compatibility with the removed ad-hoc libmfx setup code,
1060  // call hw_device_get_by_name("__qsv_device") to select the internal QSV
1061  // device.
1062  if (!dev && type == AV_HWDEVICE_TYPE_QSV)
1063  dev = hw_device_get_by_name("__qsv_device");
1064 
1065  if (!dev)
1066  err = hw_device_init_from_type(type, NULL, &dev);
1067  } else {
1068  dev = hw_device_match_by_codec(codec);
1069  if (!dev) {
1070  // No device for this codec, but not using generic hwaccel
1071  // and therefore may well not need one - ignore.
1072  return 0;
1073  }
1074  }
1075  }
1076 
1077  if (auto_device) {
1078  if (!avcodec_get_hw_config(codec, 0)) {
1079  // Decoder does not support any hardware devices.
1080  return 0;
1081  }
1082  for (int i = 0; !dev; i++) {
1083  config = avcodec_get_hw_config(codec, i);
1084  if (!config)
1085  break;
1086  type = config->device_type;
1087  dev = hw_device_get_by_type(type);
1088  if (dev) {
1089  av_log(dp, AV_LOG_INFO, "Using auto "
1090  "hwaccel type %s with existing device %s.\n",
1092  }
1093  }
1094  for (int i = 0; !dev; i++) {
1095  config = avcodec_get_hw_config(codec, i);
1096  if (!config)
1097  break;
1098  type = config->device_type;
1099  // Try to make a new device of this type.
1100  err = hw_device_init_from_type(type, hwaccel_device,
1101  &dev);
1102  if (err < 0) {
1103  // Can't make a device of this type.
1104  continue;
1105  }
1106  if (hwaccel_device) {
1107  av_log(dp, AV_LOG_INFO, "Using auto "
1108  "hwaccel type %s with new device created "
1109  "from %s.\n", av_hwdevice_get_type_name(type),
1110  hwaccel_device);
1111  } else {
1112  av_log(dp, AV_LOG_INFO, "Using auto "
1113  "hwaccel type %s with new default device.\n",
1115  }
1116  }
1117  if (dev) {
1118  dp->hwaccel_device_type = type;
1119  } else {
1120  av_log(dp, AV_LOG_INFO, "Auto hwaccel "
1121  "disabled: no device found.\n");
1122  dp->hwaccel_id = HWACCEL_NONE;
1123  return 0;
1124  }
1125  }
1126 
1127  if (!dev) {
1128  av_log(dp, AV_LOG_ERROR, "No device available "
1129  "for decoder: device type %s needed for codec %s.\n",
1131  return err;
1132  }
1133 
1135  if (!dp->dec_ctx->hw_device_ctx)
1136  return AVERROR(ENOMEM);
1137 
1138  return 0;
1139 }
1140 
1141 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
1142  const DecoderOpts *o, AVFrame *param_out)
1143 {
1144  const AVCodec *codec = o->codec;
1145  int ret;
1146 
1147  dp->flags = o->flags;
1148  dp->log_parent = o->log_parent;
1149 
1150  dp->dec.type = codec->type;
1151  dp->framerate_in = o->framerate;
1152 
1153  dp->hwaccel_id = o->hwaccel_id;
1156 
1157  snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
1158 
1159  dp->parent_name = av_strdup(o->name ? o->name : "");
1160  if (!dp->parent_name)
1161  return AVERROR(ENOMEM);
1162 
1163  if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
1165  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
1166  dp->sub_prev[i] = av_frame_alloc();
1167  if (!dp->sub_prev[i])
1168  return AVERROR(ENOMEM);
1169  }
1170  dp->sub_heartbeat = av_frame_alloc();
1171  if (!dp->sub_heartbeat)
1172  return AVERROR(ENOMEM);
1173  }
1174 
1176 
1177  dp->dec_ctx = avcodec_alloc_context3(codec);
1178  if (!dp->dec_ctx)
1179  return AVERROR(ENOMEM);
1180 
1182  if (ret < 0) {
1183  av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1184  return ret;
1185  }
1186 
1187  dp->dec_ctx->opaque = dp;
1188  dp->dec_ctx->get_format = get_format;
1189  dp->dec_ctx->pkt_timebase = o->time_base;
1190 
1191  if (!av_dict_get(*dec_opts, "threads", NULL, 0))
1192  av_dict_set(dec_opts, "threads", "auto", 0);
1193 
1194  av_dict_set(dec_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
1195 
1197  if (ret < 0) {
1198  av_log(dp, AV_LOG_ERROR,
1199  "Hardware device setup failed for decoder: %s\n",
1200  av_err2str(ret));
1201  return ret;
1202  }
1203 
1204  if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) {
1205  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
1206  av_err2str(ret));
1207  return ret;
1208  }
1209 
1210  if (dp->dec_ctx->hw_device_ctx) {
1211  // Update decoder extra_hw_frames option to account for the
1212  // frames held in queues inside the ffmpeg utility. This is
1213  // called after avcodec_open2() because the user-set value of
1214  // extra_hw_frames becomes valid in there, and we need to add
1215  // this on top of it.
1216  int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
1217  if (dp->dec_ctx->extra_hw_frames >= 0)
1218  dp->dec_ctx->extra_hw_frames += extra_frames;
1219  else
1220  dp->dec_ctx->extra_hw_frames = extra_frames;
1221  }
1222 
1223  ret = check_avoptions(*dec_opts);
1224  if (ret < 0)
1225  return ret;
1226 
1229 
1230  if (param_out) {
1231  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1232  param_out->format = dp->dec_ctx->sample_fmt;
1233  param_out->sample_rate = dp->dec_ctx->sample_rate;
1234 
1235  ret = av_channel_layout_copy(&param_out->ch_layout, &dp->dec_ctx->ch_layout);
1236  if (ret < 0)
1237  return ret;
1238  } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1239  param_out->format = dp->dec_ctx->pix_fmt;
1240  param_out->width = dp->dec_ctx->width;
1241  param_out->height = dp->dec_ctx->height;
1243  param_out->colorspace = dp->dec_ctx->colorspace;
1244  param_out->color_range = dp->dec_ctx->color_range;
1245  }
1246 
1247  param_out->time_base = dp->dec_ctx->pkt_timebase;
1248  }
1249 
1250  return 0;
1251 }
1252 
1253 int dec_init(Decoder **pdec, Scheduler *sch,
1254  AVDictionary **dec_opts, const DecoderOpts *o,
1255  AVFrame *param_out)
1256 {
1257  DecoderPriv *dp;
1258  int ret;
1259 
1260  *pdec = NULL;
1261 
1262  ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
1263  if (ret < 0)
1264  return ret;
1265 
1266  ret = dec_open(dp, dec_opts, o, param_out);
1267  if (ret < 0)
1268  goto fail;
1269 
1270  *pdec = &dp->dec;
1271 
1272  return dp->sch_idx;
1273 fail:
1274  dec_free((Decoder**)&dp);
1275  return ret;
1276 }
1277 
1278 int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
1279 {
1280  DecoderPriv *dp;
1281 
1282  OutputFile *of;
1283  OutputStream *ost;
1284  int of_index, ost_index;
1285  char *p;
1286 
1287  unsigned enc_idx;
1288  int ret;
1289 
1290  ret = dec_alloc(&dp, sch, 0);
1291  if (ret < 0)
1292  return ret;
1293 
1294  dp->index = nb_decoders;
1295 
1297  if (ret < 0) {
1298  dec_free((Decoder **)&dp);
1299  return ret;
1300  }
1301 
1302  decoders[nb_decoders - 1] = (Decoder *)dp;
1303 
1304  of_index = strtol(arg, &p, 0);
1305  if (of_index < 0 || of_index >= nb_output_files) {
1306  av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg);
1307  return AVERROR(EINVAL);
1308  }
1309  of = output_files[of_index];
1310 
1311  ost_index = strtol(p + 1, NULL, 0);
1312  if (ost_index < 0 || ost_index >= of->nb_streams) {
1313  av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg);
1314  return AVERROR(EINVAL);
1315  }
1316  ost = of->streams[ost_index];
1317 
1318  if (!ost->enc) {
1319  av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg);
1320  return AVERROR(EINVAL);
1321  }
1322 
1323  dp->dec.type = ost->type;
1324 
1325  ret = enc_loopback(ost->enc);
1326  if (ret < 0)
1327  return ret;
1328  enc_idx = ret;
1329 
1330  ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC(dp->sch_idx));
1331  if (ret < 0)
1332  return ret;
1333 
1334  ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0);
1335  if (ret < 0)
1336  return ret;
1337 
1338  if (o->codec_names.nb_opt) {
1339  const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str;
1341  if (!dp->standalone_init.codec) {
1342  av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name);
1344  }
1345  }
1346 
1347  return 0;
1348 }
1349 
1351 {
1352  DecoderPriv *dp = dp_from_dec(d);
1353  char name[16];
1354 
1355  snprintf(name, sizeof(name), "dec%d", dp->index);
1356  opts->name = av_strdup(name);
1357  if (!opts->name)
1358  return AVERROR(ENOMEM);
1359 
1360  return dp->sch_idx;
1361 }
DecoderPriv::last_frame_tb
AVRational last_frame_tb
Definition: ffmpeg_dec.c:64
AVSubtitle
Definition: avcodec.h:2227
Decoder::subtitle_header
const uint8_t * subtitle_header
Definition: ffmpeg.h:336
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:612
AVCodec
AVCodec.
Definition: codec.h:187
copy_av_subtitle
static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
Definition: ffmpeg_dec.c:409
fix_sub_duration_heartbeat
static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
Definition: ffmpeg_dec.c:572
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:623
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:1350
dec_class
static const AVClass dec_class
Definition: ffmpeg_dec.c:130
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
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:593
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:63
DecoderOpts
Definition: ffmpeg.h:309
audio_samplerate_update
static AVRational audio_samplerate_update(DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:179
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:306
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:750
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
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:62
dec_thread_uninit
static void dec_thread_uninit(DecThreadContext *dt)
Definition: ffmpeg_dec.c:821
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:139
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: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:996
DecThreadContext::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:95
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:130
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:492
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:634
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
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:456
AVFrame::width
int width
Definition: frame.h:416
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:302
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:316
dec_item_name
static const char * dec_item_name(void *obj)
Definition: ffmpeg_dec.c:123
dec_thread_init
static int dec_thread_init(DecThreadContext *dt)
Definition: ffmpeg_dec.c:829
DecoderPriv::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg_dec.c:56
DecoderPriv::sub_prev
AVFrame * sub_prev[2]
Definition: ffmpeg_dec.c:69
DecoderPriv::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg_dec.c:57
data
const char data[16]
Definition: mxf.c:148
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:319
DecoderPriv::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:44
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:76
DecoderPriv::sub_heartbeat
AVFrame * sub_heartbeat
Definition: ffmpeg_dec.c:70
AVDictionary
Definition: dict.c:34
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
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
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:557
DecoderPriv::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg_dec.c:55
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:962
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:98
DEFAULT_FRAME_THREAD_QUEUE_SIZE
#define DEFAULT_FRAME_THREAD_QUEUE_SIZE
Default size of a frame thread queue.
Definition: ffmpeg_sched.h:246
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:608
FrameData::frame_num
uint64_t frame_num
Definition: ffmpeg.h:600
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:583
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
DecoderPriv::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg_dec.c:41
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:322
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:76
finish
static void finish(void)
Definition: movenc.c:342
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:558
DecoderPriv
Definition: ffmpeg_dec.c:38
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:340
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:2160
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:962
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:77
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:313
DecoderPriv::dec
Decoder dec
Definition: ffmpeg_dec.c:39
update_benchmark
void update_benchmark(const char *fmt,...)
Definition: ffmpeg.c:517
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:745
SCH_ENC
#define SCH_ENC(encoder)
Definition: ffmpeg_sched.h:116
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:603
codec.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
DecoderPriv::parent_name
char * parent_name
Definition: ffmpeg_dec.c:79
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:341
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:379
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
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:118
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:929
avassert.h
DecThreadContext
Definition: ffmpeg_dec.c:93
DecoderPriv::log_name
char log_name[32]
Definition: ffmpeg_dec.c:78
pkt
AVPacket * pkt
Definition: movenc.c:59
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:1278
DecoderPriv::frame
AVFrame * frame
Definition: ffmpeg_dec.c:43
hwaccel_retrieve_data
static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
Definition: ffmpeg_dec.c:311
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:595
DecThreadContext::frame
AVFrame * frame
Definition: ffmpeg_dec.c:94
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:496
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:266
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:681
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:81
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:321
ffmpeg_utils.h
DecoderPriv::last_filter_in_rescale_delta
int64_t last_filter_in_rescale_delta
Definition: ffmpeg_dec.c:65
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:547
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
frame
static AVFrame * frame
Definition: demux_decode.c:54
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:50
audio_ts_process
static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:222
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:505
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:1012
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:999
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:342
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:679
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
AV_DICT_MULTIKEY
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition: dict.h:84
DecoderPriv::framerate_in
AVRational framerate_in
Definition: ffmpeg_dec.c:49
dec_open
static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1141
AVCodec::type
enum AVMediaType type
Definition: codec.h:200
Decoder
Definition: ffmpeg.h:331
dec_thread_set_name
static void dec_thread_set_name(const DecoderPriv *dp)
Definition: ffmpeg_dec.c:806
hw_device_init_from_type
int hw_device_init_from_type(enum AVHWDeviceType type, const char *device, HWDevice **dev_out)
Definition: ffmpeg_hw.c:245
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:594
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:610
AVFrame::pkt_dts
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:463
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:128
time.h
InputFilterOptions
Definition: ffmpeg.h:244
DecoderPriv::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg_dec.c:54
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:297
DecoderPriv::last_frame_sample_rate
int last_frame_sample_rate
Definition: ffmpeg_dec.c:66
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:582
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:971
AVFrame::best_effort_timestamp
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base
Definition: frame.h:643
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
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:523
DecoderPriv::sch
Scheduler * sch
Definition: ffmpeg_dec.c:72
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:185
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:1253
output_files
OutputFile ** output_files
Definition: ffmpeg.c:128
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:543
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:506
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:471
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:30
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:431
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:473
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:521
FrameData::pts
int64_t pts
Definition: ffmpeg.h:602
DecoderPriv::codec
const AVCodec * codec
Definition: ffmpeg_dec.c:83
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:118
video_frame_process
static int video_frame_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:353
SCH_DEC
#define SCH_DEC(decoder)
Definition: ffmpeg_sched.h:113
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.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:134
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:135
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
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:674
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:424
video_duration_estimate
static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:259
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
process_subtitle
static int process_subtitle(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:529
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:608
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:591
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_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:652
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:324
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:77
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:603
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:576
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:254
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:262
nb_output_files
int nb_output_files
Definition: ffmpeg.c:129
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
AVFrame::decode_error_flags
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
Definition: frame.h:671
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:2084
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:350
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
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:52
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:304
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:451
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:47
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:416
DecoderPriv::opts
AVDictionary * opts
Definition: ffmpeg_dec.c:82
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:87
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:149
Decoder::subtitle_header_size
int subtitle_header_size
Definition: ffmpeg.h:337
thread_queue.h
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:439
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
DecoderOpts::flags
int flags
Definition: ffmpeg.h:310
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:270
desc
const char * desc
Definition: libsvtav1.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
SpecifierOpt::u
union SpecifierOpt::@0 u
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:299
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:315
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:848
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:499
Decoder::class
const AVClass * class
Definition: ffmpeg.h:332
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:334
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:485
d
d
Definition: ffmpeg_filter.c:409
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:328
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:489
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3727
DecoderPriv::sch_idx
unsigned sch_idx
Definition: ffmpeg_dec.c:73
avstring.h
hw_device_get_by_name
HWDevice * hw_device_get_by_name(const char *name)
Definition: ffmpeg_hw.c:44
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
buffersrc.h
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:320
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
AVFrame::repeat_pict
int repeat_pict
Number of fields in this frame which should be repeated, i.e.
Definition: frame.h:512
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:566
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:534
dec_standalone_open
static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt)
Definition: ffmpeg_dec.c:771
OutputFile
Definition: ffmpeg.h:574
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
DecoderOpts::name
char * name
Definition: ffmpeg.h:312