File: ExampleBlackmagic.cpp

package info (click to toggle)
libopenshot 0.2.7%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,720 kB
  • sloc: cpp: 25,009; python: 93; makefile: 18; ruby: 5; sh: 2
file content (231 lines) | stat: -rw-r--r-- 5,349 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
 * @file
 * @brief Source file for Main_Blackmagic class (live greenscreen example app)
 * @author Jonathan Thomas <jonathan@openshot.org>
 *
 * @ref License
 */

/* LICENSE
 *
 * Copyright (c) 2008-2019 OpenShot Studios, LLC
 * <http://www.openshotstudios.com/>. This file is part of
 * OpenShot Library (libopenshot), an open-source project dedicated to
 * delivering high quality video editing and animation solutions to the
 * world. For more information visit <http://www.openshot.org/>.
 *
 * OpenShot Library (libopenshot) is free software: you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * OpenShot Library (libopenshot) is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
 */

#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <memory>
#include "../../include/OpenShot.h"
#include <omp.h>
#include <time.h>

using namespace openshot;

int main(int argc, char *argv[])
{
	// Init datetime
	time_t rawtime;
	struct tm * timeinfo;

	/* TIMELINE ---------------- */
	Timeline t(1920, 1080, Fraction(30,1), 48000, 2, LAYOUT_STEREO);

	// Create background video
	ImageReader b1("/home/jonathan/Pictures/moon.jpg");
	ImageReader b2("/home/jonathan/Pictures/trees.jpg");
	ImageReader b3("/home/jonathan/Pictures/clouds.jpg");
	ImageReader b4("/home/jonathan/Pictures/minecraft.png");
	ImageReader b5("/home/jonathan/Pictures/colorpgg03.jpg");
	Clip c1(&b1);

	// Background counter
	int background_frame = 0;
	int background_id = 1;

	DecklinkReader dr(1, 11, 0, 2, 16);
	Clip c2(&dr);
	Clip c3(new ImageReader("/home/jonathan/Pictures/watermark.png"));

	// mask
	Clip c4(new ImageReader("/home/jonathan/Pictures/mask_small.png"));

	// CLIP 1 (background image)
	c1.Position(0.0);
	c1.scale = SCALE_NONE;
	c1.Layer(0);
	t.AddClip(&c1);

	// CLIP 2 (decklink live stream)
	c2.Position(0.0);
	c2.scale = SCALE_NONE;
	c2.Layer(1);
	t.AddClip(&c2);

	// CLIP 3 (foreground image 1)
	c3.Position(0.0);
	c3.gravity = GRAVITY_TOP;
	//c3.gravity = GRAVITY_BOTTOM;
	c3.scale = SCALE_NONE;
	c3.Layer(2);
	t.AddClip(&c3);

	// CLIP 4 (foreground image 2)
	c4.Position(0.0);
	c4.gravity = GRAVITY_TOP;
	c4.scale = SCALE_NONE;
	c4.Layer(3);
	//t.AddClip(&c4);

	// Decklink writer
	DecklinkWriter w(0, 11, 3, 2, 16);
	w.Open();

	// Loop through reader
	int x = 0;
	while (true)
	{
		std::shared_ptr<Frame> f = t.GetFrame(x);
		if (f)
		{
			if (x != 0 && x % 30 == 0)
			{
				cout << "30 frames... (" << abs(dr.GetCurrentFrameNumber() - x) << " diff)" << endl;

				if (x != 0 && x % 60 == 0)
				{
					time ( &rawtime );
					timeinfo = localtime ( &rawtime );

					stringstream timestamp;
					timestamp << asctime (timeinfo);

					stringstream filename;
					filename << "/home/jonathan/Pictures/screenshots/detailed/" << timestamp.str() << ".jpeg";
					f->Save(filename.str(), 1.0);
					stringstream filename_small;
					filename_small << "/home/jonathan/Pictures/screenshots/thumbs/" << timestamp.str() << ".jpeg";
					f->Save(filename_small.str(), 0.15);
				}
			}

			// Send current frame to BlackMagic
			w.WriteFrame(f);

			// Increment background frame #
			background_frame++;

			// Change background
			if (background_frame == 300)
			{
				background_frame = 0;
				switch (background_id)
				{
				case 1:
					c1.Reader(&b2);
					background_id = 2;
					break;
				case 2:
					c1.Reader(&b3);
					background_id = 3;
					break;
				case 3:
					c1.Reader(&b4);
					background_id = 4;
					break;
				case 4:
					c1.Reader(&b5);
					background_id = 5;
					break;
				case 5:
					c1.Reader(&b1);
					background_id = 1;
					break;
				}
			}


			//usleep(500 * 1);
			// Go to next frame on timeline
			if (abs(dr.GetCurrentFrameNumber() - x) > 40 || x == 90)
			{
				// Got behind... skip ahead some
				x = dr.GetCurrentFrameNumber();

				cout << "JUMPING AHEAD to " << x << ", background moved to " << (float(x) / 30.0f) << endl;
			}
			else
				// Go to the next frame
				x++;
		}
	}

	// Sleep
	sleep(4);




	// Image Reader
//	ImageReader r1("/home/jonathan/Pictures/Screenshot from 2013-02-10 15:06:38.png");
//	r1.Open();
//	std::shared_ptr<Frame> f1 = r1.GetFrame(1);
//	r1.Close();
//	f1->TransparentColors("#8fa09a", 20.0);
//	f1->Display();
//	return 0;

//	ImageReader r2("/home/jonathan/Pictures/trees.jpg");
//	r2.Open();
//	std::shared_ptr<Frame> f2 = r2.GetFrame(1);
//	r2.Close();

//	DecklinkReader dr(1, 11, 0, 2, 16);
//	dr.Open();
//
//	DecklinkWriter w(0, 11, 3, 2, 16);
//	w.Open();
//
//	// Loop through reader
//	int x = 0;
//	while (true)
//	{
//		if (x % 30 == 0)
//			cout << "30 frames..." << endl;
//
//		std::shared_ptr<Frame> f = dr.GetFrame(0);
//		if (f)
//		{
//			//f->Display();
//			w.WriteFrame(f);
//			usleep(1000 * 1);
//
//			x++;
//		}
//	}
//
//	// Sleep
//	sleep(4);
//
//	// Close writer
//	w.Close();

	return 0;
}