Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.

Commit 73bf936

Browse files
committed
Add option to stitch moviepy audio w/ ffmpeg
1 parent 031a100 commit 73bf936

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Make sure to copy and paste `config-example.json` into `config.json` and fill in
3333
| owners | array[int] | The Discord IDs of the people able to use dev commands. |
3434
| case_insensitive | bool | Whether or not commands aren't case sensitive |
3535
| custom_help | bool | Whether or not to use custom help |
36+
| stitch_mpy_audio | bool | If your server has problems with MoviePy having no audio in its output, enable this to have FFmpeg add audio instead. This will make rendering slower than usual. |
3637
| botlist | object | Bot list tokens supported by [dbots.py](https://github.com/dbots-pkg/dbots.py) |
3738

3839
### Sources

config-example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "VideoBox",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "a bot that creates funny videos",
55
"prefixes": [
66
"📹 ", "🎥 ", "vbox ", "videobox ",
@@ -11,6 +11,7 @@
1111

1212
"case_insensitive": true,
1313
"custom_help": true,
14+
"stitch_mpy_audio": false,
1415

1516
"blocked": [],
1617

extensions/models/videocog.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,22 @@ async def _send_video(self, ctx, video, clips=[], spoiler=False, preset='ultrafa
3434
# Write and send file
3535
async with ctx.typing():
3636
async_write = self.bot.utils.force_async(video.write_videofile)
37-
await async_write(videoname, threads=threads, preset=preset, verbose=False, logger=None)
37+
await async_write(videoname, threads=threads, preset=preset, verbose=False, logger=None, audio=True,
38+
codec='libx264', audio_codec='libmp3lame', temp_audiofile=f'{videoname}.temp-audio.mp3', remove_temp=False)
39+
40+
# In the rare case that moviepy doesn't correctly add audio, let FFmpeg do it.
41+
if self.bot.config['stitch_mpy_audio']:
42+
stream = ffmpeg.output(ffmpeg.input(videoname).video,
43+
ffmpeg.input(f'{videoname}.temp-audio.mp3').audio,
44+
f'{videoname}.final.mp4')
45+
async_run = self.bot.utils.force_async(stream.run)
46+
await async_run(quiet=True)
47+
os.remove(f'{videoname}.temp-audio.mp3')
48+
os.remove(videoname)
49+
videoname += '.final.mp4'
50+
else:
51+
os.remove(f'{videoname}.temp-audio.mp3')
52+
3853
if os.path.getsize(videoname) > 1000000 * 8 and self.bot.config['owo_key']: # 8 MB
3954
await status_message.edit(
4055
content=f"`📹` {ctx.author.mention}'s **`{ctx.command.name}`**: Uploading..."

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ async def on_ready(self):
119119
print('Initialized.\n')
120120

121121
if len(self.config['botlist']) != 0:
122-
await self.poster.post()
123122
self.poster.start_loop()
123+
await self.poster.post()
124124

125125
async def on_message(self, message):
126126
"""Handles what the bot does whenever a message comes across."""

0 commit comments

Comments
 (0)