简体   繁体   English

将ffmpeg管道重定向到子进程

[英]Redirect ffmpeg pipe to child process

How can I redirect a ffmpeg pipe from a process to the child process stdin? 如何将ffmpeg管道从进程重定向到子进程stdin?

I want to achieve the same thing as piping in cmd: 我想实现与cmd中的管道相同的操作:

ffmpeg -i test.mov pipe:1 | vlc -

I tried: 我试过了:

avio_open("pipe:1"); // ffmpeg open pipe to STD_OUTPUT_HANDLE.

// lots of code

STARTUPINFO si;
PROCESS_INFORMATION pi;

SECURITY_ATTRIBUTES saAttr = {0}; 
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
saAttr.bInheritHandle = TRUE; 
saAttr.lpSecurityDescriptor = NULL; 

CreatePipe(&hReadPipe, &hWritePipe, &saAttr, 0);

SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe);

ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));

si.cb = sizeof(si);
si.dwFlags   = STARTF_USESTDHANDLES;
si.hStdInput = hReadPipe;   

CreateProcess(NULL,   // No module name (use command line)
    L"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc -vv --demux ffmpeg -",        // Command line
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    TRUE,          // Set handle inheritance to FALSE
    0,              // No creation flags
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &si,            // Pointer to STARTUPINFO structure
    &pi )           // Pointer to PROCESS_INFORMATION structure

// start ffmpeg write to file.

But I honestly don't know what I'm doing. 但老实说,我不知道自己在做什么。

Is there any GetStdHandle that doesn't normally print to the console? 是否有通常无法打印到控制台的任何GetStdHandle

You can try creating a pipe: 您可以尝试创建管道:

  1. Call CreatePipe() to create a read handle and a write handle 调用CreatePipe()创建读取句柄和写入句柄

  2. Call SetStdHandle() to make the write handle of the pipe your new stdout 调用SetStdHandle()使管道的写句柄成为新的stdout

  3. Specify the read handle of the pipe as hStdInput to CreateProcess() 将管道的读取句柄指定为CreateProcess()的hStdInput

Update: 更新:

if your application uses printf() to print to the STD output console, you will probably need to hack into the stdout struct and replace the handle there. 如果您的应用程序使用printf()打印到STD输出控制台,则可能需要侵入stdout结构并替换其中的句柄。 In any case, try stepping into a printf() call that does not redirected correctly and see which handle it uses in the end. 无论如何,请尝试进入不会正确重定向的printf()调用,并查看其最终使用哪个句柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM