ExampleBlackmagic.cpp
Go to the documentation of this file.
/**
* @file
* @brief Source file for Main_Blackmagic class (live greenscreen example app)
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @section LICENSE
*
* Copyright (c) 2008-2014 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;
}
openshot::DecklinkWriter::WriteFrame
void WriteFrame(std::shared_ptr< Frame > frame)
This method is required for all derived classes of WriterBase. Write a Frame to the video file...
Definition: DecklinkWriter.cpp:230
openshot::Clip::gravity
GravityType gravity
The gravity of a clip determines where it snaps to it&#39;s parent.
Definition: Clip.h:151
openshot::SCALE_NONE
Do not scale the clip.
Definition: Enums.h:54
openshot::DecklinkReader::GetCurrentFrameNumber
unsigned long GetCurrentFrameNumber()
Definition: DecklinkReader.cpp:228
openshot::ClipBase::Layer
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:84
openshot::ImageReader
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
Definition: ImageReader.h:67
openshot::Clip
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:109
openshot::Clip::scale
ScaleType scale
The scale determines how a clip should be resized to fit it&#39;s parent.
Definition: Clip.h:152
openshot::LAYOUT_STEREO
Definition: ChannelLayouts.h:46
openshot::ClipBase::Position
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:83
openshot::Clip::Reader
void Reader(ReaderBase *new_reader)
Set the current reader.
Definition: Clip.cpp:188
openshot::Timeline::GetFrame
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
Definition: Timeline.cpp:639
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:42
OpenShot Wipe Tests.t
t
Definition: OpenShot Wipe Tests.py:4
openshot::Timeline::AddClip
void AddClip(Clip *clip)
Add an openshot::Clip to the timeline.
Definition: Timeline.cpp:71
openshot::DecklinkWriter::Open
void Open()
Open device and video stream - which is called by the constructor automatically.
Definition: DecklinkWriter.cpp:57
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:45
OpenShot Wipe Tests.c2
c2
Definition: OpenShot Wipe Tests.py:14
openshot::GRAVITY_TOP
Align clip to the top center of its parent.
Definition: Enums.h:38
main
int main(int argc, char *argv[])
Definition: ExampleBlackmagic.cpp:39
OpenShot Wipe Tests.c1
c1
Definition: OpenShot Wipe Tests.py:8
openshot::DecklinkReader
This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices...
Definition: DecklinkReader.h:61
openshot::DecklinkWriter
This class uses the Blackmagic Decklink libraries, to send video streams to Blackmagic devices...
Definition: DecklinkWriter.h:61
openshot::Timeline
This class represents a timeline.
Definition: Timeline.h:145