Conversion failed! FFMpeg with custom exe in a pipe

Viewed 333

I need to use a batch file with FFmpeg pipe query. I have a set of images (img0.bmp, img1.bmp, img2.bmp) and I need FFmpeg to iterate through them and pass raw data to my custom .exe.

So, the query looks like this

ffmpeg -y -hide_banner -i img%01d.bmp -vf format=gray -f rawvideo pipe: | MY_CUSTOM_EXE

and code of the custom exe is really simple like this

int main()
{
    return 0;
}

The trick of this story is that if I pass to FFmpeg exe just one image like this ... -i img0.bmp ... it works, but if there is a set ... -i img%01d.bmp ..., so I get such an error after the very first interaction:

Input #0, image2, from 'img%01d.bmp':
  Duration: 00:00:00.12, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: bmp, pal8, 4096x3000, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (bmp (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, rawvideo, to 'pipe:':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: rawvideo (Y800 / 0x30303859), gray, 4096x3000, q=2-31, 2457600 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 rawvideo
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument
frame=    1 fps=0.0 q=-0.0 Lsize=   12000kB time=00:00:00.04 bitrate=2457600.0kbits/s speed=0.999x
video:12000kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
Conversion failed!
Press any key to continue . . .

In addition if I use this query like this

ffmpeg -y -hide_banner -i img%01d.bmp -vf format=gray -f rawvideo pipe:

or with other ffmpeg pipe commands

ffmpeg -y -hide_banner -i %input% -vf format=gray -f rawvideo pipe: | ffmpeg -hide_banner -y -framerate 30 ...

it also works perfectly.

So the problem in the MY_CUSTOM_EXE, but what could it be if it has only one line of code?

1 Answers

You must let your program consume the output from ffmpeg otherwise you get the errors you describe.

I tested my hunch and came back with:

av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe

So a simple

#include<iostream>

int main(){
    char c;
    while(std::cin >> c){}  // consume everything the pipe offers
}  // return 0 implied.

Will fix this particular error.

Related