Popen for transferring binary data between processes

I am facing the problem of transferring binary data between processes. My program opens a channel for ffmpeg using popen () and tries to capture the output and then pass it as an HTTP server.

I'm doing something like this

ffmpeg -i "input_video.avi" -ab 56 -ar 44100 -b 1500000 -r 25 -s 800x600 -f flv - 

(The output file name "-" converts the output to standard output)

After opening, I use fread () to read the feed.

I can read it and the contents of my program, when I downloaded the file to my browser, it was completed, but the output file does not play !!!

I suspect the pipe is open as a "non-binary" descriptor, since I opened it with popen ("," r "), since" r "in fopen to open a text file.

But I cannot open it with "rb", as I do for fopen (), since "rb" is not acceptable popen ().

How can I solve this problem?

UPDATE:

#define FFMPEG_COMMAND "ffmpeg -i %s -ab 56 -ar 44100 -b 1500000 -r 25 -s 800x600 -f flv -"

Code opening handset

Opening_pipe(filename)
{
    STREAMING_HANDLE *vfp = NULL;
    char command[512] = {  0 };


    vfp = (STREAMING_HANDLE *)malloc(sizeof(STREAMING_HANDLE));
    if(NULL != vfp)
    {
        sprintf(command, FFMPEG_COMMAND, filename);
        vfp->ffmpeg_pipe = popen( command, 
                                  "r" );

        if( NULL == vfp->ffmpeg_pipe )
        {
            free(vfp);
            vfp = NULL;
        }
    }    
    printf("Virt_dir_fopen : vfp => 0x%X\n", vfp);
    return vfp;
}

Code for reading from a pipe

Reading_data_from_pipe(fileHnd, buff, buflen)
{
    STREAMING_HANDLE *vfp = (STREAMING_HANDLE *)fileHnd;
    int ret_code;
    printf("Virt_dir_fread : Asking for %d bytes \n", buflen);
    ret_code =  fread(buf, 1, buflen, vfp->ffmpeg_pipe );
    printf("Virt_dir_fread : Returning %d bytes \n", ret_code);

    return ret_code;
}

Code for closing the pipe (for completeness :))

Closing_pipe(fileHnd)
{
    STREAMING_HANDLE *vfp = (STREAMING_HANDLE *)fileHnd;
    pclose(vfp->ffmpeg_pipe);
    free(vfp);
    return 0;
}

Update-2:

Compared to files

1) File-1 => Obtained by outputting data from ffmpeg

2) File-2 => Obtained directly from ffmpeg using the same configuration

There are differences that I see, 1) File_Duration_field in File-1 is 0, but File-2 has some meaning. 2) File_size_field in File-1 is 0, but File-2 has some value 3) File-1 has an additional 18 bytes at the end that are not in file-2. It appears that the detailed file file_size and file_duration were missing.

, ? ffmpeg file_size , 0 -1 ( , 0 -1).

- flv , . . ???

/ .

,

0
2

. , , .

ffmpeg pipe, , .

, ( MOV), , , .

+1

, Linux - unix. - . "b" . .

fopen manpage:

'' b '' , , . C89 ; "b" POSIX- , Linux. ( -, "b" , I/O , , Unix.)

+3

All Articles