I need to open FFMPEG pipe and write frames data to that pipe. I am using this code:
#ifdef _WIN32#define POPEN _popen#define PCLOSE _pclose#else#define POPEN popen#define PCLOSE pclose#endif// FFmpeg command to receive raw BGR24 data and encode with libx264std::ostringstream oss;oss << "ffmpeg -y -f rawvideo -pixel_format bgr24 "<< "-video_size " << width << "x" << height << " "<< "-framerate " << fps << " -i - "<< "-c:v libx264 -preset ultrafast "<< "" << video_path << "";std::string cmd = oss.str(); #ifdef _WIN32auto mode = "wb";#elseauto mode = "w";#endifpipe_ = POPEN(cmd.c_str(), mode);if (!pipe_) { throw std::runtime_error("[FFmpegWriter::FFmpegWriter] FFmpeg pipe could not be oppnened");}The writing (in loop) looks like:
size_t written = fwrite(img.data, 1, img.total() * img.elemSize(), pipe_);This works fine but it is much slower on Ubuntu (while writing frames) than it is on Windows.The wb option does not work on ubuntu and return empty pipe_.What exactly the problem here:
- Why
wbdoes not work on Ubuntu? - if
wis the way to go on Ubuntu, why it is much slower than windows (2-3X)?