OpenShot Library | libopenshot  0.3.0
FrameMapper.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_FRAMEMAPPER_H
14 #define OPENSHOT_FRAMEMAPPER_H
15 
16 #include <assert.h>
17 #include <iostream>
18 #include <vector>
19 #include <memory>
20 
21 #include "CacheMemory.h"
22 #include "ReaderBase.h"
23 #include "Frame.h"
24 #include "Fraction.h"
25 #include "KeyFrame.h"
26 
27 
28 // Include FFmpeg headers and macros
29 #include "FFmpegUtilities.h"
30 #include "OpenMPUtilities.h"
31 
32 
33 namespace openshot
34 {
42  {
46  };
47 
54  struct Field
55  {
56  int64_t Frame;
57  bool isOdd;
58 
59  Field() : Frame(0), isOdd(true) { };
60 
61  Field(int64_t frame, bool isodd)
62  {
63  Frame = frame;
64  isOdd = isodd;
65  }
66  };
67 
74  struct SampleRange
75  {
76  int64_t frame_start;
78 
79  int64_t frame_end;
81 
82  int total;
83  };
84 
91  struct MappedFrame
92  {
96  };
97 
98 
120  class FrameMapper : public ReaderBase {
121  private:
122  bool field_toggle; // Internal odd / even toggle (used when building the mapping)
123  Fraction original; // The original frame rate
124  Fraction target; // The target frame rate
125  PulldownType pulldown; // The pull-down technique
126  ReaderBase *reader; // The source video reader
127  CacheMemory final_cache; // Cache of actual Frame objects
128  bool is_dirty; // When this is true, the next call to GetFrame will re-init the mapping
129  float parent_position; // Position of parent clip (which is used to generate the audio mapping)
130  float parent_start; // Start of parent clip (which is used to generate the audio mapping)
131  SWRCONTEXT *avr; // Audio resampling context object
132 
133  // Internal methods used by init
134  void AddField(int64_t frame);
135  void AddField(Field field);
136 
137  // Clear both the fields & frames lists
138  void Clear();
139 
140  // Get Frame or Generate Blank Frame
141  std::shared_ptr<Frame> GetOrCreateFrame(int64_t number);
142 
144  int64_t AdjustFrameNumber(int64_t clip_frame_number);
145 
146  // Use the original and target frame rates and a pull-down technique to create
147  // a mapping between the original fields and frames or a video to a new frame rate.
148  // This might repeat or skip fields and frames of the original video, depending on
149  // whether the frame rate is increasing or decreasing.
150  void Init();
151 
152  public:
153  // Init some containers
154  std::vector<Field> fields; // List of all fields
155  std::vector<MappedFrame> frames; // List of all frames
156 
158  FrameMapper(ReaderBase *reader, Fraction target_fps, PulldownType target_pulldown, int target_sample_rate, int target_channels, ChannelLayout target_channel_layout);
159 
161  virtual ~FrameMapper();
162 
164  void ChangeMapping(Fraction target_fps, PulldownType pulldown, int target_sample_rate, int target_channels, ChannelLayout target_channel_layout);
165 
167  void Close() override;
168 
170  MappedFrame GetMappedFrame(int64_t TargetFrameNumber);
171 
173  CacheMemory* GetCache() override { return &final_cache; };
174 
181  std::shared_ptr<Frame> GetFrame(int64_t requested_frame) override;
182 
184  bool IsOpen() override;
185 
187  std::string Name() override { return "FrameMapper"; };
188 
189  // Get and Set JSON methods
190  std::string Json() const override;
191  void SetJson(const std::string value) override;
192  Json::Value JsonValue() const override;
193  void SetJsonValue(const Json::Value root) override;
194 
196  void Open() override;
197 
199  void PrintMapping(std::ostream* out=&std::cout);
200 
202  ReaderBase* Reader();
203 
205  void Reader(ReaderBase *new_reader) { reader = new_reader; }
206 
208  void ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t original_frame_number);
209  };
210 }
211 
212 #endif
Classic 2:3:2:3 pull-down.
Definition: FrameMapper.h:43
Header file for Fraction class.
#define SWRCONTEXT
Header file for ReaderBase class.
Header file for OpenMPUtilities (set some common macros)
std::vector< MappedFrame > frames
Definition: FrameMapper.h:155
std::vector< Field > fields
Definition: FrameMapper.h:154
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
Header file for the Keyframe class.
This struct holds a single field (half a frame).
Definition: FrameMapper.h:54
Header file for CacheMemory class.
This struct holds a the range of samples needed by this frame.
Definition: FrameMapper.h:74
Header file for Frame class.
Field(int64_t frame, bool isodd)
Definition: FrameMapper.h:61
This class represents a fraction.
Definition: Fraction.h:30
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround...
void Reader(ReaderBase *new_reader)
Set the current reader.
Definition: FrameMapper.h:205
CacheMemory * GetCache() override
Get the cache object used by this reader.
Definition: FrameMapper.h:173
This struct holds two fields which together make up a complete video frame.
Definition: FrameMapper.h:91
std::string Name() override
Return the type name of the class.
Definition: FrameMapper.h:187
This class creates a mapping between 2 different frame rates, applying a specific pull-down technique...
Definition: FrameMapper.h:120
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
SampleRange Samples
Definition: FrameMapper.h:95
Do not apply pull-down techniques, just repeat or skip entire frames.
Definition: FrameMapper.h:45
PulldownType
This enumeration determines how frame rates are increased or decreased.
Definition: FrameMapper.h:41
Header file for FFmpegUtilities.
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:29
Advanced 2:3:3:2 pull-down (minimal dirty frames)
Definition: FrameMapper.h:44