Files
libopenshot/examples/Example.cpp

78 lines
2.3 KiB
C++
Raw Normal View History

/**
* @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
2011-10-11 08:44:27 -05:00
#include <chrono>
2011-10-11 08:44:27 -05:00
#include <iostream>
#include <memory>
#include "Frame.h"
#include "FFmpegReader.h"
#include "FFmpegWriter.h"
2013-11-17 15:12:08 -06:00
2011-10-11 08:44:27 -05:00
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;
// Reader
std::stringstream writer_path;
writer_path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
/* WRITER ---------------- */
FFmpegWriter w("/home/jonathan/Downloads/performance-test.mp4");
// Set options
w.SetAudioOptions("aac", 48000, 192000);
w.SetVideoOptions("libx264", 1280, 720, Fraction(30,1), 5000000);
// Open writer
w.Open();
// --- 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);
w.WriteFrame(f);
}
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);
w.WriteFrame(f);
}
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();
w.Close();
return 0;
2019-08-05 02:54:59 -04:00
}