MythTV  master
mythavutil.cpp
Go to the documentation of this file.
1 //
2 // mythavutil.cpp
3 // MythTV
4 //
5 // Created by Jean-Yves Avenard on 28/06/2014.
6 // Copyright (c) 2014 Bubblestuff Pty Ltd. All rights reserved.
7 //
8 
9 #include "mythframe.h"
10 #include "mythavutil.h"
11 #include "mythcorecontext.h"
12 #include "mythconfig.h"
13 extern "C" {
14 #include "libswscale/swscale.h"
15 #include "libavfilter/avfilter.h"
16 #include "libavcodec/avcodec.h"
17 #include "libavfilter/buffersrc.h"
18 #include "libavfilter/buffersink.h"
19 #include "libavutil/imgutils.h"
20 #include "libavformat/avformat.h"
21 }
22 #include <QMutexLocker>
23 #include <QFile>
24 
26 {
27  switch (type)
28  {
29  case FMT_YV12: return AV_PIX_FMT_YUV420P;
30  case FMT_YUV420P9: return AV_PIX_FMT_YUV420P9;
31  case FMT_YUV420P10: return AV_PIX_FMT_YUV420P10;
32  case FMT_YUV420P12: return AV_PIX_FMT_YUV420P12;
33  case FMT_YUV420P14: return AV_PIX_FMT_YUV420P14;
34  case FMT_YUV420P16: return AV_PIX_FMT_YUV420P16;
35  case FMT_NV12: return AV_PIX_FMT_NV12;
36  case FMT_P010: return AV_PIX_FMT_P010;
37  case FMT_P016: return AV_PIX_FMT_P016;
38  case FMT_YUV422P: return AV_PIX_FMT_YUV422P;
39  case FMT_YUV422P9: return AV_PIX_FMT_YUV422P9;
40  case FMT_YUV422P10: return AV_PIX_FMT_YUV422P10;
41  case FMT_YUV422P12: return AV_PIX_FMT_YUV422P12;
42  case FMT_YUV422P14: return AV_PIX_FMT_YUV422P14;
43  case FMT_YUV422P16: return AV_PIX_FMT_YUV422P16;
44  case FMT_YUV444P: return AV_PIX_FMT_YUV444P;
45  case FMT_YUV444P9: return AV_PIX_FMT_YUV444P9;
46  case FMT_YUV444P10: return AV_PIX_FMT_YUV444P10;
47  case FMT_YUV444P12: return AV_PIX_FMT_YUV444P12;
48  case FMT_YUV444P14: return AV_PIX_FMT_YUV444P14;
49  case FMT_YUV444P16: return AV_PIX_FMT_YUV444P16;
50  case FMT_RGB24: return AV_PIX_FMT_RGB24;
51  case FMT_BGRA: return AV_PIX_FMT_BGRA; // NOLINT(bugprone-branch-clone)
52  case FMT_RGB32: return AV_PIX_FMT_RGB32;
53  case FMT_ARGB32: return AV_PIX_FMT_ARGB;
54  case FMT_RGBA32: return AV_PIX_FMT_RGBA;
55  case FMT_YUY2: return AV_PIX_FMT_UYVY422;
56  case FMT_VDPAU: return AV_PIX_FMT_VDPAU;
57  case FMT_VTB: return AV_PIX_FMT_VIDEOTOOLBOX;
58  case FMT_VAAPI: return AV_PIX_FMT_VAAPI;
59  case FMT_MEDIACODEC: return AV_PIX_FMT_MEDIACODEC;
60  case FMT_NVDEC: return AV_PIX_FMT_CUDA;
61  case FMT_DXVA2: return AV_PIX_FMT_DXVA2_VLD;
62  case FMT_MMAL: return AV_PIX_FMT_MMAL;
63  case FMT_DRMPRIME: return AV_PIX_FMT_DRM_PRIME;
64  case FMT_NONE: break;
65  }
66  return AV_PIX_FMT_NONE;
67 }
68 
70 {
71  switch (fmt)
72  {
73  case AV_PIX_FMT_YUVJ420P:
74  case AV_PIX_FMT_YUV420P: return FMT_YV12;
75  case AV_PIX_FMT_YUV420P9: return FMT_YUV420P9;
76  case AV_PIX_FMT_YUV420P10: return FMT_YUV420P10;
77  case AV_PIX_FMT_YUV420P12: return FMT_YUV420P12;
78  case AV_PIX_FMT_YUV420P14: return FMT_YUV420P14;
79  case AV_PIX_FMT_YUV420P16: return FMT_YUV420P16;
80  case AV_PIX_FMT_NV12: return FMT_NV12;
81  case AV_PIX_FMT_P010: return FMT_P010;
82  case AV_PIX_FMT_P016: return FMT_P016;
83  case AV_PIX_FMT_YUVJ422P:
84  case AV_PIX_FMT_YUV422P: return FMT_YUV422P;
85  case AV_PIX_FMT_YUV422P9: return FMT_YUV422P9;
86  case AV_PIX_FMT_YUV422P10: return FMT_YUV422P10;
87  case AV_PIX_FMT_YUV422P12: return FMT_YUV422P12;
88  case AV_PIX_FMT_YUV422P14: return FMT_YUV422P14;
89  case AV_PIX_FMT_YUV422P16: return FMT_YUV422P16;
90  case AV_PIX_FMT_YUVJ444P:
91  case AV_PIX_FMT_YUV444P: return FMT_YUV444P;
92  case AV_PIX_FMT_YUV444P9: return FMT_YUV444P9;
93  case AV_PIX_FMT_YUV444P10: return FMT_YUV444P10;
94  case AV_PIX_FMT_YUV444P12: return FMT_YUV444P12;
95  case AV_PIX_FMT_YUV444P14: return FMT_YUV444P14;
96  case AV_PIX_FMT_YUV444P16: return FMT_YUV444P16;
97  case AV_PIX_FMT_UYVY422: return FMT_YUY2;
98  case AV_PIX_FMT_RGB24: return FMT_RGB24;
99  case AV_PIX_FMT_ARGB: return FMT_ARGB32;
100  case AV_PIX_FMT_RGBA: return FMT_RGBA32;
101  case AV_PIX_FMT_BGRA: return FMT_BGRA;
102  case AV_PIX_FMT_CUDA: return FMT_NVDEC;
103  case AV_PIX_FMT_MMAL: return FMT_MMAL;
104  case AV_PIX_FMT_VDPAU: return FMT_VDPAU;
105  case AV_PIX_FMT_VIDEOTOOLBOX: return FMT_VTB;
106  case AV_PIX_FMT_VAAPI: return FMT_VAAPI;
107  case AV_PIX_FMT_DXVA2_VLD: return FMT_DXVA2;
108  case AV_PIX_FMT_MEDIACODEC: return FMT_MEDIACODEC;
109  case AV_PIX_FMT_DRM_PRIME: return FMT_DRMPRIME;
110  default: break;
111  }
112  return FMT_NONE;
113 }
114 
115 QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format)
116 {
117  MythDeintType deint = GetDeinterlacer(Deint);
118  QString result = DoubleRate ? "2x " : "";
119  if (Deint & DEINT_CPU)
120  {
121  result += "CPU ";
122  switch (deint)
123  {
124  case DEINT_HIGH: return result + "Yadif";
125  case DEINT_MEDIUM: return result + "Linearblend";
126  case DEINT_BASIC: return result + "Onefield";
127  default: break;
128  }
129  }
130  else if (Deint & DEINT_SHADER)
131  {
132  result += "GLSL ";
133  switch (deint)
134  {
135  case DEINT_HIGH: return result + "Kernel";
136  case DEINT_MEDIUM: return result + "Linearblend";
137  case DEINT_BASIC: return result + "Onefield";
138  default: break;
139  }
140  }
141  else if (Deint & DEINT_DRIVER)
142  {
143  switch (Format)
144  {
145  case FMT_MEDIACODEC: return "MediaCodec";
146  case FMT_DRMPRIME: return result + "EGL Onefield";
147  case FMT_VDPAU:
148  result += "VDPAU ";
149  switch (deint)
150  {
151  case DEINT_HIGH: return result + "Advanced";
152  case DEINT_MEDIUM: return result + "Temporal";
153  case DEINT_BASIC: return result + "Basic";
154  default: break;
155  }
156  break;
157  case FMT_NVDEC:
158  result += "NVDec ";
159  switch (deint)
160  {
161  case DEINT_HIGH:
162  case DEINT_MEDIUM: return result + "Adaptive";
163  case DEINT_BASIC: return result + "Basic";
164  default: break;
165  }
166  break;
167  case FMT_VAAPI:
168  result += "VAAPI ";
169  switch (deint)
170  {
171  case DEINT_HIGH: return result + "Compensated";
172  case DEINT_MEDIUM: return result + "Adaptive";
173  case DEINT_BASIC: return result + "Basic";
174  default: break;
175  }
176  break;
177  default: break;
178  }
179  }
180  return "None";
181 }
182 
184 {
185  if (DEINT_NONE == Deint)
186  return QString("None");
187  QString result;
188  if (Deint & DEINT_BASIC) result = "Basic";
189  else if (Deint & DEINT_MEDIUM) result = "Medium";
190  else if (Deint & DEINT_HIGH) result = "High";
191  if (Deint & DEINT_CPU) result += "|CPU";
192  if (Deint & DEINT_SHADER) result += "|GLSL";
193  if (Deint & DEINT_DRIVER) result += "|DRIVER";
194  return result;
195 }
196 
197 int AVPictureFill(AVFrame *pic, const VideoFrame *frame, AVPixelFormat fmt)
198 {
199  if (fmt == AV_PIX_FMT_NONE)
200  {
201  fmt = FrameTypeToPixelFormat(frame->codec);
202  }
203 
204  av_image_fill_arrays(pic->data, pic->linesize, frame->buf,
205  fmt, frame->width, frame->height, IMAGE_ALIGN);
206  pic->data[1] = frame->buf + frame->offsets[1];
207  pic->data[2] = frame->buf + frame->offsets[2];
208  pic->linesize[0] = frame->pitches[0];
209  pic->linesize[1] = frame->pitches[1];
210  pic->linesize[2] = frame->pitches[2];
211  return static_cast<int>(GetBufferSize(frame->codec, frame->width, frame->height));
212 }
213 
215 {
216 public:
217  explicit MythAVCopyPrivate(bool uswc)
218  : m_copyctx(new MythUSWCCopy(4096, !uswc)) {}
219 
221  {
222  if (m_swsctx)
223  {
224  sws_freeContext(m_swsctx);
225  }
226  delete m_copyctx;
227  }
228 
229  MythAVCopyPrivate(const MythAVCopyPrivate &) = delete; // not copyable
230  MythAVCopyPrivate &operator=(const MythAVCopyPrivate &) = delete; // not copyable
231 
232  int SizeData(int _width, int _height, AVPixelFormat _fmt)
233  {
234  if (_width == m_width && _height == m_height && _fmt == m_format)
235  {
236  return m_size;
237  }
238  m_size = av_image_get_buffer_size(_fmt, _width, _height, IMAGE_ALIGN);
239  m_width = _width;
240  m_height = _height;
241  m_format = _fmt;
242  return m_size;
243  }
244 
245  SwsContext *m_swsctx {nullptr};
247  int m_width {0};
248  int m_height {0};
249  int m_size {0};
250  AVPixelFormat m_format {AV_PIX_FMT_NONE};
251 };
252 
254 {
255 }
256 
258 {
259  delete d;
260 }
261 
262 void MythAVCopy::FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch,
263  int width, int height, AVPixelFormat pix_fmt)
264 {
265  int size = av_image_get_buffer_size(pix_fmt, width, height, IMAGE_ALIGN);
266 
267  if (pix_fmt == AV_PIX_FMT_YUV420P)
268  {
269  int chroma_pitch = pitch >> 1;
270  int chroma_height = height >> 1;
271  int offsets[3] =
272  { 0,
273  pitch * height,
274  pitch * height + chroma_pitch * chroma_height };
275  int pitches[3] = { pitch, chroma_pitch, chroma_pitch };
276 
277  init(frame, FMT_YV12, pic->data[0], width, height, size, pitches, offsets);
278  }
279  else if (pix_fmt == AV_PIX_FMT_NV12)
280  {
281  int offsets[3] = { 0, pitch * height, 0 };
282  int pitches[3] = { pitch, pitch, 0 };
283 
284  init(frame, FMT_NV12, pic->data[0], width, height, size, pitches, offsets);
285  }
286 }
287 
288 int MythAVCopy::Copy(AVFrame *dst, AVPixelFormat dst_pix_fmt,
289  const AVFrame *src, AVPixelFormat pix_fmt,
290  int width, int height)
291 {
292  if ((pix_fmt == AV_PIX_FMT_YUV420P || pix_fmt == AV_PIX_FMT_NV12) &&
293  (dst_pix_fmt == AV_PIX_FMT_YUV420P))
294  {
295  VideoFrame framein {};
296  VideoFrame frameout {};
297 
298  FillFrame(&framein, src, width, width, height, pix_fmt);
299  FillFrame(&frameout, dst, width, width, height, dst_pix_fmt);
300 
301  d->m_copyctx->copy(&frameout, &framein);
302  return frameout.size;
303  }
304 
305  int new_width = width;
306 #if ARCH_ARM
307  // The ARM build of FFMPEG has a bug that if sws_scale is
308  // called with source and dest sizes the same, and
309  // formats as shown below, it causes a bus error and the
310  // application core dumps. To avoid this I make a -1
311  // difference in the new width, causing it to bypass
312  // the code optimization which is failing.
313  if (pix_fmt == AV_PIX_FMT_YUV420P
314  && dst_pix_fmt == AV_PIX_FMT_BGRA)
315  new_width = width - 1;
316 #endif
317  d->m_swsctx = sws_getCachedContext(d->m_swsctx, width, height, pix_fmt,
318  new_width, height, dst_pix_fmt,
319  SWS_FAST_BILINEAR, nullptr, nullptr, nullptr);
320  if (d->m_swsctx == nullptr)
321  {
322  return -1;
323  }
324 
325  sws_scale(d->m_swsctx, src->data, src->linesize,
326  0, height, dst->data, dst->linesize);
327 
328  return d->SizeData(width, height, dst_pix_fmt);
329 }
330 
332 {
333  if ((src->codec == FMT_YV12 || src->codec == FMT_NV12) &&
334  (dst->codec == FMT_YV12))
335  {
336  d->m_copyctx->copy(dst, src);
337  return dst->size;
338  }
339 
340  AVFrame srcpic;
341  AVFrame dstpic;
342 
343  AVPictureFill(&srcpic, src);
344  AVPictureFill(&dstpic, dst);
345 
346  return Copy(&dstpic, FrameTypeToPixelFormat(dst->codec),
347  &srcpic, FrameTypeToPixelFormat(src->codec),
348  src->width, src->height);
349 }
350 
351 int MythAVCopy::Copy(AVFrame *pic, const VideoFrame *frame,
352  unsigned char *buffer, AVPixelFormat fmt)
353 {
355  unsigned char *sbuf = buffer ? buffer : CreateBuffer(type, frame->width, frame->height);
356 
357  if (!sbuf)
358  {
359  return 0;
360  }
361 
362  AVFrame pic_in;
363  AVPixelFormat fmt_in = FrameTypeToPixelFormat(frame->codec);
364 
365  AVPictureFill(&pic_in, frame, fmt_in);
366  av_image_fill_arrays(pic->data, pic->linesize, sbuf, fmt, frame->width, frame->height, IMAGE_ALIGN);
367  return Copy(pic, fmt, &pic_in, fmt_in, frame->width, frame->height);
368 }
369 
370 int MythAVCopy::Copy(VideoFrame *frame, const AVFrame *pic, AVPixelFormat fmt)
371 {
372  if (fmt == AV_PIX_FMT_NV12 || fmt == AV_PIX_FMT_YUV420P)
373  {
374  VideoFrame framein {};
375  FillFrame(&framein, pic, frame->width, frame->width, frame->height, fmt);
376  return Copy(frame, &framein);
377  }
378 
379  AVFrame frame_out;
380  AVPixelFormat fmt_out = FrameTypeToPixelFormat(frame->codec);
381 
382  AVPictureFill(&frame_out, frame, fmt_out);
383  return Copy(&frame_out, fmt_out, pic, fmt, frame->width, frame->height);
384 }
385 
387  int width, int height, float ar)
388  : m_pixfmt(pixfmt)
389  , m_width(width)
390  , m_height(height)
391  , m_ar(ar)
392 {
393  if (Flush() < 0)
394  {
395  m_errored = true;
396  }
397 }
398 
400 {
401  if (m_errored)
402  {
403  return -1;
404  }
405  if (src)
406  {
407  memcpy(m_filterFrame->data, src->data, sizeof(src->data));
408  memcpy(m_filterFrame->linesize, src->linesize, sizeof(src->linesize));
409  m_filterFrame->width = m_width;
410  m_filterFrame->height = m_height;
411  m_filterFrame->format = m_pixfmt;
412  }
413  int res = av_buffersrc_add_frame(m_bufferSrcCtx, m_filterFrame);
414  if (res < 0)
415  {
416  return res;
417  }
418  res = av_buffersink_get_frame(m_bufferSinkCtx, m_filterFrame);
419  if (res < 0)
420  {
421  return res;
422  }
423 
424  av_image_copy(dst->data, dst->linesize,
425  (const uint8_t **)((AVFrame*)m_filterFrame)->data,
426  (const int*)((AVFrame*)m_filterFrame)->linesize,
428 
429  av_frame_unref(m_filterFrame);
430 
431  return 0;
432 }
433 
435 {
436  if (m_errored)
437  {
438  return -1;
439  }
440  if (!m_filterGraph && Flush() < 0)
441  {
442  return -1;
443  }
444  int res = Deinterlace(dst, src);
445  if (res == AVERROR(EAGAIN))
446  {
447  res = Deinterlace(dst, nullptr);
448  // We have drained the filter, we need to recreate it on the next run.
449  avfilter_graph_free(&m_filterGraph);
450  }
451  return res;
452 }
453 
455 {
456  if (m_filterGraph)
457  {
458  avfilter_graph_free(&m_filterGraph);
459  }
460 
461  m_filterGraph = avfilter_graph_alloc();
462  if (!m_filterGraph)
463  {
464  return -1;
465  }
466 
467  AVFilterInOut *inputs = nullptr;
468  AVFilterInOut *outputs = nullptr;
469  AVRational ar = av_d2q(m_ar, 100000);
470  QString args = QString("buffer=video_size=%1x%2:pix_fmt=%3:time_base=1/1:pixel_aspect=%4/%5[in];"
471  "[in]yadif[out];[out] buffersink")
472  .arg(m_width).arg(m_height).arg(m_pixfmt).arg(ar.num).arg(ar.den);
473  int res = avfilter_graph_parse2(m_filterGraph, args.toLatin1().data(), &inputs, &outputs);
474  while (true)
475  {
476  if (res < 0 || inputs || outputs)
477  {
478  break;
479  }
480  res = avfilter_graph_config(m_filterGraph, nullptr);
481  if (res < 0)
482  {
483  break;
484  }
485  if (!(m_bufferSrcCtx = avfilter_graph_get_filter(m_filterGraph, "Parsed_buffer_0")))
486  {
487  break;
488  }
489  if (!(m_bufferSinkCtx = avfilter_graph_get_filter(m_filterGraph, "Parsed_buffersink_2")))
490  {
491  break;
492  }
493  return 0;
494  }
495  avfilter_inout_free(&inputs);
496  avfilter_inout_free(&outputs);
497  return -1;
498 }
499 
501 {
502  if (m_filterGraph)
503  {
504  avfilter_graph_free(&m_filterGraph);
505  }
506 }
507 
509 {
511 }
512 
513 AVCodecContext *MythCodecMap::getCodecContext(const AVStream *stream,
514  const AVCodec *pCodec, bool nullCodec)
515 {
516  QMutexLocker lock(&m_mapLock);
517  AVCodecContext *avctx = m_streamMap.value(stream, nullptr);
518  if (!avctx)
519  {
520  if (stream == nullptr || stream->codecpar == nullptr)
521  return nullptr;
522  if (nullCodec)
523  pCodec = nullptr;
524  else
525  {
526  if (!pCodec)
527  pCodec = avcodec_find_decoder(stream->codecpar->codec_id);
528  if (!pCodec)
529  {
530  LOG(VB_GENERAL, LOG_WARNING,
531  QString("avcodec_find_decoder fail for %1").arg(stream->codecpar->codec_id));
532  return nullptr;
533  }
534  }
535  avctx = avcodec_alloc_context3(pCodec);
536  if (avcodec_parameters_to_context(avctx, stream->codecpar) < 0)
537  avcodec_free_context(&avctx);
538  if (avctx)
539  {
540  avctx->pkt_timebase = stream->time_base;
541  m_streamMap.insert(stream, avctx);
542  }
543  }
544  return avctx;
545 }
546 
547 AVCodecContext *MythCodecMap::hasCodecContext(const AVStream *stream)
548 {
549  return m_streamMap.value(stream, nullptr);
550 }
551 
555 void MythCodecMap::freeCodecContext(const AVStream *stream)
556 {
557  QMutexLocker lock(&m_mapLock);
558  AVCodecContext *avctx = m_streamMap.take(stream);
559  if (avctx)
560  {
561  if (avctx->internal)
562  avcodec_flush_buffers(avctx);
563  avcodec_free_context(&avctx);
564  }
565 }
566 
568 {
569  QMutexLocker lock(&m_mapLock);
570  QMap<const AVStream*, AVCodecContext*>::iterator i = m_streamMap.begin();
571  while (i != m_streamMap.end()) {
572  const AVStream *stream = i.key();
573  ++i;
574  freeCodecContext(stream);
575  }
576 }
577 
579 {
580  const int probeBufferSize = 8 * 1024;
581  AVInputFormat *fmt = nullptr;
582  AVProbeData probe;
583  memset(&probe, 0, sizeof(AVProbeData));
584  probe.filename = "";
585  probe.buf = new unsigned char[probeBufferSize + AVPROBE_PADDING_SIZE];
586  probe.buf_size = probeBufferSize;
587  memset(probe.buf, 0, probeBufferSize + AVPROBE_PADDING_SIZE);
588  av_log_set_level(AV_LOG_FATAL);
589  m_errorCode = 0;
590  if (filename == "")
591  m_errorCode = 97;
592  QFile infile(filename);
593  if (m_errorCode == 0 && !infile.open(QIODevice::ReadOnly))
594  m_errorCode = 99;
595  if (m_errorCode==0) {
596  int64_t leng = infile.read(reinterpret_cast<char*>(probe.buf), probeBufferSize);
597  probe.buf_size = static_cast<int>(leng);
598  infile.close();
599  fmt = av_probe_input_format(&probe, static_cast<int>(true));
600  if (fmt == nullptr)
601  m_errorCode = 98;
602  }
603  AVFormatContext *ctx = nullptr;
604  if (m_errorCode==0)
605  {
606  ctx = avformat_alloc_context();
607  m_errorCode = avformat_open_input(&ctx, filename.toUtf8(), fmt, nullptr);
608  }
609  if (m_errorCode==0)
610  m_errorCode = avformat_find_stream_info(ctx, nullptr);
611 
612  if (m_errorCode==0)
613  {
614  for (uint ix = 0; ix < ctx->nb_streams; ix++)
615  {
616  AVStream *stream = ctx->streams[ix];
617  if (stream == nullptr)
618  continue;
619  AVCodecParameters *codecpar = stream->codecpar;
620  const AVCodecDescriptor* desc = nullptr;
621  MythStreamInfo info;
622  info.m_codecType = ' ';
623  if (codecpar != nullptr)
624  {
625  desc = avcodec_descriptor_get(codecpar->codec_id);
626  switch (codecpar->codec_type)
627  {
628  case AVMEDIA_TYPE_VIDEO:
629  info.m_codecType = 'V';
630  break;
631  case AVMEDIA_TYPE_AUDIO:
632  info.m_codecType = 'A';
633  break;
634  case AVMEDIA_TYPE_SUBTITLE:
635  info.m_codecType = 'S';
636  break;
637  default:
638  continue;
639  }
640  }
641  if (desc != nullptr)
642  info.m_codecName = desc->name;
643  info.m_duration = stream->duration * stream->time_base.num / stream->time_base.den;
644  if (info.m_codecType == 'V')
645  {
646  if (codecpar != nullptr)
647  {
648  info.m_width = codecpar->width;
649  info.m_height = codecpar->height;
650  info.m_SampleAspectRatio = static_cast<float>(codecpar->sample_aspect_ratio.num)
651  / static_cast<float>(codecpar->sample_aspect_ratio.den);
652  switch (codecpar->field_order)
653  {
654  case AV_FIELD_PROGRESSIVE:
655  info.m_fieldOrder = "PR";
656  break;
657  case AV_FIELD_TT:
658  info.m_fieldOrder = "TT";
659  break;
660  case AV_FIELD_BB:
661  info.m_fieldOrder = "BB";
662  break;
663  case AV_FIELD_TB:
664  info.m_fieldOrder = "TB";
665  break;
666  case AV_FIELD_BT:
667  info.m_fieldOrder = "BT";
668  break;
669  default:
670  break;
671  }
672  }
673  info.m_frameRate = static_cast<float>(stream->r_frame_rate.num)
674  / static_cast<float>(stream->r_frame_rate.den);
675  info.m_avgFrameRate = static_cast<float>(stream->avg_frame_rate.num)
676  / static_cast<float>(stream->avg_frame_rate.den);
677  }
678  if (info.m_codecType == 'A')
679  info.m_channels = codecpar->channels;
680  m_streamInfoList.append(info);
681  }
682  }
683  if (m_errorCode != 0)
684  {
685  switch(m_errorCode) {
686  case 97:
687  m_errorMsg = "File Not Found";
688  break;
689  case 98:
690  m_errorMsg = "av_probe_input_format returned no result";
691  break;
692  case 99:
693  m_errorMsg = "File could not be opened";
694  break;
695  default:
696  std::string errbuf;
697  if (av_strerror_stdstring(m_errorCode, errbuf) == 0)
698  m_errorMsg = QString::fromStdString(errbuf);
699  else
700  m_errorMsg = "UNKNOWN";
701  }
702  LOG(VB_GENERAL, LOG_ERR,
703  QString("MythStreamInfoList failed for %1. Error code:%2 Message:%3")
705 
706  }
707 
708  if (ctx != nullptr)
709  {
710  avformat_close_input(&ctx);
711  avformat_free_context(ctx);
712  }
713  delete [] probe.buf;
714 }
MythStreamInfoList::m_errorMsg
QString m_errorMsg
Definition: mythavutil.h:225
FMT_MEDIACODEC
@ FMT_MEDIACODEC
Definition: mythframe.h:65
build_compdb.args
args
Definition: build_compdb.py:11
DEINT_DRIVER
@ DEINT_DRIVER
Definition: mythframe.h:129
MythCodecMap::hasCodecContext
AVCodecContext * hasCodecContext(const AVStream *stream)
Definition: mythavutil.cpp:547
MythStreamInfo::m_codecName
QString m_codecName
Definition: mythavutil.h:200
DEINT_MEDIUM
@ DEINT_MEDIUM
Definition: mythframe.h:125
MythStreamInfo::m_height
int m_height
Definition: mythavutil.h:204
FMT_YUV420P10
@ FMT_YUV420P10
Definition: mythframe.h:30
GetBufferSize
static size_t GetBufferSize(VideoFrameType Type, int Width, int Height, int Aligned=MYTH_WIDTH_ALIGNMENT)
Definition: mythframe.h:658
FMT_YUV420P16
@ FMT_YUV420P16
Definition: mythframe.h:33
MythPictureDeinterlacer::m_ar
float m_ar
Definition: mythavutil.h:191
VideoFrame::pitches
int pitches[3]
Y, U, & V pitches.
Definition: mythframe.h:161
MythAVCopy::MythAVCopy
MythAVCopy(bool USWC=true)
Definition: mythavutil.cpp:253
FMT_VTB
@ FMT_VTB
Definition: mythframe.h:66
DEINT_SHADER
@ DEINT_SHADER
Definition: mythframe.h:128
FMT_YUV420P14
@ FMT_YUV420P14
Definition: mythframe.h:32
MythPictureDeinterlacer::MythPictureDeinterlacer
MythPictureDeinterlacer(AVPixelFormat pixfmt, int width, int height, float ar=1.0F)
Definition: mythavutil.cpp:386
FMT_DRMPRIME
@ FMT_DRMPRIME
Definition: mythframe.h:68
FMT_YUV444P10
@ FMT_YUV444P10
Definition: mythframe.h:50
FMT_YUV422P14
@ FMT_YUV422P14
Definition: mythframe.h:45
MythStreamInfo::m_codecType
char m_codecType
Definition: mythavutil.h:199
MythStreamInfo::m_avgFrameRate
float m_avgFrameRate
Definition: mythavutil.h:212
d
static const uint16_t * d
Definition: iso6937tables.cpp:1025
MythStreamInfo
Definition: mythavutil.h:196
FMT_P010
@ FMT_P010
Definition: mythframe.h:58
MythPictureDeinterlacer::m_height
int m_height
Definition: mythavutil.h:190
MythPictureDeinterlacer::Deinterlace
int Deinterlace(AVFrame *dst, const AVFrame *src)
Definition: mythavutil.cpp:399
DEINT_NONE
@ DEINT_NONE
Definition: mythframe.h:123
arg
arg(title).arg(filename).arg(doDelete))
PixelFormatToFrameType
VideoFrameType PixelFormatToFrameType(AVPixelFormat fmt)
Definition: mythavutil.cpp:69
MythDate::Format
Format
Definition: mythdate.h:12
DeinterlacerPref
QString DeinterlacerPref(MythDeintType Deint)
Definition: mythavutil.cpp:183
FMT_YUV422P
@ FMT_YUV422P
Definition: mythframe.h:41
VideoFrame::buf
unsigned char * buf
Definition: mythframe.h:140
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythStreamInfo::m_duration
int64_t m_duration
Definition: mythavutil.h:201
mythframe.h
VideoFrame
Definition: mythframe.h:137
MythCodecMap::freeAllCodecContexts
void freeAllCodecContexts()
Definition: mythavutil.cpp:567
MythUSWCCopy
Definition: mythframe.h:199
MythAVCopyPrivate::MythAVCopyPrivate
MythAVCopyPrivate(bool uswc)
Definition: mythavutil.cpp:217
MythPictureDeinterlacer::m_bufferSinkCtx
AVFilterContext * m_bufferSinkCtx
Definition: mythavutil.h:186
FMT_YUV444P14
@ FMT_YUV444P14
Definition: mythframe.h:52
FMT_YUV444P
@ FMT_YUV444P
Definition: mythframe.h:48
VideoFrame::codec
VideoFrameType codec
Definition: mythframe.h:139
MythAVCopyPrivate::m_swsctx
SwsContext * m_swsctx
Definition: mythavutil.cpp:245
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:26
DEINT_CPU
@ DEINT_CPU
Definition: mythframe.h:127
MythPictureDeinterlacer::Flush
int Flush()
Definition: mythavutil.cpp:454
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
MythStreamInfoList::m_errorCode
int m_errorCode
Definition: mythavutil.h:224
MythPictureDeinterlacer::m_pixfmt
AVPixelFormat m_pixfmt
Definition: mythavutil.h:188
DeinterlacerName
QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format)
Return a user friendly description of the given deinterlacer.
Definition: mythavutil.cpp:115
MythStreamInfo::m_width
int m_width
Definition: mythavutil.h:203
MythCodecMap::getCodecContext
AVCodecContext * getCodecContext(const AVStream *stream, const AVCodec *pCodec=nullptr, bool nullCodec=false)
Definition: mythavutil.cpp:513
MythPictureDeinterlacer::~MythPictureDeinterlacer
~MythPictureDeinterlacer()
Definition: mythavutil.cpp:500
av_strerror_stdstring
int av_strerror_stdstring(int errnum, std::string &errbuf)
Definition: mythaverror.cpp:27
FMT_YUV444P9
@ FMT_YUV444P9
Definition: mythframe.h:49
FMT_YV12
@ FMT_YV12
Definition: mythframe.h:28
MythAVCopyPrivate::m_format
AVPixelFormat m_format
Definition: mythavutil.cpp:250
FMT_YUV422P10
@ FMT_YUV422P10
Definition: mythframe.h:43
FMT_YUV444P16
@ FMT_YUV444P16
Definition: mythframe.h:53
MythAVCopyPrivate
Definition: mythavutil.cpp:214
MythStreamInfo::m_channels
int m_channels
Definition: mythavutil.h:214
FMT_BGRA
@ FMT_BGRA
Definition: mythframe.h:36
MythStreamInfo::m_SampleAspectRatio
float m_SampleAspectRatio
Definition: mythavutil.h:205
FMT_YUV420P12
@ FMT_YUV420P12
Definition: mythframe.h:31
MythAVCopyPrivate::m_copyctx
MythUSWCCopy * m_copyctx
Definition: mythavutil.cpp:246
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
MythPictureDeinterlacer::m_filterFrame
MythAVFrame m_filterFrame
Definition: mythavutil.h:185
init
static void init(VideoFrame *vf, VideoFrameType _codec, unsigned char *_buf, int _width, int _height, int _size, const int *p=nullptr, const int *o=nullptr, float _aspect=-1.0F, double _rate=-1.0F, int _aligned=MYTH_WIDTH_ALIGNMENT)
Definition: mythframe.h:232
MythAVCopyPrivate::operator=
MythAVCopyPrivate & operator=(const MythAVCopyPrivate &)=delete
uint
unsigned int uint
Definition: compat.h:140
FMT_YUV444P12
@ FMT_YUV444P12
Definition: mythframe.h:51
MythAVCopyPrivate::m_size
int m_size
Definition: mythavutil.cpp:249
FMT_ARGB32
@ FMT_ARGB32
Definition: mythframe.h:38
MythPictureDeinterlacer::m_width
int m_width
Definition: mythavutil.h:189
MythStreamInfo::m_frameRate
float m_frameRate
Definition: mythavutil.h:211
FMT_NVDEC
@ FMT_NVDEC
Definition: mythframe.h:67
FMT_YUV422P9
@ FMT_YUV422P9
Definition: mythframe.h:42
MythDeintType
MythDeintType
Definition: mythframe.h:121
MythStreamInfo::m_fieldOrder
QString m_fieldOrder
Definition: mythavutil.h:210
VideoFrame::offsets
int offsets[3]
Y, U, & V offsets.
Definition: mythframe.h:162
FMT_YUV420P9
@ FMT_YUV420P9
Definition: mythframe.h:29
AVPictureFill
int AVPictureFill(AVFrame *pic, const VideoFrame *frame, AVPixelFormat fmt)
AVPictureFill Initialise AVFrame pic with content from VideoFrame frame.
Definition: mythavutil.cpp:197
mythcorecontext.h
FMT_VDPAU
@ FMT_VDPAU
Definition: mythframe.h:61
FMT_YUV422P16
@ FMT_YUV422P16
Definition: mythframe.h:46
FMT_YUY2
@ FMT_YUY2
Definition: mythframe.h:55
FMT_DXVA2
@ FMT_DXVA2
Definition: mythframe.h:63
FMT_RGB24
@ FMT_RGB24
Definition: mythframe.h:35
FMT_YUV422P12
@ FMT_YUV422P12
Definition: mythframe.h:44
DEINT_HIGH
@ DEINT_HIGH
Definition: mythframe.h:126
MythStreamInfoList::MythStreamInfoList
MythStreamInfoList(QString filename)
Definition: mythavutil.cpp:578
mythavutil.h
MythCodecMap::m_mapLock
QMutex m_mapLock
Definition: mythavutil.h:98
MythAVCopy::d
MythAVCopyPrivate * d
Definition: mythavutil.h:141
VideoFrame::height
int height
Definition: mythframe.h:143
MythAVCopyPrivate::~MythAVCopyPrivate
~MythAVCopyPrivate()
Definition: mythavutil.cpp:220
CreateBuffer
static unsigned char * CreateBuffer(VideoFrameType Type, int Width, int Height)
Definition: mythframe.h:689
MythCodecMap::~MythCodecMap
~MythCodecMap()
Definition: mythavutil.cpp:508
MythPictureDeinterlacer::m_errored
bool m_errored
Definition: mythavutil.h:192
FMT_RGB32
@ FMT_RGB32
endian dependent format, ARGB or BGRA
Definition: mythframe.h:37
FMT_MMAL
@ FMT_MMAL
Definition: mythframe.h:64
VideoFrameType
VideoFrameType
Definition: mythframe.h:24
FMT_VAAPI
@ FMT_VAAPI
Definition: mythframe.h:62
MythAVCopy::Copy
int Copy(VideoFrame *dst, const VideoFrame *src)
Definition: mythavutil.cpp:331
MythCodecMap::m_streamMap
QMap< const AVStream *, AVCodecContext * > m_streamMap
Definition: mythavutil.h:97
MythAVCopy::~MythAVCopy
virtual ~MythAVCopy()
Definition: mythavutil.cpp:257
FMT_NV12
@ FMT_NV12
Definition: mythframe.h:57
DEINT_BASIC
@ DEINT_BASIC
Definition: mythframe.h:124
VideoFrame::size
int size
Definition: mythframe.h:147
MythAVCopyPrivate::m_height
int m_height
Definition: mythavutil.cpp:248
MythAVCopyPrivate::m_width
int m_width
Definition: mythavutil.cpp:247
FMT_P016
@ FMT_P016
Definition: mythframe.h:59
MythAVCopyPrivate::SizeData
int SizeData(int _width, int _height, AVPixelFormat _fmt)
Definition: mythavutil.cpp:232
MythUSWCCopy::copy
void copy(VideoFrame *dst, const VideoFrame *src)
Definition: mythframe.cpp:622
GetDeinterlacer
MythDeintType GetDeinterlacer(MythDeintType Option)
Definition: mythframe.cpp:860
MythPictureDeinterlacer::DeinterlaceSingle
int DeinterlaceSingle(AVFrame *dst, const AVFrame *src)
Definition: mythavutil.cpp:434
VideoFrame::width
int width
Definition: mythframe.h:142
MythCodecMap::freeCodecContext
void freeCodecContext(const AVStream *stream)
Definition: mythavutil.cpp:555
FrameTypeToPixelFormat
AVPixelFormat FrameTypeToPixelFormat(VideoFrameType type)
Convert VideoFrameType into FFmpeg's PixelFormat equivalent and vice-versa.
Definition: mythavutil.cpp:25
MythPictureDeinterlacer::m_filterGraph
AVFilterGraph * m_filterGraph
Definition: mythavutil.h:184
MythAVCopy::FillFrame
static void FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch, int width, int height, AVPixelFormat pix_fmt)
Definition: mythavutil.cpp:262
FMT_RGBA32
@ FMT_RGBA32
Definition: mythframe.h:39
MythPictureDeinterlacer::m_bufferSrcCtx
AVFilterContext * m_bufferSrcCtx
Definition: mythavutil.h:187
MythStreamInfoList::m_streamInfoList
QVector< MythStreamInfo > m_streamInfoList
Definition: mythavutil.h:226