LuisMayo / objection_engine

Library that turns comment chains into ace attorney scenes, used in several bots
MIT License
105 stars 20 forks source link

Audio Codec issue #103

Closed ScaredDonut closed 1 year ago

ScaredDonut commented 1 year ago

Hi,

First of all thank you for making this awesome too! :)

I am having a little issue with using the engine. I am trying to integrate it into my Discord bot, however, when I first ran it I was getting a permission error.

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: PermissionError: [Errno 13] Permission denied: 'assets.zip'

I found out it was because it was trying to download the content into the / directory (basically where the sys, tmp, home, etc, folders are). So I ended up modifying most of the files so it puts the files into the /home/ubuntu/.../.../.../Red-DiscordBot/data/main/cogs/CogManager/cogs/donuttools/assets folder.

Everything ended up working except the video does not play on Discord, however, if you download it off discord it plays the video just fine but without any audio.

So what I did was I commented out these lines from anim.py

  #  # Clean up the temporary files that were created.
  #  if os.path.exists(root_filename):
  #      shutil.rmtree(root_filename)
  #  if os.path.exists(text_filename):
  #      os.remove(text_filename)
  #  if os.path.exists(audio_filename):
  #      os.remove(audio_filename)

to make sure that the audio file generates and it does. It plays the .mp3 fine when downloaded off the SFTP. However, the video doesn't have any sound if downloaded of the SFTP.

I ended up debugging some vars into the txt file for the output_filename and audio_filename variables and I think there is where the issue lies.

The output is:

file /home/ubuntu/.local/share/Red-DiscordBot/data/main/cogs/CogManager/cogs/donuttools/aceRenders/1673116664ace/0.mp4 (txt.write('file ' + root_filename + '/' +video + '\n')) 1673116664ace.mp4 (txt.write(output_filename + '\n')) /home/ubuntu/.local/share/Red-DiscordBot/data/main/cogs/CogManager/cogs/donuttools/aceRenders/1673116664ace.mp4.audio.aac (txt.write(audio_filename + '\n'))

As you can see the video actually renders as 0.mp4 but the output is 1673116664ace.mp4 and this happens for every single render.

I was wondering if you could point me in the right direction where would I go from here?

Thanks for your time and help! :)

LuisMayo commented 1 year ago

It's normal for the video to be rendered as 0.mp4 since it just renders it part by part and then it concats all the videos.

That being said. I'm not sure what could be happening here. Errors that you may be happening.

  1. Check ffmpeg is properly installed. If it isn't maybe the audio and the video are not properly getting merged. And that's why the video may have no audio You can do it by typing ffmpeg at your terminal and checking if the output is correct. If it throws an unrecognized command error you should install it with sudo apt install ffmpeg

  2. Check the working directory. Objection engine uses the current working directory as a base both for the assets management and for the video generation. If assets were getting downloaded to the root directory / maybe the CWD isn't being properly set. Are you using any launcher/process manager (like supervisord) for your bot or are you launching it manually in the terminal?

Thanks!

ScaredDonut commented 1 year ago

Good morning,

That makes sense thanks for the explanation!

  1. FFMPEG appears to be correctly installed.

    ubuntu@bull-last-stand:~$ ffmpeg -version
    ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
    built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  2. I am using the built in services/systemd for the bot

[Unit]
Description=%I redbot
After=multi-user.target
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/home/ubuntu/redenv/bin/python -O -m redbot %I --no-prompt
User=ubuntu
Group=ubuntu
Type=idle
Restart=always
RestartSec=15
RestartPreventExitStatus=0
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target
LuisMayo commented 1 year ago

Nice.

I don't have a lot of experience on SystemCTL but you probably should set a workingdirectory proerty setting to change the current directory to a non-root folder.

Please make sure that the user running the service (ubuntu in this case) has full Read/Write permissions on the directory you specify on the workingdirectory property.

This should fix the assets.zip problem and hopefully the non-concated one too

ScaredDonut commented 1 year ago

Yup, that was the issue! Thank you so much you're a live saver! :)