Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ugoira FFMPEG permission denied during conversion #1132

Closed
anon1593 opened this issue Jul 3, 2022 · 20 comments
Closed

Ugoira FFMPEG permission denied during conversion #1132

anon1593 opened this issue Jul 3, 2022 · 20 comments

Comments

@anon1593
Copy link

anon1593 commented Jul 3, 2022

Prerequisites

  • [y] Did you read FAQ section in readme.md?
  • [y ] Did you test with the latest releases or commit ?
  • [ y] Did you search for existing issues in Issues?

Description

Unknown Error, please check the log file: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x00000162F7FE92C0>)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'

Highly random, some download fine, others error.
Experiencing this error for at least a month.

Steps to Reproduce

Download random ugoira and convert

Expected behavior: [What you expected to happen]
Download and convert to gif & webm
Actual behavior: [What actually happened]
Fatal error
Log file: [Attach the pixivutil.log file in the application folder, recommended to delete the old file, reproduce the issue, and upload the newly generated file here]
2022-07-03 13:42:22,945 - PixivUtil20220701 - INFO - ###############################################################
2022-07-03 13:42:22,945 - PixivUtil20220701 - INFO - Starting with argument: [C:\PixivUtil2\PixivUtil2.py].
2022-07-03 13:42:22,945 - PixivUtil20220701 - INFO - Setting log level to: DEBUG
2022-07-03 13:42:22,945 - PixivUtil20220701 - INFO - No default cookie jar available, creating...
2022-07-03 13:42:23,102 - PixivUtil20220701 - INFO - Using default DB Path: C:\PixivUtil2\db.sqlite
2022-07-03 13:42:23,117 - PixivUtil20220701 - INFO - Using Blacklist Tags: 11 items.
2022-07-03 13:42:23,117 - PixivUtil20220701 - INFO - Using Blacklist Members: 7 members.
2022-07-03 13:42:25,439 - PixivUtil20220701 - INFO - Trying to log in with saved cookie
2022-07-03 13:42:26,615 - PixivUtil20220701 - INFO - Logging in, return url: https://www.pixiv.net/en/
2022-07-03 13:42:26,631 - PixivUtil20220701 - INFO - Login successful.
2022-07-03 13:42:26,631 - PixivUtil20220701 - INFO - Logged in using cookie
2022-07-03 13:42:26,631 - PixivUtil20220701 - INFO - My User Id: 8870660.
2022-07-03 13:42:26,631 - PixivUtil20220701 - INFO - Premium User: False.
2022-07-03 13:42:26,631 - PixivUtil20220701 - INFO - Locale = /en
2022-07-03 13:42:26,701 - PixivUtil20220701 - INFO - Using Blacklist Tags: 11 items.
2022-07-03 13:42:26,709 - PixivUtil20220701 - INFO - Using Blacklist Members: 7 members.
2022-07-03 13:42:39,797 - PixivUtil20220701 - INFO - Image id mode (2).
2022-07-03 13:42:41,104 - PixivUtil20220701 - DEBUG - Getting image page: 83158226
2022-07-03 13:42:41,470 - PixivUtil20220701 - DEBUG - New UI Mode
2022-07-03 13:42:42,023 - PixivUtil20220701 - DEBUG - using webrpc: https://www.pixiv.net/rpc/get_work.php?id=83158226
2022-07-03 13:42:43,202 - PixivUtil20220701 - DEBUG - Sanitized Filename: C:\01\wirai (10428223)\83158226_ugoira1920x1080 - Maid suit.zip
2022-07-03 13:42:43,203 - PixivUtil20220701 - INFO - Filename : C:\01\wirai (10428223)\83158226_ugoira1920x1080 - Maid suit.zip
2022-07-03 13:42:43,204 - PixivUtil20220701 - INFO - Creating directory: C:\01\wirai (10428223)
2022-07-03 13:42:43,207 - PixivUtil20220701 - INFO - Using Referer: https://www.pixiv.net/artworks/83158226
2022-07-03 13:42:43,787 - PixivUtil20220701 - INFO - Using Referer: https://www.pixiv.net/artworks/83158226
2022-07-03 13:42:55,743 - PixivUtil20220701 - INFO - done.
2022-07-03 13:42:55,744 - PixivUtil20220701 - INFO - Creating ugoira archive => C:\01\wirai (10428223)\83158226_ugoira1920x1080 - Maid suit.ugoira
2022-07-03 13:42:55,751 - PixivUtil20220701 - INFO - Processing ugoira to animated gif...
2022-07-03 13:42:55,908 - PixivUtil20220701 - DEBUG - Procced to change C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg image for a pixel format with 3 components
2022-07-03 13:42:55,908 - PixivUtil20220701 - INFO - [re_encode_image()] running with cmd: ffmpeg -i C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg -pix_fmt gbrpf32be C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139_temp.jpg
2022-07-03 13:42:55,912 - PixivUtil20220701 - DEBUG - Start re_encoding image C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg
2022-07-03 13:42:56,015 - PixivUtil20220701 - ERROR - Error at process_image(): 83158226
2022-07-03 13:42:56,016 - PixivUtil20220701 - ERROR - Traceback (most recent call last):
File "C:\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'

