Huge refactor, switched almost all methods to using pointers for Frames, and moved some key method calls outside the critical OMP sections. Also, refactored the sws scaler, to create a pool of 32 scalers, and give each thread it's own scaler. This refactor resulted in a 40%+ increase in speed on the FFmpegReader class.

I also added a cmake build flag for the google perftools library, to assist on profiling performance issues.
This commit is contained in:
Jonathan Thomas
2012-08-15 17:27:14 -05:00
parent 9b6d4dc4a1
commit d1af1b5fef
14 changed files with 239 additions and 173 deletions

View File

@@ -30,7 +30,7 @@ using namespace openshot;
FFmpegWriter::FFmpegWriter(string path) throw (InvalidFile, InvalidFormat, InvalidCodec, InvalidOptions, OutOfMemory) :
path(path), fmt(NULL), oc(NULL), audio_st(NULL), video_st(NULL), audio_pts(0), video_pts(0), samples(NULL),
audio_outbuf(NULL), audio_outbuf_size(0), audio_input_frame_size(0), audio_input_position(0),
converted_audio(NULL), initial_audio_input_frame_size(0), resampler(NULL)
converted_audio(NULL), initial_audio_input_frame_size(0), resampler(NULL), img_convert_ctx(NULL)
{
// Init FileInfo struct (clear all values)
@@ -299,10 +299,10 @@ void FFmpegWriter::WriteFrame(FileReaderBase* reader, int start, int length)
for (int number = start; number <= length; number++)
{
// Get the frame
Frame f = reader->GetFrame(number);
Frame *f = reader->GetFrame(number);
// Encode frame
WriteFrame(&f);
WriteFrame(f);
}
}
@@ -321,6 +321,9 @@ void FFmpegWriter::close_video(AVFormatContext *oc, AVStream *st)
{
avcodec_close(st->codec);
// Deallocate swscontext
sws_freeContext(img_convert_ctx);
//av_free(picture->data[0]);
//av_free(picture);
//if (tmp_picture) {
@@ -747,10 +750,9 @@ void FFmpegWriter::write_video_packet(Frame* frame)
// Resize image and convet pixel format to correct output format (for example: RGB to YUV420P)
SwsContext *img_convert_ctx = NULL;
// Init the software scaler from FFMpeg
img_convert_ctx = sws_getContext(frame->GetWidth(), frame->GetHeight(), PIX_FMT_RGB24, info.width, info.height, c->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
if (!img_convert_ctx)
// Init the software scaler from FFMpeg
img_convert_ctx = sws_getContext(frame->GetWidth(), frame->GetHeight(), PIX_FMT_RGB24, info.width, info.height, c->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
if (img_convert_ctx == NULL)
throw OutOfMemory("Could not allocate SwsContext.", path);
@@ -758,9 +760,6 @@ void FFmpegWriter::write_video_packet(Frame* frame)
sws_scale(img_convert_ctx, frame_source->data, frame_source->linesize, 0,
frame->GetHeight(), frame_final->data, frame_final->linesize);
// Deallocate swscontext
sws_freeContext(img_convert_ctx);
// Encode Picture and Write Frame
int video_outbuf_size = 200000;