OpenShot Library | libopenshot  0.2.2
Example.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for Example Executable (example app for libopenshot)
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #include <fstream>
29 #include <iostream>
30 #include <memory>
31 #include "../../include/OpenShot.h"
32 #include "../../include/CrashHandler.h"
33 
34 using namespace openshot;
35 
36 
37 int main(int argc, char* argv[]) {
38 
39  FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-720p.mp4");
40  r9.Open();
41  r9.DisplayInfo();
42 
43  /* WRITER ---------------- */
44  FFmpegWriter w9("/home/jonathan/metadata.mp4");
45 
46  // Set options
47  w9.SetAudioOptions(true, "libmp3lame", r9.info.sample_rate, r9.info.channels, r9.info.channel_layout, 128000);
48  w9.SetVideoOptions(true, "libx264", r9.info.fps, 1024, 576, Fraction(1,1), false, false, 3000000);
49 
50  w9.info.metadata["title"] = "testtest";
51  w9.info.metadata["artist"] = "aaa";
52  w9.info.metadata["album"] = "bbb";
53  w9.info.metadata["year"] = "2015";
54  w9.info.metadata["description"] = "ddd";
55  w9.info.metadata["comment"] = "eee";
56  w9.info.metadata["comment"] = "comment";
57  w9.info.metadata["copyright"] = "copyright OpenShot!";
58 
59  // Open writer
60  w9.Open();
61 
62  for (long int frame = 1; frame <= 100; frame++)
63  {
64  //int frame_number = (rand() % 750) + 1;
65  int frame_number = frame;
66  std::shared_ptr<Frame> f = r9.GetFrame(frame_number);
67  w9.WriteFrame(f);
68  }
69 
70  // Close writer & reader
71  w9.Close();
72 
73  // Close timeline
74  r9.Close();
75 
76  cout << "Completed successfully!" << endl;
77 
78  return 0;
79 }
WriterInfo info
Information about the current media file.
Definition: WriterBase.h:93
ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition: ReaderBase.h:83
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
std::map< string, string > metadata
An optional map/dictionary of video & audio metadata.
Definition: WriterBase.h:76
This class uses the FFmpeg libraries, to write and encode video files and audio files.
Definition: FFmpegWriter.h:143
int main(int argc, char *argv[])
Definition: Example.cpp:37
void Close()
Close File.
void WriteFrame(std::shared_ptr< Frame > frame)
Add a frame to the stack waiting to be encoded.
void Open()
Open writer.
void SetVideoOptions(bool has_video, string codec, Fraction fps, int width, int height, Fraction pixel_ratio, bool interlaced, bool top_field_first, int bit_rate)
Set video export options.
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
Definition: FFmpegReader.h:92
This class represents a fraction.
Definition: Fraction.h:42
void Close()
Close the writer.
ReaderInfo info
Information about the current media file.
Definition: ReaderBase.h:112
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: ReaderBase.h:69
This namespace is the default namespace for all code in the openshot library.
void Open()
Open File - which is called by the constructor automatically.
void SetAudioOptions(bool has_audio, string codec, int sample_rate, int channels, ChannelLayout channel_layout, int bit_rate)
Set audio export options.
void DisplayInfo()
Display file information in the standard output stream (stdout)
Definition: ReaderBase.cpp:66
int channels
The number of audio channels used in the audio stream.
Definition: ReaderBase.h:82
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition: ReaderBase.h:81