2022-07-03 13:42:56,018 - PixivUtil20220701 - ERROR - Exception: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x00000162F7FF2AC0>)
2022-07-03 13:42:56,019 - PixivUtil20220701 - ERROR - Traceback (most recent call last):
File "C:\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'

2022-07-03 13:42:56,019 - PixivUtil20220701 - DEBUG - Sanitized Filename: Error medium page for image 83158226.html
2022-07-03 13:42:56,020 - PixivUtil20220701 - ERROR - Dumping html to: Error medium page for image 83158226.html
2022-07-03 13:42:56,021 - PixivUtil20220701 - ERROR - Traceback (most recent call last):
File "C:\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'

2022-07-03 13:42:56,036 - PixivUtil20220701 - ERROR - Unknown Error: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'
Traceback (most recent call last):
File "C:\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\PixivUtil2\PixivUtil2.py", line 1725, in main
np_is_valid, op_is_valid, selection = main_loop(ewd, op_is_valid, selection, np_is_valid, args, options)
File "C:\PixivUtil2\PixivUtil2.py", line 1399, in main_loop
menu_download_by_image_id(op_is_valid, args, options)
File "C:\PixivUtil2\PixivUtil2.py", line 342, in menu_download_by_image_id
PixivImageHandler.process_image(sys.modules[name],
File "C:\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'
2022-07-03 13:42:56,039 - PixivUtil20220701 - ERROR - Unknown Error, please check the log file: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x00000162F7FE92C0>)
2022-07-03 13:42:56,040 - PixivUtil20220701 - ERROR - Traceback (most recent call last):
File "C:\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\PixivUtil2\PixivUtil2.py", line 1725, in main
np_is_valid, op_is_valid, selection = main_loop(ewd, op_is_valid, selection, np_is_valid, args, options)
File "C:\PixivUtil2\PixivUtil2.py", line 1399, in main_loop
menu_download_by_image_id(op_is_valid, args, options)
File "C:\PixivUtil2\PixivUtil2.py", line 342, in menu_download_by_image_id
PixivImageHandler.process_image(sys.modules[name],
File "C:\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirab7yr3559\000139.jpg'

Versions

You can get this information from executing PixivUtil2.py --help.
Latest Commit as of 7/3/2022 1:00PM

@Toyem
Copy link
Contributor

Toyem commented Jul 3, 2022

I can't reproduce the error you have while converting the ugoira to gif. (log.log)
Do you mind sharing the configuration of the [FFmpeg] and [Ugoira] section of the config.ini file to better try to reproduce the error ?

@anon1593
Copy link
Author

anon1593 commented Jul 3, 2022

Sure,

[FFmpeg]
ffmpeg = ffmpeg
ffmpegCodec = libvpx-vp9
ffmpegExt = webm
ffmpegParam = -lossless 1 -vsync 2 -r 999 -pix_fmt yuv420p
webpCodec = libwebp
webpParam = -lossless 0 -q:v 90 -loop 0 -vsync 2 -r 999
gifParam = -filter_complex "[0:v]split[a][b];[a]palettegen=stats_mode=diff[p];[b][p]paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle"
apngParam = -vf "setpts=PTS-STARTPTS,hqdn3d=1.5:1.5:6:6" -plays 0
verboseOutput = True

[Ugoira]
writeUgoiraInfo = False
createUgoira = True
deleteZipFile = True
createGif = True
createApng = False
deleteUgoira = False
createWebm = True
createWebp = False

@Toyem
Copy link
Contributor

Toyem commented Jul 3, 2022

I still can't get the error.
Do you have the complete line with the value of {p.returncode} (it doesn't show up in the log but it should be visible in the console output):
Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.
Does it still happen if you try to download again the ugoira ?

@anon1593
Copy link
Author

anon1593 commented Jul 3, 2022

yes it still happens, here is the output you wanted:
Processing ugoira to animated gif...
ffmpeg version git-2020-08-31-4a11a6f Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.1 (GCC) 20200805
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --enable-libsvtav1 --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 58.100 / 56. 58.100
libavcodec 58.101.101 / 58.101.101
libavformat 58. 51.101 / 58. 51.101
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
C:/Users/1/AppData/Local/Temp/convert_ugoirar2c92h0b000139.jpg: No such file or directory
Traceback (most recent call last):
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\1\Documents\Github\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirar2c92h0b\000139.jpg'
Error at process_image(): 83158226
Exception: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x000001D439E35800>)
Dumping html to: Error medium page for image 83158226.html
Error at process_image(): 83158226
Exception: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x000001D439E35800>)
Dumping html to: Error medium page for image 83158226.html
Traceback (most recent call last):
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1053, in convert_ugoira
check_image_encoding(d)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1162, in check_image_encoding
re_encode_image(re_encode_channel, file)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1193, in re_encode_image
raise PixivException("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.", errorCode=PixivException.OTHER_ERROR)
PixivException.PixivException: PixivException(9999 error, hasDumpPage=N)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\1\Documents\Github\PixivUtil2\PixivUtil2.py", line 1725, in main
np_is_valid, op_is_valid, selection = main_loop(ewd, op_is_valid, selection, np_is_valid, args, options)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivUtil2.py", line 1399, in main_loop
menu_download_by_image_id(op_is_valid, args, options)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivUtil2.py", line 342, in menu_download_by_image_id
PixivImageHandler.process_image(sys.modules[name],
File "C:\Users\1\Documents\Github\PixivUtil2\PixivImageHandler.py", line 336, in process_image
PixivDownloadHandler.handle_ugoira(image, filename, config, notifier)
File "C:\Users\1\Documents\Github\PixivUtil2\PixivDownloadHandler.py", line 384, in handle_ugoira
PixivHelper.ugoira2gif(ugo_name,
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 967, in ugoira2gif
convert_ugoira(ugoira_file,
File "C:\Users\1\Documents\Github\PixivUtil2\PixivHelper.py", line 1080, in convert_ugoira
shutil.rmtree(d)
File "C:\Python310\lib\shutil.py", line 739, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/1/AppData/Local/Temp/convert_ugoirar2c92h0b\000139.jpg'
Unknown Error, please check the log file: (<class 'PermissionError'>, PermissionError(13, 'The process cannot access the file because it is being used by another process'), <traceback object at 0x000001D439C1EC00>)
press enter to exit.

@Toyem
Copy link
Contributor

Toyem commented Jul 3, 2022

Ok, since I can't reproduce the error on my laptop, I'm gonna ask you to do mess around a little with your code.
First can you type this command on your terminal and give me the result of the command:
pip show PIL

Then, can you modify lines 1146 and 1147 of the PixivHelper.py file like the following (be careful with the indentation):
From

                im = Image.open(fp)
                nb_components = len(im.getbands())

To

                with Image.open(fp) as im:
                    nb_components = len(im.getbands())

Then you're gonna restart the script and tell me if you still have the error.

@anon1593
Copy link
Author

anon1593 commented Jul 3, 2022

Yeah, it is very random
pip says PIL not installed
No change after editing the script

@Toyem
Copy link
Contributor

Toyem commented Jul 3, 2022

My bad, it was pip show pillow but if the little tweak didn't change anything it's not use ...
It seems to only occur on Windows and be related to Pillow.
Maybe try to change lines 1146 and 1147 with thoses:

                with Image.open(fp) as im:
                    nb_components = len(im.getbands())
                    im.close()

If it's still doesn't work, I'm gonna see tomorrow if i can launch it on Windows.

@anon1593
Copy link
Author

anon1593 commented Jul 3, 2022

C:\WINDOWS\system32>pip show pillow
Name: Pillow
Version: 8.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Location: c:\python310\lib\site-packages

Now it just crashes immediately.

@Toyem
Copy link
Contributor

Toyem commented Jul 6, 2022

My Windows VM crashed and broke it's SSD. I won't be able to investigate the issue quickly

@Phenrei
Copy link

Phenrei commented Jul 6, 2022

I have had the same issue with a couple mp4 creations since the last update, which I hadn't had before. I'm using the bundled exe windows version as well.

Image 99548831 is an example, which according to debug logging fails when trying to convert image 3 (000002.jpg). In this case, image 2 is grayscale image inside an otherwise full color ugoira (a line step inside a progress image), so the image conversion fails and it dumps out, and the whole program crashes a few steps later due to failing to clean up after itself as the last image in the directory was still claimed by the exe. I was able to edit the ugoira archive with the image upconverted to full color and the mp4 creation went through fine.

My other failed convert was an NSFW case where the final image (a fade to black) had also been optimized down to a 8bpp image. I'd just deleted the problem image in the archive as it hadn't really mattered to the final input and that one went ahead.

@Nandaka
Copy link
Owner

Nandaka commented Jul 7, 2022

try to convert to webm?

@Toyem
Copy link
Contributor

Toyem commented Jul 7, 2022

According to the description that you make @Phenrei, the cause of the problem probably comes from the modifications that I made on the conversion of the ugoira in the issue #1109
The thing is, it only seems to show up on Windows OS.
There must be a particularity of ffmpeg with windows which does not exist on the other OS during the conversion of jpeg

@Toyem
Copy link
Contributor

Toyem commented Jul 15, 2022

@anon1593 and @Phenrei, It took me long enough but I found the cause of your error. You only have to modify line 1138 of PixivHelper.py from:

        f = os.path.join(directory, filename)

to

        f = os.path.join(directory, os.sep, filename)

That should solve the issue, otherwise don't hesitate to raise any other error you might have.

@Phenrei
Copy link

Phenrei commented Jul 15, 2022

Thanks for tracking it down. I've only encountered it a couple more times since this post and it's quickly fixable from my end with a quick Irfanview reencode, so I'll just wait for the fix in the next build. My system python is a mess due to other programs so I end up using the exes.

@Nandaka
Copy link
Owner

Nandaka commented Jul 16, 2022

Changes merged :D

@biggestsonicfan
Copy link
Contributor

@Toyem was Windows fix tested in a Linux environment?

import os
directory = '/pixiv'
filename = 'image.png'
combined = os.path.join(directory, os.sep, filename)
print(combined)

On linux, this produces /image.png as the output, not /pixiv/image.png

@Toyem
Copy link
Contributor

Toyem commented Jul 19, 2022

As mention by @cglmrfreeman just before, the fix I made for Windows creates an error on Linux (but it works just fine on MacOS).

The error is not visible on the console output nor on the logs but by observing the results produced by the program, we observe (as for the issue 1109) that the beginning of the gifs have not been generated.

The problem most likely comes from the behavior mention above of os.path.join on Linux which happens to be different from that on Windows.
... Back to fixing

@Nandaka
Copy link
Owner

Nandaka commented Jul 20, 2022

why not just do the old way?

f = os.path.abspath(f"{directory}{os.sep}{filename}")

@biggestsonicfan
Copy link
Contributor

At that point why prefix with os.path.abspath when f"{directory}{os.sep}{filename}" produces the same string?

@Toyem
Copy link
Contributor

Toyem commented Jul 20, 2022

On paper, the idea was good and it works for Unix OS (Linux and MacOs) but everything goes wrong on Windows.
The heart of the problem was not really the creation of the path but the path itself.
Windows and Unix living in two totally different universes, their separator for folder paths are not really compatible (/ for Unix and \ for Windows) and one line forced all paths to follow the Unix nomenclature:

d.replace(os.sep, '/')

It tended to create chimeras of path absolutely not readable for Windows. Hence the problem on this OS.
In any case, I tested this commit on the 3 main OS. No more worries for this issue (let's hope)

Nandaka pushed a commit that referenced this issue Jul 21, 2022
…1132 (#1136)

- MacOS Catalina 10.15.7
- Linux (Ubuntu 22.04)
- Windows 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants