Repository navigation
Description
Problem Description
Environment
Operating System: Windows (reproducible on a Japanese-language installation, but affects any non-ASCII username).
Software: HandBrake CLI or any part of the library that creates temporary files.
Precondition: The Windows user profile path contains non-ASCII characters. For example: C:\Users\てすと\ (where "てすと" is Japanese for "test").
Problem Description
HandBrake fails to create temporary files (such as two-pass encoding logs) when the path to the system's temporary directory includes non-ASCII characters. The application incorrectly handles the encoding of the path string, leading to a file-open error and preventing operations like two-pass encoding from starting.
Steps to Reproduce
On a Windows machine, create a local user account with a name containing Japanese (or other non-ASCII) characters (e.g., てすと).
Log in as this new user. The user's temporary path will now be something like C:\Users\てすと\AppData\Local\Temp.
Attempt to start a HandBrake process that requires creating a temporary file, for example, the first pass of a two-pass encode.
The process will fail immediately.
Expected Behavior
HandBrake should correctly resolve the path to the temporary directory, handle the non-ASCII characters properly, and successfully create the required temporary files (e.g., ffmpeg.log).
Actual Behavior
The process fails with a file-open error. The error message displays a garbled version of the path and reports error 2 (ENOENT), indicating the system could not find the file/path specified.
encavcodecInit: Failed to open C:/Users/??て??~1/AppData/Local/Temp/HandBrake-27124/ffmpeg.log (reason: unknown error 2)
The garbled path ??て??~1 is a clear symptom of an encoding mismatch.
Root Cause Analysis
The bug is located in the hb_init_temporary_directory function in libhb/ports.c.
Incorrect API Usage: The function currently calls the Windows API GetTempPath. In a MinGW/C environment, this typically resolves to the ANSI version, GetTempPathA.
Encoding Mismatch: On a non-English Windows system (e.g., Japanese), GetTempPathA returns a char* string encoded in the system's active ANSI code page (e.g., Shift-JIS / CP932 for Japanese).
Faulty Assumption: The rest of HandBrake's C code, particularly file I/O wrappers like hb_fopen, correctly assumes that any char* representing a path is UTF-8 encoded.
Failure Point: The Shift-JIS encoded string from GetTempPathA is passed to hb_fopen. Inside hb_fopen, the MultiByteToWideChar(CP_UTF8, ...) call attempts to convert this string as if it were UTF-8. This fails, producing a corrupted UTF-16 path. The underlying _wfopen_s call then fails with an ENOENT (File not found) error because the corrupted path does not exist.
This contrasts with the robust implementation in hb_get_user_config_directory, which correctly uses the wide-character API SHGetFolderPathW and then converts the resulting UTF-16 path to UTF-8.
Proposed Solution
Modify hb_init_temporary_directory in ports.c to correctly handle Unicode paths on Windows, mirroring the approach used elsewhere in the file.
Call the wide-character version of the Windows API, GetTempPathW(), to retrieve the path as a wchar_t* (UTF-16) string, which is the native format for Windows paths.
Use WideCharToMultiByte() with the CP_UTF8 code page to convert the UTF-16 path into a proper UTF-8 encoded char* string.
Use this valid UTF-8 string for all subsequent C-level operations in HandBrake.
This change will ensure that user paths containing any Unicode characters are handled correctly, resolving the bug.
Example Implementation:
C
// In ports.c, inside hb_init_temporary_directory
#if defined( SYS_CYGWIN ) || defined( SYS_MINGW )
wchar_t *wide_base = malloc(MAX_PATH * sizeof(wchar_t));
char *base = malloc(MAX_PATH * 4); // Sufficient buffer for UTF-8
DWORD ret_size = 0;
if (wide_base)
{
// 1. Call the Wide-character API
ret_size = GetTempPathW(MAX_PATH, wide_base);
}
if (ret_size > 0 && ret_size < MAX_PATH && base)
{
// 2. Convert the UTF-16 path to UTF-8
WideCharToMultiByte(CP_UTF8, 0, wide_base, -1, base, MAX_PATH * 4, NULL, NULL);
}
else
{
// Fallback for safety
if (base) strcpy(base, "c:");
}
free(wide_base);
// ... rest of the function proceeds with 'base' containing a valid UTF-8 path ...
// e.g., path = hb_strdup_printf("%s/HandBrake-%d", base, (int)getpid());
// ...
free(base);
#endif
Activity Log, Crash Log or any other details
HandBrake 1.9.2 (2025022300)
OS: Microsoft Windows NT 10.0.19045.0
CPU: AMD Ryzen 5 2400G with Radeon Vega Graphics
Ram: 16331 MB,
GPU Information:
Radeon RX 580 Series - 31.0.21923.1000
Screen: 2560x1440
Temp Dir: C:\Users\さがが\AppData\Local\Temp\
Install Dir: D:\Softwate\
Data Dir: C:\Users\さがが\AppData\Roaming\HandBrake
-------------------------------------------
# Starting Encode ...
[16:44:07] base preset: Fast 1080p30 (Modified)
[16:44:07] Remote Process started with Process ID: 14388 using port: 8037. Max Allowed Instances: 1
[16:44:07] Worker: Starting HandBrake Engine ...
[16:44:07] Worker: Parent Process Id 19628
[16:44:07] Worker: Starting Web Server on port 8037 ...
[16:44:07] Worker: Starting Listener: 1
[16:44:07] Worker: Server Started
[16:44:07] Worker: Disconnected worker monitoring enabled!
[16:44:07] Compile-time hardening features are enabled
Cannot load nvEncodeAPI64.dll
[16:44:07] vcn: is available
[16:44:07] qsv: not available on this system
[16:44:08] hb_init: starting libhb thread
[16:44:08] Starting work at: Fri Jun 27 16:44:08 2025
[16:44:08] 1 job(s) to process
[16:44:08] json job:
{
"Audio": {
"AudioList": [
{
"Bitrate": 160,
"DRC": 0,
"Encoder": "vorbis",
"Gain": 0,
"Mixdown": 4,
"NormalizeMixLevel": false,
"Samplerate": 0,
"Track": 0,
"DitherMethod": 0
}
],
"CopyMask": [
"copy:aac"
],
"FallbackEncoder": "av_aac"
},
"Destination": {
"ChapterList": [
{
"Name": "\u7AE0\u8282 1"
}
],
"ChapterMarkers": true,
"AlignAVStart": false,
"File": "C:\\Users\\\u3055\u304C\u304C\\Videos\\1(2)(3).webm",
"Options": {
"IpodAtom": false,
"Optimize": false
},
"Mux": "av_webm"
},
"Filters": {
"FilterList": [
{
"ID": 6,
"Settings": {
"mode": "7"
}
},
{
"ID": 4,
"Settings": {
"block-height": "16",
"block-thresh": "40",
"block-width": "16",
"filter-mode": "2",
"mode": "3",
"motion-thresh": "1",
"spatial-metric": "2",
"spatial-thresh": "1"
}
},
{
"ID": 20,
"Settings": {
"crop-bottom": "0",
"crop-left": "0",
"crop-right": "0",
"crop-top": "0",
"height": "640",
"width": "960"
}
},
{
"ID": 11,
"Settings": {
"mode": "2",
"rate": "27000000/900000"
}
}
]
},
"PAR": {
"Num": 8,
"Den": 9
},
"Metadata": {},
"SequenceID": 0,
"Source": {
"Angle": 1,
"Range": {
"Type": "chapter",
"Start": 1,
"End": 1
},
"Title": 1,
"Path": "D:\\video\\1(2)(3).mp4",
"HWDecode": 0,
"KeepDuplicateTitles": false
},
"Subtitle": {
"Search": {
"Burn": true,
"Default": false,
"Enable": true,
"Forced": true
},
"SubtitleList": []
},
"Video": {
"Encoder": "VP9",
"Level": "auto",
"MultiPass": true,
"Turbo": true,
"ColorMatrixCode": 0,
"Options": "",
"Preset": "medium",
"Quality": 22,
"QSV": {
"Decode": false
},
"HardwareDecode": 0
}
}
[16:44:08] CPU: Unknown
[16:44:08] - logical processor count: 8
[16:44:08] Intel Quick Sync Video support: no
[16:44:08] hb_scan: path=D:\video\1(2)(3).mp4, title_index=1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\video\1(2)(3).mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.3.100
Duration: 00:00:23.07, start: 0.000000, bitrate: 1629 kb/s
Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 960x640 [SAR 8:9 DAR 4:3], 1493 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.3.100 h264_amf
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : Stereo
vendor_id : [0][0][0][0]
[16:44:08] scan: decoding previews for title 1
[16:44:08] scan: audio 0x1: aac, rate=44100Hz, bitrate=129241 English (AAC LC, 2.0 ch, 129 kbps)
[16:44:08] using bitstream PAR 8:9
[16:44:08] scan: 10 previews, 960x640, 30.000 fps, autocrop = 0/0/0/0, aspect 4:3, PAR 8:9, color profile: 1-1-1, chroma location: left
[16:44:08] libhb: scan thread found 1 valid title(s)
[16:44:08] Skipping subtitle scan. No suitable subtitle tracks.
[16:44:08] Starting Task: Analysis Pass
[16:44:08] work: skipping crop/scale filter
[16:44:08] work: track 1, dithering not supported by codec
[16:44:08] work: only 1 chapter, disabling chapter markers
[16:44:08] job configuration:
[16:44:08] * source
[16:44:08] + D:\video\1(2)(3).mp4
[16:44:08] + title 1, chapter(s) 1 to 1
[16:44:08] + container: mov,mp4,m4a,3gp,3g2,mj2
[16:44:08] + data rate: 1629 kbps
[16:44:08] * destination
[16:44:08] + C:\Users\さがが\Videos\1(2)(3).webm
[16:44:08] + container: WebM (libavformat)
[16:44:08] * video track
[16:44:08] + decoder: h264 8-bit (yuv420p)
[16:44:08] + bitrate 1493 kbps
[16:44:08] + filters
[16:44:08] + Comb Detect (mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16)
[16:44:08] + Decomb (mode=39)
[16:44:08] + Framerate Shaper (mode=2:rate=27000000/900000)
[16:44:08] + frame rate: 30.000 fps -> peak rate limited to 30.000 fps
[16:44:08] + Output geometry
[16:44:08] + storage dimensions: 960 x 640
[16:44:08] + pixel aspect ratio: 8 : 9
[16:44:08] + display dimensions: 853 x 640
[16:44:08] + encoder: VP9 (libvpx)
[16:44:08] + preset: medium
[16:44:08] + quality: 22.00 (CQ)
[16:44:08] + color profile: 1-1-1
[16:44:08] + color range: tv
[16:44:08] + chroma location: left
[16:44:08] * audio track 1
[16:44:08] + decoder: English (AAC LC, 2.0 ch, 129 kbps) (track 1, id 0x1)
[16:44:08] + bitrate: 129 kbps, samplerate: 44100 Hz
[16:44:08] + mixdown: Stereo
[16:44:08] + encoder: Vorbis (libvorbis)
[16:44:08] + bitrate: 160 kbps, samplerate: 44100 Hz
[16:44:08] sync: expecting 692 video frames
[16:44:08] encvorbis: opening libvorbis
[16:44:08] encavcodecInit: VP9 encoder
[16:44:08] encavcodec: encoding at CQ 22.00
[16:44:08] encavcodec: encoding with stored aspect 8/9
encavcodecInit: Failed to open C:/Users/さがが/AppData/Local/Temp/HandBrake-14388/ffmpeg.log (reason: unknown error 2)
Failure to initialise thread 'FFMPEG encoder (libavcodec)'
[16:44:08] comb detect: heavy 0 | light 0 | uncombed 0 | total 0
[16:44:08] vfr: 0 frames output, 0 dropped and 0 duped for CFR/PFR
[16:44:08] vfr: lost time: 0 (0 frames)
[16:44:08] vfr: gained time: 0 (0 frames) (0 not accounted for)
[16:44:08] aac-decoder done: 0 frames, 0 decoder errors
[16:44:08] h264-decoder done: 0 frames, 0 decoder errors
[16:44:08] sync: got 0 frames, 692 expected
[16:44:08] Finished work at: Fri Jun 27 16:44:08 2025
[16:44:08] libhb: work result = 3
# Job Failed to Initialise. Check log and input settings (3)
What Operating System are you running?
windows 10
What version of HandBrake are you running?
1.9.2
Where did you download HandBrake from?
github
Activity
github-actions commentedon Jun 27, 2025
Hello,
Welcome to the HandBrake repository.
Warning
Please be cautious of any non-members suggesting that you download a "DLL" or any other files from 3rd party websites.
These are likely malicious!
Members of the HandBrake team can be identified by the "(Member)" label in the top right of any response from them.
Tip
For HandBrake documentation, please see https://handbrake.fr/docs
Thank You,
The HandBrake Bot
ports: handle temporary files path with non-ASCII characters on Windows
ports: handle temporary files path with non-ASCII characters on Windows
ports: handle temporary files path with non-ASCII characters on Windows
galad87 commentedon Jun 28, 2025
Try #6999
438853439 commentedon Jun 30, 2025
Hi @galad87,
It's fixed in #6999. I've tested it and can confirm everything is working normally now.
This issue can be closed. Thanks again!
ports: handle temporary files path with non-ASCII characters on Windo…