diff --git a/include/FileWriterBase.h b/include/FileWriterBase.h new file mode 100644 index 00000000..7d795be7 --- /dev/null +++ b/include/FileWriterBase.h @@ -0,0 +1,79 @@ +#ifndef OPENSHOT_FILE_WRITER_BASE_H +#define OPENSHOT_FILE_WRITER_BASE_H + +/** + * \file + * \brief Header file for FileWriterBase class + * \author Copyright (c) 2011 Jonathan Thomas + */ + +#include +#include +#include "Fraction.h" +#include "Frame.h" + +using namespace std; + +namespace openshot +{ + /** + * \brief This struct contains info about encoding a media file, such as height, width, frames per second, etc... + * + * Each derived class of FileWriterBase is responsible for updating this struct to reflect accurate information + * about the streams. + */ + struct WriterInfo + { + bool has_video; ///< Determines if this file has a video stream + bool has_audio; ///< Determines if this file has an audio stream + float duration; ///< Length of time (in seconds) + int file_size; ///< Size of file (in bytes) + int height; ///< The height of the video (in pixels) + int width; ///< The width of the video (in pixesl) + int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...) + Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps) + int video_bit_rate; ///< The bit rate of the video stream (in bytes) + Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) + Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) + string vcodec; ///< The name of the video codec used to encode / decode the video stream + long int video_length; ///< The number of frames in the video stream + int video_stream_index; ///< The index of the video stream + Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen + bool interlaced_frame; // Are the contents of this frame interlaced + bool top_field_first; // Which interlaced field should be displayed first + string acodec; ///< The name of the audio codec used to encode / decode the video stream + int audio_bit_rate; ///< The bit rate of the audio stream (in bytes) + int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate) + int channels; ///< The number of audio channels used in the audio stream + int audio_stream_index; ///< The index of the audio stream + Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played + }; + + /** + * \brief This abstract class is the base class, used by writers. Writers are types of classes that encode + * video, audio, and image files. + * + * The only requirements for a 'writer', are to derive from this base class, and implement the + * WriteFrame method. + */ + class FileWriterBase + { + public: + /// Information about the current media file + WriterInfo info; + + /// This method is required for all derived classes of FileReaderBase, and return the + /// openshot::Frame object, which contains the image and audio information for that + /// frame of video. + /// + /// @returns The requested frame of video + /// @param[in] number The frame number that is requested. + virtual void WriteFrame(Frame frame); + + /// Display file information in the standard output stream (stdout) + void DisplayInfo(); + }; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20e7d38f..ea850e9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,7 @@ add_library(openshot SHARED Coordinate.cpp FFmpegReader.cpp FileReaderBase.cpp + FileWriterBase.cpp Fraction.cpp Frame.cpp FrameMapper.cpp diff --git a/src/FileWriterBase.cpp b/src/FileWriterBase.cpp new file mode 100644 index 00000000..dd442cb1 --- /dev/null +++ b/src/FileWriterBase.cpp @@ -0,0 +1,42 @@ +#include "../include/FileWriterBase.h" + +using namespace openshot; + +// Display file information +void FileWriterBase::DisplayInfo() { + cout << fixed << setprecision(2) << boolalpha; + cout << "----------------------------" << endl; + cout << "----- File Information -----" << endl; + cout << "----------------------------" << endl; + cout << "--> Has Video: " << info.has_video << endl; + cout << "--> Has Audio: " << info.has_audio << endl; + cout << "--> Duration: " << info.duration << " Seconds" << endl; + cout << "--> File Size: " << double(info.file_size) / 1024 / 1024 << " MB" << endl; + cout << "----------------------------" << endl; + cout << "----- Video Attributes -----" << endl; + cout << "----------------------------" << endl; + cout << "--> Width: " << info.width << endl; + cout << "--> Height: " << info.height << endl; + cout << "--> Pixel Format: " << info.pixel_format << endl; + cout << "--> Frames Per Second: " << info.fps.ToDouble() << " (" << info.fps.num << "/" << info.fps.den << ")" << endl; + cout << "--> Video Bit Rate: " << info.video_bit_rate/1000 << " kb/s" << endl; + cout << "--> Pixel Ratio: " << info.pixel_ratio.ToDouble() << " (" << info.pixel_ratio.num << "/" << info.pixel_ratio.den << ")" << endl; + cout << "--> Display Aspect Ratio: " << info.display_ratio.ToDouble() << " (" << info.display_ratio.num << "/" << info.display_ratio.den << ")" << endl; + cout << "--> Video Codec: " << info.vcodec << endl; + cout << "--> Video Length: " << info.video_length << " Frames" << endl; + cout << "--> Video Stream Index: " << info.video_stream_index << endl; + cout << "--> Video Timebase: " << info.video_timebase.ToDouble() << " (" << info.video_timebase.num << "/" << info.video_timebase.den << ")" << endl; + cout << "--> Interlaced: " << info.interlaced_frame << endl; + cout << "--> Interlaced: Top Field First: " << info.top_field_first << endl; + cout << "----------------------------" << endl; + cout << "----- Audio Attributes -----" << endl; + cout << "----------------------------" << endl; + cout << "--> Audio Codec: " << info.acodec << endl; + cout << "--> Audio Bit Rate: " << info.audio_bit_rate/1000 << " kb/s" << endl; + cout << "--> Sample Rate: " << info.sample_rate << " Hz" << endl; + cout << "--> # of Channels: " << info.channels << endl; + cout << "--> Audio Stream Index: " << info.audio_stream_index << endl; + cout << "--> Audio Timebase: " << info.audio_timebase.ToDouble() << " (" << info.audio_timebase.num << "/" << info.audio_timebase.den << ")" << endl; + cout << "----------------------------" << endl; +} + diff --git a/src/Main.cpp b/src/Main.cpp index 301f7f7c..e099672e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -15,8 +15,8 @@ int main() { // openshot::FFmpegReader r("/home/jonathan/Apps/libopenshot/src/examples/test.mp4"); // openshot::FFmpegReader r("/home/jonathan/Apps/libopenshot/src/examples/test1.mp4"); - // openshot::FFmpegReader r("/home/jonathan/Apps/libopenshot/src/examples/piano.wav"); - openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); + openshot::FFmpegReader r("/home/jonathan/apps/libopenshot/src/examples/piano.wav"); + // openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); // openshot::FFmpegReader r("/home/jonathan/Videos/00001.mts"); // openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/piano.wav"); @@ -31,7 +31,7 @@ int main() for (int repeat = 0; repeat <= 10; repeat++) { cout << "----------- REPEAT READER " << repeat << " ---------------" << endl; - for (int frame = 300; frame <= 400; frame++) + for (int frame = 1; frame <= 400; frame++) { Frame f = r.GetFrame(frame); f.Play();