Skip to content

Commit ea11a55

Browse files
committed
Fix psychedelic ffmpeg pipe on Windows
1 parent cca1063 commit ea11a55

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

examples/psychedelic/Psychedelic.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
#include <streambuf>
1111
#include <string>
1212

13+
#ifdef _WIN32
14+
#define OPENMOQ_POPEN _popen
15+
#define OPENMOQ_PCLOSE _pclose
16+
#define OPENMOQ_POPEN_READ_MODE "rb"
17+
#else
18+
#define OPENMOQ_POPEN popen
19+
#define OPENMOQ_PCLOSE pclose
20+
#define OPENMOQ_POPEN_READ_MODE "r"
21+
#endif
22+
1323
namespace {
1424

1525
class PopenStreamBuf final : public std::streambuf {
@@ -195,11 +205,11 @@ int main(int argc, char** argv) {
195205

196206
const std::string ffmpeg_cmd = build_ffmpeg_video_command(args.seconds);
197207
std::cerr << "[psychedelic] launching ffmpeg: " << ffmpeg_cmd << '\n';
198-
FILE* ffmpeg_pipe = popen(ffmpeg_cmd.c_str(), "r");
208+
FILE* ffmpeg_pipe = OPENMOQ_POPEN(ffmpeg_cmd.c_str(), OPENMOQ_POPEN_READ_MODE);
199209
if (ffmpeg_pipe == nullptr) {
200210
throw std::runtime_error("failed to start ffmpeg. Is it installed and in PATH?");
201211
}
202-
const std::unique_ptr<FILE, int (*)(FILE*)> pipe_guard(ffmpeg_pipe, pclose);
212+
const std::unique_ptr<FILE, int (*)(FILE*)> pipe_guard(ffmpeg_pipe, OPENMOQ_PCLOSE);
203213
PopenIStream live_input(pipe_guard.get());
204214

205215
const TransportStatus status = publisher.publish_live(live_input, endpoint, tls, endpoint_alpn_overridden);

0 commit comments

Comments
 (0)