boost::filesystem2::remove(boost::filesystem2::wpath(env::media_folder() + widen(filename))); // Delete the file if it exists\r
\r
graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
- graph_->set_color("write-time", diagnostics::color(0.5f, 0.5f, 0.1f));\r
graph_->set_text(print());\r
diagnostics::register_graph(graph_);\r
\r
~ffmpeg_consumer()\r
{ \r
encode_executor_.stop();\r
- encode_executor_.join();\r
-\r
write_executor_.stop();\r
+ encode_executor_.join();\r
write_executor_.join();\r
\r
LOG_ON_ERROR2(av_write_trailer(oc_.get()), "[ffmpeg_consumer]");\r
});\r
}\r
\r
- std::shared_ptr<AVFrame> convert_video(const safe_ptr<core::read_frame>& frame, AVCodecContext* c)\r
+ std::shared_ptr<AVFrame> convert_video(core::read_frame& frame, AVCodecContext* c)\r
{\r
if(!sws_) \r
{\r
}\r
\r
std::shared_ptr<AVFrame> in_frame(avcodec_alloc_frame(), av_free);\r
- avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()), const_cast<uint8_t*>(frame->image_data().begin()), PIX_FMT_BGRA, format_desc_.width, format_desc_.height);\r
+ avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()), const_cast<uint8_t*>(frame.image_data().begin()), PIX_FMT_BGRA, format_desc_.width, format_desc_.height);\r
\r
std::shared_ptr<AVFrame> out_frame(avcodec_alloc_frame(), av_free);\r
picture_buf_.resize(avpicture_get_size(c->pix_fmt, c->width, c->height));\r
return out_frame;\r
}\r
\r
- std::shared_ptr<AVPacket> encode_video_frame(const safe_ptr<core::read_frame>& frame)\r
+ std::shared_ptr<AVPacket> encode_video_frame(core::read_frame& frame)\r
{ \r
auto c = video_st_->codec;\r
\r
return nullptr;\r
}\r
\r
- byte_vector convert_audio(const safe_ptr<core::read_frame>& frame, AVCodecContext* c)\r
+ byte_vector convert_audio(core::read_frame& frame, AVCodecContext* c)\r
{\r
if(!swr_) \r
swr_.reset(new audio_resampler(c->channels, format_desc_.audio_channels, \r
c->sample_fmt, AV_SAMPLE_FMT_S32));\r
\r
\r
- auto audio_data = frame->audio_data();\r
+ auto audio_data = frame.audio_data();\r
\r
std::vector<int8_t, tbb::cache_aligned_allocator<int8_t>> audio_resample_buffer;\r
std::copy(reinterpret_cast<const uint8_t*>(audio_data.begin()), \r
return byte_vector(audio_resample_buffer.begin(), audio_resample_buffer.end());\r
}\r
\r
- std::shared_ptr<AVPacket> encode_audio_frame(const safe_ptr<core::read_frame>& frame)\r
+ std::shared_ptr<AVPacket> encode_audio_frame(core::read_frame& frame)\r
{ \r
auto c = audio_st_->codec;\r
\r
{ \r
boost::timer frame_timer;\r
\r
- auto video = encode_video_frame(frame);\r
- auto audio = encode_audio_frame(frame);\r
+ auto video = encode_video_frame(*frame);\r
+ auto audio = encode_audio_frame(*frame);\r
\r
graph_->set_value("frame-time", frame_timer.elapsed()*format_desc_.fps*0.5);\r
\r
write_executor_.begin_invoke([=]\r
{\r
- boost::timer write_timer;\r
-\r
if(video)\r
- av_write_frame(oc_.get(), video.get());\r
+ av_interleaved_write_frame(oc_.get(), video.get());\r
if(audio)\r
- av_write_frame(oc_.get(), audio.get());\r
-\r
- graph_->set_value("write-time", write_timer.elapsed()*format_desc_.fps*0.5);\r
+ av_interleaved_write_frame(oc_.get(), audio.get());\r
});\r
});\r
}\r