0

Is there a way to let ffmpeg read from multiple buffers or multiple named pipes ?

Basically I want to output the first loop to different pipes instead of .jpg files, and run the video filter command using those pipes as input. Right now enormous disk IO is needed to create and read jpg tiles.

// heic -> tiles -> jpeg tiles
#pragma omp parallel for
    for(uint i = 0; i < data.tiles.size(); ++i) {
        char buff[100];
        snprintf(buff, sizeof(buff), "./tmp/%03d.jpg", data.tiles[i].idx);
        std::string cmdStr = "ffmpeg -i - -loglevel warning -frames:v 1 -vsync vfr -an -q:v 1 " + std::string(buff);
        FILE * pipe_in;
        if(pipe_in = popen(cmdStr.c_str(), "w")) {
            fwrite((char*)&data.tiles[i].data[0], 1, data.tiles[i].data.size(), pipe_in);
            fflush(pipe_in);
            fclose(pipe_in);
        }
    }

... some processing

// jpeg tiles -> big jpeg
std::string inputStr = "./tmp/%03d.jpg";
std::string cmdStr = "ffmpeg -i " + inputStr +
        " -loglevel warning -threads 4 -q:v 1 -vf \"tile=" + std::to_string(data.cols) + "x" + std::to_string(data.rows) +
        ",crop=" + std::to_string(data.width) + ":" + std::to_string(data.height) + ":0:0" +
        transStr + "\" -y " + outputStr;
ret = std::system(cmdStr.c_str());
baci
  • 2,528
  • 15
  • 28
  • the ffmpeg command in the loop just reads the first frame of the input , maybe you can do that with the ffmpeg api similar to [this](http://dranger.com/ffmpeg/tutorial01.html). Then maybe you can process them frame by frame – dafnahaktana Aug 13 '17 at 20:29
  • it reads the pipe in the loop, where data is pushed. however the output is pushed to a .jpg file. It should be pushed to other pipe(s) and the filter command (bottom) should input those in theory – baci Aug 13 '17 at 21:10
  • it's a bit of a code but you can still use the ffmpeg api to read from buffers and write to buffers. see answer to [this](https://stackoverflow.com/questions/5237175/process-video-stream-from-memory-buffer) for reading from buffer, and [this](https://stackoverflow.com/questions/30670385/ffmpeg-i-o-output-buffer) and to write the output to buffer , then you can wrtie the output buffer to a pipe – dafnahaktana Aug 14 '17 at 06:03
  • In that case if I use avcodec and buffers, no pipe is needed, however I was looking for a quick solution using the executable – baci Aug 14 '17 at 06:08

0 Answers0