Files
libopenshot/examples/Example.cpp

60 lines
2.0 KiB
C++

/**
* @file
* @brief Source file for Example Executable (example app for libopenshot)
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <chrono>
#include <iostream>
#include <memory>
#include "Frame.h"
#include "FFmpegReader.h"
using namespace openshot;
int main(int argc, char* argv[]) {
// Path to your video
const char* path = "/home/jonathan/Downloads/openshot-testing/sintel_trailer-720p.mp4";
FFmpegReader r(path);
r.Open();
const long int total_frames = r.info.video_length;
// --- Measure forward pass ---
auto t0 = std::chrono::high_resolution_clock::now();
for (long int frame = 1; frame <= total_frames; frame++) {
float percent = (float(frame) / total_frames) * 100.0f;
std::cout << "Forward: Requesting Frame #: " << frame
<< " (" << percent << "%)\n";
std::shared_ptr<Frame> f = r.GetFrame(frame);
// (optional) preview or process f here
}
auto t1 = std::chrono::high_resolution_clock::now();
auto forward_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
// --- Measure backward pass ---
auto t2 = std::chrono::high_resolution_clock::now();
for (long int frame = total_frames; frame >= 1; frame--) {
float percent = (float(total_frames - frame + 1) / total_frames) * 100.0f;
std::cout << "Backward: Requesting Frame #: " << frame
<< " (" << percent << "%)\n";
std::shared_ptr<Frame> f = r.GetFrame(frame);
// (optional) preview or process f here
}
auto t3 = std::chrono::high_resolution_clock::now();
auto backward_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t2).count();
std::cout << "\nForward pass elapsed: " << forward_ms << " ms\n";
std::cout << "Backward pass elapsed: " << backward_ms << " ms\n";
r.Close();
return 0;
}