{"id":17256457,"url":"https://github.com/tianzerl/pyanime4k","last_synced_at":"2025-04-12T23:05:48.176Z","repository":{"id":40594872,"uuid":"252749378","full_name":"TianZerL/pyanime4k","owner":"TianZerL","description":"An easy way to use anime4k in python","archived":false,"fork":false,"pushed_at":"2021-05-12T18:44:43.000Z","size":63,"stargazers_count":118,"open_issues_count":15,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T23:05:39.325Z","etag":null,"topics":["anime","anime4k","anime4kcpp","gpu-acceleration","machine-learning","python","python3","upscale","upscaling","video-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TianZerL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-03T14:02:56.000Z","updated_at":"2025-03-24T16:34:31.000Z","dependencies_parsed_at":"2022-09-18T04:02:32.121Z","dependency_job_id":null,"html_url":"https://github.com/TianZerL/pyanime4k","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianZerL%2Fpyanime4k","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianZerL%2Fpyanime4k/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianZerL%2Fpyanime4k/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianZerL%2Fpyanime4k/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TianZerL","download_url":"https://codeload.github.com/TianZerL/pyanime4k/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643008,"owners_count":21138354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anime","anime4k","anime4kcpp","gpu-acceleration","machine-learning","python","python3","upscale","upscaling","video-processing"],"created_at":"2024-10-15T07:14:31.440Z","updated_at":"2025-04-12T23:05:48.145Z","avatar_url":"https://github.com/TianZerL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyAnime4K\n\nPyAnime4K is a simple, fast and powerful Anime4K Python implementation.\n\n## Installation\n### Pip\nPyAnime4K can be installed easily through `pip`.(recommended for Windows)\n\n```shell\npip install pyanime4k\n```\n### Shell script\nFor Ubuntu you can also use `setup_wheel_ubuntu.sh` to build wheel file and install it (especially recommended for Google Colab):\n\n```\n# For Google Colab, you need to add \"!\" at the beginning\n# \"setup_wheel_ubuntu.sh\" need root permission for installing dependency library by apt\nwget https://github.com/TianZerL/pyanime4k/raw/master/setup_wheel_ubuntu.sh \u0026\u0026 chmod 777 setup_wheel_ubuntu.sh \u0026\u0026 ./setup_wheel_ubuntu.sh\n```\n## Manual installation\n\n### Compile Anime4KCPP for pyanime4k\n1. Clone [Anime4KCPP](https://github.com/TianZerL/Anime4KCPP)\n2. Follow [this](https://github.com/TianZerL/Anime4KCPP/wiki/Building), and for pyanime4k, only core and c wrapper is needed.  Make sure CMake option `Build_C_wrapper` is turned on, and if you want to build core and c wrapper in one file, turned on `Build_C_wrapper_with_core` (recommend)\n\n### install pyanime4k\n1. Clone the repo   \n2. Download from release or compile the Anime4KCPP core and Anime4KCPP C Wrapper.  \n3. - Copy `ac.dll` and `Anime4KCPPCore.dll` (if turned off Build_C_wrapper_with_core option of Anime4KCPP in CMake) and  `opencv_world440.dll` to the pyanime4k/wrapper (Windows)  \n   - Copy `libac.so` to the pyanime4k/wrapper (Linux)  \n   - Copy `libac.dylib` to the pyanime4k/wrapper (macOS)  \n4. Enjoy  \n\n## Usages\n\n### Upscaling Images\n\n```python\n# pathlib.Path path objects are recommended instead of strings\nimport pathlib\n\n# import pyanime4k library\nimport pyanime4k\n\n# display single image upscaled with Anime4KCPP\npyanime4k.show_upscaled_image(pathlib.Path('image1.png'))\n\n# upscale a single image\npyanime4k.upscale_images(pathlib.Path('image1.png'))\n\n# upscale a list of images\nimages = [\n    pathlib.Path('image1.png'),\n    pathlib.Path('image2.png')\n]\n\npyanime4k.upscale_images(\n    input_paths=images,\n    output_path=pathlib.Path('./output')\n)\n```\n\n### Upscaling Videos\n\n```python\n# pathlib.Path path objects are recommended instead of strings\nimport pathlib\n\n# import pyanime4k library\nimport pyanime4k\n\n# upscale a single video file\npyanime4k.upscale_videos(pathlib.Path('video1.mp4'))\n\n# upscale multiple files\nvideos = [\n    pathlib.Path('video1.mp4'),\n    pathlib.Path('video2.mp4')\n]\n\npyanime4k.upscale_videos(\n    input_paths=videos,\n    output_path=pathlib.Path('./output')\n)\n```\n\n### Preview a video with OpenCV\n\n```python\nfrom pyanime4k import ac\nimport cv2\n\nvideo = cv2.VideoCapture(r\"F:\\Temp\\Anime4K\\P1-1.m4v\")\na = ac.AC(\n    managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0, dID=0)]),\n    type=ac.ProcessorType.OpenCL_ACNet\n)\nwhile True:\n    v,f = video.read()\n    if not v:\n        break\n    # the default color format of OpenCV is BGR\n    f = a.proccess_image_with_numpy(f)\n    cv2.imshow(\"video\", f)\n    cv2.waitKey(1)\n\n```\n\n### Specify GPU\n\nYou can specify GPU for processing if you have more than one GPU\n\n```python\nfrom pyanime4k import ac\n\n# print GPU list to get pID and dID of each GPU\nac.AC.list_GPUs()\n\n# check GPU support\nflag, info = ac.AC.check_GPU_support(GPGPU=ac.GPGPUModel.AC_OpenCL, pID=1, dID=0)\n\n# init AC core with pID and dID\nif flag:\n    a = ac.AC(\n        managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0, dID=0)]),\n        type=ac.ProcessorType.OpenCL_ACNet\n    )\n\n# print GPU information\nprint(info)\n\n# or to check the current processor information\nprint(a.get_processor_info())\n\n```\n\n### Manual Upscaling\n\nYou may also create a low-level AC object and handle each of the steps manually.\n\n```python\nfrom pyanime4k import ac\nimport pyanime4k\n\nparameters = ac.Parameters()\n# enable HDN for ACNet\nparameters.HDN = True\n\na = ac.AC(\n    managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0, dID=0)]),\n    type=ac.ProcessorType.OpenCL_ACNet\n)\n\n# load image from file\na.load_image(r\"D:\\Temp\\anime4k\\p1.png\")\n\n# start processing\na.process()\n\n# preview upscaled image\na.show_image()\n\n# save image to file\na.save_image('image1_output.png')\n\n# from PIL and numpy\nimport numpy as np\nfrom PIL import Image\n\nimg = Image.open(r\"D:\\Temp\\anime4k\\p1.png\").convert(\"RGB\")\nimg = np.array(img)\n\n# BGR, RGB and YUV444 is supported\na.load_image_from_numpy(img, input_type=ac.AC_INPUT_RGB)\n\n# start processing\na.process()\n\n# save image to numpy array\nnew_img = a.save_image_to_numpy()\n\nnew_img  = Image.fromarray(new_img)\nnew_img.show()\n\n# from OpenCV\nimport cv2\n\nimg = cv2.imread(r\"D:\\Temp\\anime4k\\p1.png\")\n\na.load_image_from_numpy(img,input_type=ac.AC_INPUT_BGR)\na.process()\nimg = a.save_image_to_numpy()\n\ncv2.imshow(\"opencv\", img)\ncv2.waitKey(0)\n\n# save image to file\na.save_image('image1_output_1.png')\n\n# let's process video\na.set_video_mode(True)\n\n# load video file\na.load_video(r\"D:\\Temp\\anime4k\\P1-1.m4v\")\n\n# specify output video file name\n# note that this needs to be done before processing starts\na.set_save_video_info(\"output_tmp.mp4\", codec=ac.Codec.MP4V)\n\n# start processing with progress\na.process_with_progress()\n\n# process with callback function\ndef print_progress_time(v, t):\n    print(\"%.2f%% elapsed: %.2f remaining:  %.2f\" % (v * 100, t, t/v - t), end=\"\\r\")\n\n'''\n#or\ndef print_progress(v):\n    print(\"%.2f%%\" % (v * 100), end=\"\\r\")\n'''\n\n# load video file\na.load_video(r\"D:\\Temp\\anime4k\\P1-1.m4v\")\n\n# specify output video file name\n# note that this needs to be done before processing starts\na.set_save_video_info(\"output_tmp_.mp4\", codec=ac.Codec.MP4V)\n\n# start processing with progress value and time callback\na.process_with_progress_time_callback(print_progress_time)\n\n'''\n#or\n# start processing with progress value callback\na.process_with_progress_callback(print_progress)\n'''\n\n# save video to file\na.save_video()\n\n# merge audio and auto delete tmp file\npyanime4k.migrate_audio_streams(\"output_tmp.mp4\",r\"D:\\Temp\\anime4k\\P1-1.m4v\",\"output.mp4\")\n```\n\n### Process a video with OpenCV\n\n```python\nfrom pyanime4k import ac\nimport cv2\nimport time\nimport threading\nimport queue\n\n# init VideoCapture and VideoWriter\nvideoReader = cv2.VideoCapture(r\"D:\\Temp\\anime4k\\P1-1.m4v\")\nfps = videoReader.get(cv2.CAP_PROP_FPS)\nh = videoReader.get(cv2.CAP_PROP_FRAME_HEIGHT)\nw = videoReader.get(cv2.CAP_PROP_FRAME_WIDTH)\nvideoWriter = cv2.VideoWriter(\n    \"output.mp4\",\n    cv2.VideoWriter_fourcc(\"m\", \"p\", \"4\", \"v\"),\n    fps,\n    (int(w * 2), int(h * 2)),\n)\n\n# init Anime4KCPP\na = ac.AC(\n    managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0, dID=0)]),\n    type=ac.ProcessorType.OpenCL_ACNet\n)\n\n# frame queue\nq = queue.Queue(12)\n\n# write frames to disk\ndef writeFrames():\n    while True:\n        f = q.get()\n        videoWriter.write(f)\n        q.task_done()\n\n\n# write frames in new thread\nt = threading.Thread(target=writeFrames, daemon=True)\nt.start()\n\ns = time.time()\n\nwhile True:\n    v, f = videoReader.read()\n    if not v:\n        break\n    f = a.proccess_image_with_numpy(f)\n    q.put(f)\n\ne = time.time()\nprint(\"time:\", e - s, \"s\")\n\n# wait for finished\nq.join()\n\nvideoWriter.release()\n\n```\n\n## Other Anime4K Implementations\n\n- Go\n  - [TianZerL/Anime4KGo](https://github.com/TianZerL/Anime4KGo)\n- C++\n  - [TianZerL/Anime4KCPP](https://github.com/TianZerL/Anime4KCPP)\n- C#\n  - [shadow578/Anime4kSharp](https://github.com/shadow578/Anime4kSharp)\n  - [net2cn/Anime4KSharp](https://github.com/net2cn/Anime4KSharp)\n- GLSL\n  - [bloc97/Anime4K](https://github.com/bloc97/Anime4K)\n- Rust\n  - [andraantariksa/Anime4K-rs](https://github.com/andraantariksa/Anime4K-rs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianzerl%2Fpyanime4k","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftianzerl%2Fpyanime4k","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianzerl%2Fpyanime4k/lists"}