diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 80e547c3..2587eb3c 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -90,6 +90,9 @@ void FFmpegReader::Open() pStream = pFormatCtx->streams[videoStream]; pCodecCtx = pFormatCtx->streams[videoStream]->codec; + // Set number of threads equal to number of processors + 1 + pCodecCtx->thread_count = omp_get_num_procs() + 1; + // Find the decoder for the video stream AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (pCodec == NULL) { @@ -113,6 +116,9 @@ void FFmpegReader::Open() aStream = pFormatCtx->streams[audioStream]; aCodecCtx = pFormatCtx->streams[audioStream]->codec; + // Set number of threads equal to number of processors + 1 + aCodecCtx->thread_count = omp_get_num_procs() + 1; + // Find the decoder for the audio stream AVCodec *aCodec = avcodec_find_decoder(aCodecCtx->codec_id); if (aCodec == NULL) { diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index e5860bb7..128179d7 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -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), - initial_audio_input_frame_size(0), resampler(NULL), img_convert_ctx(NULL), cache_size(12), + initial_audio_input_frame_size(0), resampler(NULL), img_convert_ctx(NULL), cache_size(8), num_of_rescalers(32), rescaler_position(0), video_codec(NULL), audio_codec(NULL), is_writing(false) { @@ -656,6 +656,9 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st) AVCodec *codec; audio_codec = st->codec; + // Set number of threads equal to number of processors + 1 + audio_codec->thread_count = omp_get_num_procs() + 1; + // Find the audio encoder codec = avcodec_find_encoder(audio_codec->codec_id); if (!codec) @@ -704,6 +707,9 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st) AVCodec *codec; video_codec = st->codec; + // Set number of threads equal to number of processors + 1 + video_codec->thread_count = omp_get_num_procs() + 1; + /* find the video encoder */ codec = avcodec_find_encoder(video_codec->codec_id); if (!codec) diff --git a/src/Main.cpp b/src/Main.cpp index 95cbe2d5..2db74a05 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -20,9 +20,9 @@ int main() // openshot::FFmpegReader r("../../src/examples/piano.wav"); // openshot::FFmpegReader r("/home/jonathan/Videos/big-buck-bunny_trailer.webm"); - // openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); + openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); // openshot::FFmpegReader r("/home/jonathan/Videos/OpenShot_Now_In_3d.mp4"); - openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4"); + // openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/piano.wav"); // openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3"); // openshot::FFmpegReader r("/home/jonathan/Documents/OpenShot Art/test.jpeg");