AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Frame.cpp
Go to the documentation of this file.
1 #include "Frame.hpp"
2 
3 #include <stdexcept>
4 
5 namespace avtranscoder
6 {
7 
9  : _frame(NULL)
10 {
12 }
13 
14 Frame::Frame(const Frame& otherFrame)
15  : _frame(NULL)
16 {
17  // allocate frame
19  // check if the frame could be a valid video/audio frame
20  if(otherFrame.getAVFrame().format == -1)
21  return;
22  // reference the other frame
23  refFrame(otherFrame);
24 }
25 
27 {
28  if(_frame != NULL)
29  {
30 #if LIBAVCODEC_VERSION_MAJOR > 54
31  av_frame_free(&_frame);
32 #else
33 #if LIBAVCODEC_VERSION_MAJOR > 53
34  avcodec_free_frame(&_frame);
35 #else
36  av_free(_frame);
37 #endif
38 #endif
39  _frame = NULL;
40  }
41 }
42 
44 {
45  return av_frame_get_pkt_size(_frame);
46 }
47 
48 void Frame::copyData(const Frame& frameToRef)
49 {
50  const int ret = av_frame_copy(_frame, &frameToRef.getAVFrame());
51  if(ret < 0)
52  {
53  throw std::ios_base::failure("Unable to copy data of other frame: " + getDescriptionFromErrorCode(ret));
54  }
55 }
56 
57 void Frame::copyProperties(const Frame& otherFrame)
58 {
59  av_frame_copy_props(_frame, &otherFrame.getAVFrame());
60 }
61 
62 void Frame::refFrame(const Frame& otherFrame)
63 {
64  const int ret = av_frame_ref(_frame, &otherFrame.getAVFrame());
65  if(ret < 0)
66  {
67  throw std::ios_base::failure("Unable to reference other frame: " + getDescriptionFromErrorCode(ret));
68  }
69 }
70 
72 {
73  av_frame_unref(_frame);
74 }
75 
77 {
78 #if LIBAVCODEC_VERSION_MAJOR > 54
79  _frame = av_frame_alloc();
80 #else
81  _frame = avcodec_alloc_frame();
82 #endif
83  if(_frame == NULL)
84  {
85  throw std::runtime_error("Unable to allocate an empty Frame.");
86  }
87 }
88 
89 bool Frame::isAudioFrame() const
90 {
91  if(_frame->sample_rate && _frame->channels && _frame->channel_layout && _frame->format != -1)
92  return true;
93  return false;
94 }
95 
96 bool Frame::isVideoFrame() const
97 {
98  if(_frame->width && _frame->height && _frame->format != -1)
99  return true;
100  return false;
101 }
102 }
bool isVideoFrame() const
Definition: Frame.cpp:96
void allocateAVFrame()
Definition: Frame.cpp:76
Frame()
Allocate an empty frame. This only allocates the AVFrame itself, not the data buffers.
Definition: Frame.cpp:8
void clear()
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: Frame.cpp:71
std::string getDescriptionFromErrorCode(const int code)
Get the string description corresponding to the error code provided by ffmpeg/libav.
Definition: common.cpp:22
bool isAudioFrame() const
Definition: Frame.cpp:89
void refFrame(const Frame &otherFrame)
Copy frame properties and create a new reference to data of the given frame.
Definition: Frame.cpp:62
void copyProperties(const Frame &otherFrame)
Copy all the fields that do not affect the data layout in the buffers.
Definition: Frame.cpp:57
int getEncodedSize() const
Definition: Frame.cpp:43
virtual ~Frame()
Definition: Frame.cpp:26
AVFrame * _frame
Definition: Frame.hpp:97
This class describes decoded (raw) audio or video data.
Definition: Frame.hpp:16
void copyData(const Frame &frameToRef)
Copy the data of the given Frame.
Definition: Frame.cpp:48
AVFrame & getAVFrame()
Definition: Frame.hpp:88
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy