From e73b0255332cb9edab1682402b131d8d877f7793 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 12 May 2016 20:20:49 -0700 Subject: [PATCH] obs-ffmpeg: Fix ffmpeg-mux unicode file saving (win32) On windows, if you were saving a file name or directory with characters that are not of the current windows character set, it could cause the file saving process to fail. This fixes it so that on windows it uses wmain and converts the unicode command line to a UTF-8 command line, which works with FFmpeg. --- plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c index 74bb1f4fd..576daf826 100644 --- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c +++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c @@ -17,6 +17,7 @@ #ifdef _WIN32 #include #include +#include #define inline __inline #endif @@ -629,7 +630,11 @@ static inline bool ffmpeg_mux_packet(struct ffmpeg_mux *ffm, uint8_t *buf, /* ------------------------------------------------------------------------- */ +#ifdef _WIN32 +int wmain(int argc, wchar_t *argv_w[]) +#else int main(int argc, char *argv[]) +#endif { struct ffm_packet_info info = {0}; struct ffmpeg_mux ffm = {0}; @@ -638,6 +643,21 @@ int main(int argc, char *argv[]) int ret; #ifdef _WIN32 + char **argv; + + argv = malloc(argc * sizeof(char*)); + for (int i = 0; i < argc; i++) { + size_t len = wcslen(argv_w[i]); + int size; + + size = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], len, NULL, 0, + NULL, NULL); + argv[i] = malloc(size + 1); + WideCharToMultiByte(CP_UTF8, 0, argv_w[i], len, argv[i], + size + 1, NULL, NULL); + argv[i][size] = 0; + } + _setmode(_fileno(stdin), O_BINARY); #endif setvbuf(stderr, NULL, _IONBF, 0); @@ -660,5 +680,11 @@ int main(int argc, char *argv[]) ffmpeg_mux_free(&ffm); resize_buf_free(&rb); + +#ifdef _WIN32 + for (int i = 0; i < argc; i++) + free(argv[i]); + free(argv); +#endif return 0; } -- GitLab