Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 132 lines (123 sloc) 4.149 kb
a83448f1 »
2011-01-20 initial commit
1 #ifndef _MP4TRACKX
2 #define _MP4TRACKX
3
4 #include "mp4v2wrapper.h"
5
6 struct SampleTime {
7 uint64_t dts, cts;
8 };
9
10 struct FPSRange {
11 uint32_t numFrames;
12 int fps_num, fps_denom;
13 };
14
585043f4 »
2011-05-15 mdhd rebuilding, code clean up
15 /*
16 * XXX:
17 * Ugly class only to reveal protected members of MP4Track
18 * via casting.
19 * Cannot have data members!
20 */
a83448f1 »
2011-01-20 initial commit
21 class MP4TrackX: public mp4v2::impl::MP4Track {
585043f4 »
2011-05-15 mdhd rebuilding, code clean up
22 public:
23 void RebuildMdhd();
24
25 void UpdateDurationsX(MP4Duration duration) {
26 return UpdateDurations(duration);
27 }
28 MP4Duration ToMovieDurationX(MP4Duration trackDuration) {
29 return ToMovieDuration(trackDuration);
30 }
31 void UpdateModificationTimesX() {
32 return UpdateModificationTimes();
33 }
34
35 mp4v2::impl::MP4Integer32Property*& TimeScaleProperty() {
36 return m_pTimeScaleProperty;
37 }
38 mp4v2::impl::MP4IntegerProperty* TrackDurationProperty() {
39 return m_pTrackDurationProperty;
40 }
41 mp4v2::impl::MP4IntegerProperty*& MediaDurationProperty() {
42 return m_pMediaDurationProperty;
43 }
44 mp4v2::impl::MP4IntegerProperty*& MediaModificationProperty() {
45 return m_pMediaModificationProperty;
46 }
47 mp4v2::impl::MP4Integer32Property* SttsCountProperty() {
48 return m_pSttsCountProperty;
49 }
50 mp4v2::impl::MP4Integer32Property* SttsSampleCountProperty() {
51 return m_pSttsSampleCountProperty;
52 }
53 mp4v2::impl::MP4Integer32Property* SttsSampleDeltaProperty() {
54 return m_pSttsSampleDeltaProperty;
55 }
56 mp4v2::impl::MP4Integer32Property* CttsCountProperty() {
57 return m_pCttsCountProperty;
58 }
59 mp4v2::impl::MP4Integer32Property* CttsSampleCountProperty() {
60 return m_pCttsSampleCountProperty;
61 }
62 mp4v2::impl::MP4Integer32Property* CttsSampleOffsetProperty() {
63 return m_pCttsSampleOffsetProperty;
64 }
65 mp4v2::impl::MP4Integer32Property* ElstCountProperty() {
66 return m_pElstCountProperty;
67 }
68 mp4v2::impl::MP4IntegerProperty* ElstMediaTimeProperty() {
69 return m_pElstMediaTimeProperty;
70 }
71 mp4v2::impl::MP4IntegerProperty* ElstDurationProperty() {
72 return m_pElstDurationProperty;
73 }
74 };
75
76 class TrackEditor {
a83448f1 »
2011-01-20 initial commit
77 struct CTSComparator {
585043f4 »
2011-05-15 mdhd rebuilding, code clean up
78 TrackEditor *owner_;
79 CTSComparator(TrackEditor *owner): owner_(owner) {}
a83448f1 »
2011-01-20 initial commit
80 bool operator()(uint32_t a, uint32_t b)
81 {
82 return owner_->CompareByCTS(a, b);
83 }
84 };
585043f4 »
2011-05-15 mdhd rebuilding, code clean up
85 MP4TrackX *m_track;
a83448f1 »
2011-01-20 initial commit
86 std::vector<SampleTime> m_sampleTimes;
87 std::vector<uint32_t> m_ctsIndex;
be056b07 »
2011-03-29 DTS compression
88 uint32_t m_timeScale;
5a8655f3 »
2011-05-08 added -p option, enabled DTS compression without modifying fps
89 int64_t m_initialDelay;
be056b07 »
2011-03-29 DTS compression
90 bool m_compressDTS;
b6157e20 »
2011-05-16 audio delay support
91 int m_audioDelay;
a83448f1 »
2011-01-20 initial commit
92 public:
585043f4 »
2011-05-15 mdhd rebuilding, code clean up
93 TrackEditor(MP4TrackX *track);
b6157e20 »
2011-05-16 audio delay support
94 void EnableDTSCompression(bool enable) { m_compressDTS = enable; }
95 void SetAudioDelay(int delay) { m_audioDelay = delay; }
2b280860 »
2012-04-13 add --timescale
96 void SetFPS(FPSRange *fpsRanges, size_t numRanges, int timeScale);
9a424aea »
2011-01-21 added -t option to import timecode v2 file.
97 void SetTimeCodes(double *timeCodes, size_t count, uint32_t timeScale);
5a8655f3 »
2011-05-08 added -p option, enabled DTS compression without modifying fps
98 void AdjustTimeCodes();
99 void DoEditTimeCodes();
100 uint32_t GetTimeScale() const { return m_timeScale; }
502f310e »
2012-04-14 keep extra sampletime entry to hold last time delta
101 size_t GetFrameCount() const { return m_sampleTimes.size() - 1; }
b6157e20 »
2011-05-16 audio delay support
102 uint64_t &DTS(size_t n) { return m_sampleTimes[n].dts; }
103 uint64_t &CTS(size_t n) { return m_sampleTimes[m_ctsIndex[n]].cts; }
502f310e »
2012-04-14 keep extra sampletime entry to hold last time delta
104 uint64_t GetMediaDuration() { return CTS(GetFrameCount()) - CTS(0); }
b6157e20 »
2011-05-16 audio delay support
105
a83448f1 »
2011-01-20 initial commit
106 private:
107 bool CompareByCTS(uint32_t a, uint32_t b)
108 {
109 return m_sampleTimes[a].cts < m_sampleTimes[b].cts;
110 }
b6157e20 »
2011-05-16 audio delay support
111 void LoadDTS();
112 void LoadCTS();
2b280860 »
2012-04-13 add --timescale
113 void NormalizeFPSRange(FPSRange *begin, const FPSRange *end);
9a424aea »
2011-01-21 added -t option to import timecode v2 file.
114 uint32_t CalcTimeScale(FPSRange *begin, const FPSRange *end);
115 uint64_t CalcSampleTimes(
a83448f1 »
2011-01-20 initial commit
116 const FPSRange *begin, const FPSRange *end, uint32_t timeScale);
b6157e20 »
2011-05-16 audio delay support
117 template <typename TimeCode>
118 void DelayTimeCodes(int64_t offset, TimeCode timeCode);
119 template <typename TimeCode>
120 void CompressTimeCodes(int64_t offset, TimeCode timeCode);
5a8655f3 »
2011-05-08 added -p option, enabled DTS compression without modifying fps
121 void OffsetCTS(int64_t off);
be056b07 »
2011-03-29 DTS compression
122 int64_t CalcInitialDelay();
9a424aea »
2011-01-21 added -t option to import timecode v2 file.
123 void UpdateStts();
3cd881e8 »
2011-03-29 refactored CTS offset calcuration
124 void UpdateCtts();
b6157e20 »
2011-05-16 audio delay support
125 void UpdateElst(MP4TrackX *track, int64_t mediaTime);
126 int64_t GetAudioDelayInTimeScale()
127 {
128 return m_audioDelay / 1000.0 * m_timeScale;
129 }
a83448f1 »
2011-01-20 initial commit
130 };
131
132 #endif
Something went wrong with that request. Please try again.