[FFmpeg-devel] [PATCH] avisynth: Make sure the filename passed to avisynth is in the right code page

Motofumi Oka chikuzen.mo at gmail.com
Sat Jun 22 21:14:36 CEST 2013


From: Oka Motofumi <chikuzen.mo at gmail.com>
Date: Fri, 21 Jun 2013 22:57:03 +0900
Subject: [PATCH] avisynth: Make sure the filename passed to avisynth is in
 the right code page

avisynth is a non-unicode application and cannot accept UTF-8
characters. Therefore, the input filename should be converted to
the correct code page that it expects.
---
 libavformat/avisynth.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index a5a4fcc..c2e7920 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -355,11 +355,23 @@ static int avisynth_open_file(AVFormatContext *s) {
     AviSynthContext *avs = (AviSynthContext *)s->priv_data;
     AVS_Value arg, val;
     int ret;
+#ifdef _WIN32
+#define MAX_AVS_PATH_LENGTH 1024
+    char filename_ansi[MAX_AVS_PATH_LENGTH];
+    wchar_t filename_wc[MAX_AVS_PATH_LENGTH];
+#endif

     if (ret = avisynth_context_create(s))
         return ret;

+#ifdef _WIN32
+    // Convert UTF-8 to ANSI code page
+    MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc,
MAX_AVS_PATH_LENGTH);
+    WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
MAX_AVS_PATH_LENGTH, NULL, NULL);
+    arg = avs_new_value_string(filename_ansi);
+#else
     arg = avs_new_value_string(s->filename);
+#endif
     val = avs_library->avs_invoke(avs->env, "Import", arg, 0);
     if (avs_is_error(val)) {
         av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val));

-- 
1.7.11.msysgit.1


2013/6/23 Derek Buitenhuis <derek.buitenhuis at gmail.com>

> On 2013-06-21 10:07 AM, Motofumi Oka wrote:
> > avisynth is a non-unicode application and cannot accept UTF-8
> > characters. Therefore, the input filename should be converted to
> > the correct code page that it expects.
> > ---
> >  libavformat/avisynth.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
>
> Gotta love Avisynth. Feels pretty stupid to have WIN32 ifdefs
> in Avisynth code, but I guess there's that one guy in existence
> who cares about Avxsynth...
>
>
> > +#ifdef _WIN32
> > +#define MAX_AVS_PATH_LENGTH 1024
> > +    char filename[MAX_AVS_PATH_LENGTH];
> > +    wchar_t filename_wc[MAX_AVS_PATH_LENGTH];
> > +#endif
>
> Where does this max length come from?
>
> > +#ifdef _WIN32
> > +    // Convert UTF-8 to ASCII code page
> > +    MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc,
> MAX_AVS_PATH_LENGTH);
> > +    WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename,
> MAX_AVS_PATH_LENGTH, NULL, NULL);
>
> Is it worth it to check the return values here? (I'm guessing
> probably not.)
>
> > +    arg = avs_new_value_string(filename);
>
> Perhaps call it filename_ansi?
>
> Otherwise, seems OK.
>
> - Derek
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list