|
Post by AnthroHeart on Apr 1, 2024 0:32:39 GMT
For using tricky Python to do it, here is some info:
I created a Python script with the help of GPT4, though I had to figure things out as the latest version of Pillow does not work with this code.
I created this video automatically from my WAV file. It uses Pillow v9.5.0 with Python v3.7.4 and ffmpeg in a conda environment. I use miniconda3 on Windows.
It exports to a .mp4 that can be uploaded to YouTube.
This might be useful to you guys who want to put your .mp3 or .wav files on YouTube. You can adjust the settings in the file for a custom slide.
Python Code. You have to create a conda environment that isolates the particular version of Python necessary for this.
# conda create -n mp3toyoutube python=3.7.4 # conda activate mp3toyoutube # pip install ffmpeg # pip install Pillow==9.5.0
from PIL import Image, ImageDraw, ImageFont import subprocess import sys
def create_background_image(filename): text = input("Heading Text: ") #"I am Love and Bliss" textfontsize = 128 subtext = input("Subheading Text: ") #"(174Hz) 33.333% Smoothing" subtextfontsize = 100 backgroundcolor = "#301934" textcolor = "yellow" subtextcolor = "yellow" textyoffset = -80 subtextyoffset = 120
# Create an image with a specific background color image = Image.new('RGB', (1920, 1080), color = backgroundcolor) draw = ImageDraw.Draw(image)
# Define a font textfont = ImageFont.truetype('times.ttf', textfontsize)
# Use textsize to get the width and height of the text text_width, text_height = draw.textsize(text, font=textfont)
# Now you can use text_width and text_height to position your text # For example, to center the text: image_width, image_height = image.size x = (image_width - text_width) / 2 y = (image_height - text_height) / 2 + textyoffset
# Draw the text draw.text((x, y), text, fill=textcolor, font=textfont)
# Define a font subtextfont = ImageFont.truetype('times.ttf', subtextfontsize) subtext_width, subtext_height = draw.textsize(subtext, font=subtextfont)
# Now you can use text_width and text_height to position your text # For example, to center the text: image_width, image_height = image.size x2 = (image_width - subtext_width) / 2 y2 = (image_height - subtext_height) / 2 + subtextyoffset
# Draw the text draw.text((x2, y2), subtext, fill=subtextcolor, font=subtextfont)
# Save the image image.save('background.png')
def convert_to_mp4(audio_file): # Create the background image create_background_image(audio_file) # Prepare output filename output_file = audio_file.rsplit('.', 1)[0] + '.mp4' # Use FFmpeg to combine the image and audio into an MP4 command = [ 'ffmpeg', '-loop', '1', '-i', 'background.png', '-i', audio_file, '-c:v', 'libx264', '-tune', 'stillimage', '-c:a', 'aac', '-b:a', '192k', '-pix_fmt', 'yuv420p', '-shortest', output_file ] subprocess.run(command)
if __name__ == "__main__": # Take the audio file name from the command line argument audio_file = sys.argv[1] convert_to_mp4(audio_file)
Code: Youtube_From_WAV.py (2.57 KB)
|
|
|
Post by nathanmyersc on Apr 1, 2024 0:50:22 GMT
Make it support a background image and then a slideshow of images timed to change every 30 seconds. Then you can do that bitmap thing you were talking about,
|
|
|
Post by AnthroHeart on Apr 1, 2024 0:52:58 GMT
Make it support a background image
This command makes it work for youtube
ffmpeg -loop 1 -framerate 2 -y -i Golden2.png -r 1 -i Eulercat.flac -r 1 -shortest -c:a copy Euler.mp4
The first -i is the image you want and the second -i is the music.
The code I posted is if you want text and subtext lined up. Though I haven't gone in meticulously and lined up vertically.
But reden's method produces a bigger mp4, so probably better quality.
I have this if you just want to create a background.png slide image before running the ffmpeg command. But it requires the conda environment as specified above.
|
|
|
Post by AnthroHeart on Apr 1, 2024 0:59:59 GMT
Make it support a background image and then a slideshow of images timed to change every 30 seconds. Then you can do that bitmap thing you were talking about, What bitmap thing would I do to change the image every 30 seconds?
|
|
|
Post by nathanmyersc on Apr 1, 2024 1:05:27 GMT
what is conda enviroment?
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:07:10 GMT
what is conda enviroment? It's a virtual environment that lets you keep different versions of Python apart.
Some python scripts require different version of python, and a conda environment lets you target a specific version:
You would do: conda create -n environment_name python=3.7.4 If you want Python v.3.7.4
Then:
conda activate environment_name
You'll see you're in the conda environment by your command line:
(mp3toyoutube) C:\Repeater\Text_To_Wav_Repeater>
|
|
|
Post by nathanmyersc on Apr 1, 2024 1:09:41 GMT
so i have to use the console before i run the script?
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:10:50 GMT
so i have to use the console before i run the script? For this particular one I think so. But there might be a way to create a batch file to activate the environment and run the python.
There's probably easier ways to make slides as images though.
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:13:07 GMT
Perplexity.ai says you can use Google Slides to create a slide image, so that might be an easier way.
You might even be able to specify a background image.
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:23:27 GMT
An easier way is to use Google Slides and download your slide as png after you're done creating, and then feed that image into ffmpeg:
ffmpeg -loop 1 -framerate 2 -y -i Golden2.png -r 1 -i Eulercat.flac -r 1 -shortest -c:a copy Euler.mp4
The first -i is the image you want and the second -i is the music.
I created this image (from an iStockPhoto image) in Google Slides. You might have to use page setup to increase the image resolution beyond default. Max on Google Slides is 1600x1600, so change your image so the biggest dimension (x or y) is 1600 pixels before importing, and find the dimensions of it so you can input them into Page Setup.
|
|
|
Post by reden on Apr 1, 2024 1:39:38 GMT
Make it support a background image
This command makes it work for youtube
ffmpeg -loop 1 -framerate 2 -y -i Golden2.png -r 1 -i Eulercat.flac -r 1 -shortest -c:a copy Euler.mp4
The first -i is the image you want and the second -i is the music.
The code I posted is if you want text and subtext lined up. Though I haven't gone in meticulously and lined up vertically.
But reden's method produces a bigger mp4, so probably better quality.
I have this if you just want to create a background.png slide image before running the ffmpeg command. But it requires the conda environment as specified above.
I wrote text on my images and did other edits if necessary manually using Acorn (a Mac image editor) but any other editor like Photoshop, Photopea (free, online), Paint.NET (free, Windows), etc. will work. Nowadays I don't write text or modify them anymore.
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:41:25 GMT
I use Gimp, but it's very tricky to line up text vertically exactly where I need it. I don't want the header text in the middle vertically, since there's subheader. Google Slides was quite a bit easier for me. Unless they have templates for gimp for that.
|
|
|
Post by AnthroHeart on Apr 1, 2024 1:43:32 GMT
This is going to be better than using Audioship.io that I used to use until they cancelled my paid credits in lieu of a subscription plan. They go from mp3/wav to YouTube directly. But I think using ffmpeg and Google Slides will be better. They also put a watermark on my videos lately.
|
|
|
Post by reden on Apr 1, 2024 2:08:19 GMT
You have 3111 posts. Photopea is like Photoshop but free and online.
|
|
|
Post by AnthroHeart on Apr 1, 2024 2:10:12 GMT
An easier way is to use Google Slides and download your slide as png after you're done creating, and then feed that image into ffmpeg:
ffmpeg -loop 1 -framerate 2 -y -i Golden2.png -r 1 -i Eulercat.flac -r 1 -shortest -c:a copy Euler.mp4
The first -i is the image you want and the second -i is the music.
I created this image (from an iStockPhoto image) in Google Slides. You might have to use page setup to increase the image resolution beyond default. Max on Google Slides is 1600x1600, so change your image so the biggest dimension (x or y) is 1600 pixels before importing, and find the dimensions of it so you can input them into Page Setup.
I found that YouTube is not accepting mp4 files created with ffmpeg that way. It abandons them when trying to upload.
Once you have a background.png image, you can run this python to convert it to .mp4 that YouTube accepts. It shouldn't need conda and all that.
Just run using: python Youtube_From_WAV.py file.wav
You will need ffmpeg installed. It names the file the same name as the wav, just with a mp4 extension. You can use mp3s as well.
|
|