2013-09-12 23:41:49 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
2015-02-07 16:48:43 -06:00
|
|
|
* @brief Source file for Example Executable (example app for libopenshot)
|
2013-09-12 23:41:49 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2025-06-04 17:19:01 -05:00
|
|
|
#include <chrono>
|
2011-10-11 08:44:27 -05:00
|
|
|
#include <iostream>
|
2017-08-20 17:37:39 -05:00
|
|
|
#include <memory>
|
2021-03-31 19:35:58 -04:00
|
|
|
#include "Frame.h"
|
|
|
|
|
#include "FFmpegReader.h"
|
2025-06-05 19:38:53 -05:00
|
|
|
#include "FFmpegWriter.h"
|
2013-11-17 15:12:08 -06:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
using namespace openshot;
|
|
|
|
|
|
2017-08-01 01:19:07 -05:00
|
|
|
int main(int argc, char* argv[]) {
|
2025-06-04 17:19:01 -05:00
|
|
|
// Path to your video
|
|
|
|
|
const char* path = "/home/jonathan/Downloads/openshot-testing/sintel_trailer-720p.mp4";
|
Improved Profile Class (Helper methods, Sortable, Unit tests) (#895)
* Removing legacy profile property. Add new operators for Profile classes (for comparison). Also added new functions to generate different variations of the Profile data (key, short name, long name, long name w/description).
* Add empty constructor for Profile class, and new Profile unit tets
* Adding zero padding to profile Key function, for easier sorting: 01920x1080i2997_16:09
* Clear setfill flag after creating Key() output
* Updating example exe to load an *.osp project file via C++, which makes debugging complex broken projects much easier.
* - Add new unit test to FFmpegWriter to create an animated GIF and verify it can be wrapped with a FrameMapper (with no audio track)
- Improve FrameMapper to ignore missing audio data (i.e. when no audio samples present, don't try and find them or resample them)
* Fix some whitespace issues
* Fix inline documentation mistype
* Fixed missing reuse licensing on new example profile files
* Changing Profile::Key() format to exclude the : character, since Windows file names cannot contain that
* - Large memory leak fixed in FFmpegWriter when closing the video & audio contexts
- Reducing # of cached frames and rescalers to 1, since we no longer use OMP and this is unneeded - we need to refactor much of this code out eventually
* - Fixing whitespace issues
- Code clean-up / line wrapping / etc...
2023-02-02 16:29:38 -06:00
|
|
|
|
2025-06-04 17:19:01 -05:00
|
|
|
FFmpegReader r(path);
|
Improved Profile Class (Helper methods, Sortable, Unit tests) (#895)
* Removing legacy profile property. Add new operators for Profile classes (for comparison). Also added new functions to generate different variations of the Profile data (key, short name, long name, long name w/description).
* Add empty constructor for Profile class, and new Profile unit tets
* Adding zero padding to profile Key function, for easier sorting: 01920x1080i2997_16:09
* Clear setfill flag after creating Key() output
* Updating example exe to load an *.osp project file via C++, which makes debugging complex broken projects much easier.
* - Add new unit test to FFmpegWriter to create an animated GIF and verify it can be wrapped with a FrameMapper (with no audio track)
- Improve FrameMapper to ignore missing audio data (i.e. when no audio samples present, don't try and find them or resample them)
* Fix some whitespace issues
* Fix inline documentation mistype
* Fixed missing reuse licensing on new example profile files
* Changing Profile::Key() format to exclude the : character, since Windows file names cannot contain that
* - Large memory leak fixed in FFmpegWriter when closing the video & audio contexts
- Reducing # of cached frames and rescalers to 1, since we no longer use OMP and this is unneeded - we need to refactor much of this code out eventually
* - Fixing whitespace issues
- Code clean-up / line wrapping / etc...
2023-02-02 16:29:38 -06:00
|
|
|
r.Open();
|
|
|
|
|
|
2025-06-04 17:19:01 -05:00
|
|
|
const long int total_frames = r.info.video_length;
|
Improved Profile Class (Helper methods, Sortable, Unit tests) (#895)
* Removing legacy profile property. Add new operators for Profile classes (for comparison). Also added new functions to generate different variations of the Profile data (key, short name, long name, long name w/description).
* Add empty constructor for Profile class, and new Profile unit tets
* Adding zero padding to profile Key function, for easier sorting: 01920x1080i2997_16:09
* Clear setfill flag after creating Key() output
* Updating example exe to load an *.osp project file via C++, which makes debugging complex broken projects much easier.
* - Add new unit test to FFmpegWriter to create an animated GIF and verify it can be wrapped with a FrameMapper (with no audio track)
- Improve FrameMapper to ignore missing audio data (i.e. when no audio samples present, don't try and find them or resample them)
* Fix some whitespace issues
* Fix inline documentation mistype
* Fixed missing reuse licensing on new example profile files
* Changing Profile::Key() format to exclude the : character, since Windows file names cannot contain that
* - Large memory leak fixed in FFmpegWriter when closing the video & audio contexts
- Reducing # of cached frames and rescalers to 1, since we no longer use OMP and this is unneeded - we need to refactor much of this code out eventually
* - Fixing whitespace issues
- Code clean-up / line wrapping / etc...
2023-02-02 16:29:38 -06:00
|
|
|
|
2025-06-05 19:38:53 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
|
2025-06-04 17:19:01 -05:00
|
|
|
// --- 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";
|
Improved Profile Class (Helper methods, Sortable, Unit tests) (#895)
* Removing legacy profile property. Add new operators for Profile classes (for comparison). Also added new functions to generate different variations of the Profile data (key, short name, long name, long name w/description).
* Add empty constructor for Profile class, and new Profile unit tets
* Adding zero padding to profile Key function, for easier sorting: 01920x1080i2997_16:09
* Clear setfill flag after creating Key() output
* Updating example exe to load an *.osp project file via C++, which makes debugging complex broken projects much easier.
* - Add new unit test to FFmpegWriter to create an animated GIF and verify it can be wrapped with a FrameMapper (with no audio track)
- Improve FrameMapper to ignore missing audio data (i.e. when no audio samples present, don't try and find them or resample them)
* Fix some whitespace issues
* Fix inline documentation mistype
* Fixed missing reuse licensing on new example profile files
* Changing Profile::Key() format to exclude the : character, since Windows file names cannot contain that
* - Large memory leak fixed in FFmpegWriter when closing the video & audio contexts
- Reducing # of cached frames and rescalers to 1, since we no longer use OMP and this is unneeded - we need to refactor much of this code out eventually
* - Fixing whitespace issues
- Code clean-up / line wrapping / etc...
2023-02-02 16:29:38 -06:00
|
|
|
std::shared_ptr<Frame> f = r.GetFrame(frame);
|
2025-06-05 19:38:53 -05:00
|
|
|
w.WriteFrame(f);
|
Improved Profile Class (Helper methods, Sortable, Unit tests) (#895)
* Removing legacy profile property. Add new operators for Profile classes (for comparison). Also added new functions to generate different variations of the Profile data (key, short name, long name, long name w/description).
* Add empty constructor for Profile class, and new Profile unit tets
* Adding zero padding to profile Key function, for easier sorting: 01920x1080i2997_16:09
* Clear setfill flag after creating Key() output
* Updating example exe to load an *.osp project file via C++, which makes debugging complex broken projects much easier.
* - Add new unit test to FFmpegWriter to create an animated GIF and verify it can be wrapped with a FrameMapper (with no audio track)
- Improve FrameMapper to ignore missing audio data (i.e. when no audio samples present, don't try and find them or resample them)
* Fix some whitespace issues
* Fix inline documentation mistype
* Fixed missing reuse licensing on new example profile files
* Changing Profile::Key() format to exclude the : character, since Windows file names cannot contain that
* - Large memory leak fixed in FFmpegWriter when closing the video & audio contexts
- Reducing # of cached frames and rescalers to 1, since we no longer use OMP and this is unneeded - we need to refactor much of this code out eventually
* - Fixing whitespace issues
- Code clean-up / line wrapping / etc...
2023-02-02 16:29:38 -06:00
|
|
|
}
|
2025-06-04 17:19:01 -05:00
|
|
|
auto t1 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
auto forward_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
|
2018-03-04 03:10:59 -06:00
|
|
|
|
2025-06-04 17:19:01 -05:00
|
|
|
// --- 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);
|
2025-06-05 19:38:53 -05:00
|
|
|
w.WriteFrame(f);
|
2025-06-04 17:19:01 -05:00
|
|
|
}
|
|
|
|
|
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();
|
2025-06-05 19:38:53 -05:00
|
|
|
w.Close();
|
2025-06-04 17:19:01 -05:00
|
|
|
return 0;
|
2019-08-05 02:54:59 -04:00
|
|
|
}
|