Code Monkey home page Code Monkey logo

bad-apple's Issues

ModuleNotFOundError: No module named 'PIL'

I never used Python but I really wanted to try this. I followed all the steps.

\Desktop\bad-apple-master\touhou_bad_apple_v3.py", line 7, in
from PIL import Image
ModuleNotFoundError: No module named 'PIL'

block=False is not supported in Linux

block=False is not supported in Linux, you may need to add an thread to execute playsound():

import threading
...

threading.Thread(target=playsound, args=("tng_bad-apple.mp3",)).start()

V4.5 works flawless on fedora but:

At the end, theres that. :I
it works perfectly until it reaches the end
Python 3.9 has been used.
Afaik Python 3.10 has some issues cause this hasn't been optimized for Python 3.10 or newer.

Traceback (most recent call last):
  File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 181, in <module>
    main()
  File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 171, in main
    play_video(total_frames=total_frames)
  File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 37, in play_video
    sys.stdout.write("\r" + ASCII_LIST[frame_number])
IndexError: list index out of range 

Not really an issue, just some tweaks, from a new-ish scripter

Forked your repo, and had a look, also had a look about the suggestions made by the other user, but honestly, cv2 and the way you're currently doing the ascii conversion, is over my head slightly. If I properly sat down and read it, I might get somewhere, but anyways.
I've tweaked your script to also use threading on the frames, so it should be faster. Also, completely removed the need to save to a file, twice, by just directly passing the cv2 result to PIL, and then outputting the frames, though I do like the idea for keeping the frames, which is why I'm also looking into perhaps RLE compressing the frames into a single file, instead of having a whole folder of 7kb ASCIIs.
I'm not really sure if you wanted the tweaks I made in your version, so I made it as a separate file on my repo and put this as a issue, instead of a PR (though if comments were a thing, I'd put it there), if you just want to take a look. Just as someone who vaguely knows Python, this was a nice project to at least be able to work on.

Oh, and progress bar still works!

[touhou_bad_apple_v4.5.py] pygame.error: Unrecognized audio format

Hey :) Its been a while since my last ticket :)
I have a new one for yaa. Even when this project was a weekend project. im still amazed about your progress..

It seems to be that there is something wrong with the audio format...

see log:

python3 touhou_bad_apple_v4.5.py

Select option:

  1. Play
  2. Exit
    ==============================================================
    Your option: 1
    Please enter the video file name (file must be in root!): BadApple.mp4
    MoviePy - Writing audio in audio.mp3
    MoviePy - Done.
    Beginning ASCII generation...
    Progress: [####################### ] 99% Frame 6570 of 6571 framesASCII generation completed! ASCII generation time: 28.546977519989014Traceback (most recent call last):
    File "touhou_bad_apple_v4.5.py", line 181, in
    main()
    File "touhou_bad_apple_v4.5.py", line 170, in main
    play_audio('audio.mp3')
    File "touhou_bad_apple_v4.5.py", line 24, in play_audio
    pygame.mixer.music.load(path)
    pygame.error: Unrecognized audio format

Possible optimizations in ASCII generation, video quality, and video playback

Hi, I saw the code on touhou_bad_apple_v2.py and I though of some possible speed improvements right off the bat.

First is ASCII generation. As you're doing right now, the best way to improve processing speed is by creating a Pool and allocating each frame to a worker until the frame extraction is over. The disadvantage is that you lose the current progress bar you have implemented, and instead will need something more complex like an N lines progress bar, one for each worker in the pool, or a signaling method between threads, like a semaphore, and is just too much work for what the current project is aiming for. You can also improve the video quality by adding more characters to the list, more specifically a space(all black) " " and a block character(all white) "\u2588", and adapting the padding calculation on line 86 to include the new characters.

Another improvement, and probably the most important one, is saving the ASCII frames to a single file containing all frames, instead of multiple files. The reasoning is that opening and closing files takes time, which would be better spent synchronizing the frames in the terminal.

Checking files also takes time. As of right now, you are manually checking every single .txt file for all the frames and checking if they exist. This can be done much faster if you use instead os.listdir() and filter the results containing the string .txt, then count the results(or a single file if you use the approach above). Also, please always use os.path.join() instead of manually using /. Reasoning is that the os.path library provides cross-platform separators and better handling of absolute paths, which is much less error prone.

I could make a fork and do those changes, but I think it would be very useful if you did them yourself, since you can learn new skills and functions with them. Tell me what you think about my suggestions, then close this issue later.

Edit: my mistake, I just noticed you changed to a white background in the video. Correct characters are a space(all white) " " and a block character(all black) "\u2588"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.