gpt4 book ai didi

c++ - 将 ffmpeg 管道重定向到子进程

转载 作者:太空宇宙 更新时间:2023-11-04 12:10:46 26 4
gpt4 key购买 nike

如何将 ffmpeg 管道从进程重定向到子进程标准输入?

我想在 cmd 中实现与管道相同的功能:

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

我试过:

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.

但老实说,我不知道自己在做什么。

是否有任何 GetStdHandle 通常不会打印到控制台?

最佳答案

您可以尝试创建一个管道:

  1. 调用CreatePipe()创建读句柄和写句柄

  2. 调用SetStdHandle()使管道的写句柄成为新的标准输出

  3. 将管道的读取句柄指定为 CreateProcess() 的 hStdInput

更新:

如果您的应用程序使用 printf() 打印到 STD 输出控制台,您可能需要侵入 stdout 结构并替换那里的句柄。在任何情况下,尝试进入未正确重定向的 printf() 调用,看看它最终使用了哪个句柄。

关于c++ - 将 ffmpeg 管道重定向到子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9966749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com