I uploaded this video on Youtube last night: Nightly Experiments – A few notes 2.0. The music was recorded as an MP3 file with Audacity after connecting the musical keyboard's output jack to the laptop's line-in jack using a cable with 3.5 mm stereo plug at both ends. A 3.5 mm stereo jack to 6.35 mm stereo adapter was used to connect the 3.5 mm (approx. ⅛") stereo plug to the keyboard's 6.35 mm (¼") stereo jack.

In this blog post, I'll explain how I converted the MPEG audio (a .mp3 file) to an MPEG video (a .mpg file) with my Debian GNU/Linux system so that I could upload the video to Youtube. My requirements were simple. I needed one still image displaying some text while the music plays. I wrote this Python script to generate a JPEG image that displays the album name and the title at the center and my name at the bottom right corner.

import Image, ImageDraw, ImageFont

ALBUM = 'Nightly Experiments'
TITLE = 'A few notes 2.0'
ARTIST = 'Susam Pal'
FILE = 'a_few_notes_2.jpg'

WIDTH = 640
HEIGHT = 480
GAP = 10

FONT = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'

image = Image.new('RGB', (WIDTH, HEIGHT))
writer = ImageDraw.Draw(image)
largeFont = ImageFont.truetype(FONT, 36)
smallFont = ImageFont.truetype(FONT, 20)

albumWidth, albumHeight = writer.textsize(ALBUM, font=largeFont)
titleWidth, titleHeight = writer.textsize(TITLE, font=largeFont)
artistWidth, artistHeight = writer.textsize(ARTIST, font=smallFont)

albumX = (WIDTH - albumWidth) / 2
albumY = (HEIGHT - albumHeight - titleHeight -
GAP - 2 * MARGIN - artistHeight) / 2
titleX = (WIDTH - titleWidth) / 2
titleY = albumY + albumHeight + GAP
artistX = WIDTH - artistWidth - MARGIN
artistY = HEIGHT - artistHeight - MARGIN

writer.text((albumX, albumY), ALBUM, font=largeFont)
writer.text((titleX, titleY), TITLE, font=largeFont)
writer.text((artistX, artistY), ARTIST, font=smallFont)


Python Imaging Library (PIL) is used in this script. It can be installed on Debian GNU/Linux by running: aptitude install python-imaging.

After generating the JPEG image by running the above script, the JPEG image and the MPEG audio was converted into an MPEG video by running this command:

ffmpeg -ab 256k -loop_input -shortest -i a_few_notes_2.jpg -i a_few_notes_2.mp3 a_few_notes_2.mpg
FFmpeg video converter can be installed by running: aptitude install ffmpeg.

1 comment

Post a comment