2323#define popen _popen
2424#define pclose _pclose
2525#define mkdir(path, mode) _mkdir(path)
26+ #define SAM3_NULL_DEV "NUL"
27+ #define SAM3_POPEN_READ "rb"
2628#else
2729#include <sys/stat.h>
30+ #define SAM3_NULL_DEV "/dev/null"
31+ #define SAM3_POPEN_READ "r"
2832#endif
2933
3034/* C++ standard library */
@@ -12289,16 +12293,16 @@ sam3_image sam3_decode_video_frame(const std::string& video_path, int frame_inde
1228912293 snprintf(cmd, sizeof(cmd),
1229012294 "ffmpeg -nostdin -loglevel error -i \"%s\" "
1229112295 "-vf \"select=eq(n\\,%d)\" -vsync vfr -frames:v 1 "
12292- "-f rawvideo -pix_fmt rgb24 pipe:1 2>/dev/null ",
12293- video_path.c_str(), frame_index);
12296+ "-f rawvideo -pix_fmt rgb24 pipe:1 2>%s ",
12297+ video_path.c_str(), frame_index, SAM3_NULL_DEV );
1229412298
1229512299 // First, get dimensions
1229612300 char info_cmd[1024];
1229712301 snprintf(info_cmd, sizeof(info_cmd),
1229812302 "ffprobe -v error -select_streams v:0 "
12299- "-show_entries stream=width,height -of csv=p=0 \"%s\" 2>/dev/null ",
12300- video_path.c_str());
12301- FILE* fp = popen(info_cmd, "r" );
12303+ "-show_entries stream=width,height -of csv=p=0 \"%s\" 2>%s ",
12304+ video_path.c_str(), SAM3_NULL_DEV );
12305+ FILE* fp = popen(info_cmd, SAM3_POPEN_READ );
1230212306 if (!fp) return img;
1230312307 int w = 0, h = 0;
1230412308 if (fscanf(fp, "%d,%d", &w, &h) != 2) {
@@ -12312,7 +12316,7 @@ sam3_image sam3_decode_video_frame(const std::string& video_path, int frame_inde
1231212316 img.channels = 3;
1231312317 img.data.resize(w * h * 3);
1231412318
12315- fp = popen(cmd, "r" );
12319+ fp = popen(cmd, SAM3_POPEN_READ );
1231612320 if (!fp) {
1231712321 img.data.clear();
1231812322 return img;
@@ -12333,9 +12337,9 @@ sam3_video_info sam3_get_video_info(const std::string& video_path) {
1233312337 snprintf(cmd, sizeof(cmd),
1233412338 "ffprobe -v error -select_streams v:0 "
1233512339 "-show_entries stream=width,height,r_frame_rate,nb_frames "
12336- "-of csv=p=0 \"%s\" 2>/dev/null ",
12337- video_path.c_str());
12338- FILE* fp = popen(cmd, "r" );
12340+ "-of csv=p=0 \"%s\" 2>%s ",
12341+ video_path.c_str(), SAM3_NULL_DEV );
12342+ FILE* fp = popen(cmd, SAM3_POPEN_READ );
1233912343 if (!fp) return info;
1234012344
1234112345 int w = 0, h = 0, num = 0, den = 1, nf = 0;
0 commit comments