Imagine Dragons' Radioactive

By HexHammer

Record the audio

$ cd Desktop
$ mkdir radioactive
$ cd radioactive
$ arecord -f S16_LE -r 44100 -c 2 -V stereo radioactive.aac --> cd quality, 2 channels, stereo vumeter.

Film the video

$ kazam &
$ cd ../aimos/motion
$ ./motion.sh
$ cd ../radioactive
$ nano radioactivelyrics.txt

I'm waking up,white
to ash and dust
I wipe my brow
and I sweat my rust
I'm breathing in
the chemicals
I'm breaking in
shaping up
then checking out
on the prison bus
This is it
the apocalypse
Whoa-oh
I'm waking up,yellow
I feel it
in my bones
Enough to make
my systems blow
Welcome to the new age...
$ kazam &
$ python pygamelyrics.py

>> import pygame
>> from pygame.locals import *
>> pygame.init()
>> pygame.font.init()
>> legend=pygame.font.SysFont('Sans', 72,bold=True)
>> w=1024; h=768
>> window = pygame.display.set_mode((w,h))
>> pygame.display.set_caption(str(w)+","+str(h))
>> screen = pygame.display.get_surface()
>> lfile=open('radioactivelyrics.txt','r')
>> lyrics=list(lfile)
>> lfile.close()
>> print 'ready? click on the display and press space.'
>> waiting=True
>> while waiting:
>>   events = pygame.event.get()
>>   for event in events:
>>     if event.type == KEYDOWN:
>>       if event.key == K_SPACE: waiting=False
>> print 'running...'
>> cr=255; cg=255; cb=255
>> for l in lyrics:
>>   waiting=True
>>   if ',' in l:                       # current text colour can be specified after a comma
>>     col=l.split(',')[1].strip()      # in the radioactivelyrics.txt file
>>     if col=='white': cr=255; cg=255; cb=255
>>     if col=='red': cr=255;cg=0;cb=0
>>     if col=='yellow': cr=255;cg=255;cb=192
>>     if col=='green': cr=0;cg=255;cb=0
>>   print l.split(',')[0]+'<'+col+'>'
>>   r=cr; g=cg; b=cb
>>   while waiting:
>>     events=pygame.event.get()
>>     for event in events:
>>       if event.type==KEYDOWN:
>>         if event.key==K_SPACE: waiting=False
>>     pygame.draw.rect(screen,(0,0,0),(0,0,w,h))
>>     txt=l.split(',')[0].strip().lower()
>>     text=legend.render(txt, True, (r,g,b))
>>     tw=text.get_width()
>>     th=text.get_height()
>>     screen.blit(text,((w/2)-(tw/2),(h/2)-(th/2)))
>>     pygame.display.flip()
>>     r=r-1; g=g-1; b=b-1
>>     if r<0: r=0
>>     if g<0: g=0
>>     if b<0: b=0
>> print '\ndone'
>> sleep(5)
>> pygame.display.quit()
Edit the video

$ mkdir face
$ mkdir left
$ mkdir right
$ mkdir lyrics
$ avconv -i face.mp4 -f image2 face/%04d.png   or   use ffmpeg -i face.mp4 -f image2 face/%04d.png
$ avconv -i left.mp4 -f image2 left/%04d.png
$ avconv -i right.mp4 -f image2 right/%04d.png
$ avconv -i lyrics.mp4 -f image2 lyrics/%04d.png

$ mplayer left.mp4 --> get frame number of start of audio.
$ cd left
$ ls >files
$ python ../r_delete.py
>> import os
>> fil=open('files',r)
>> lst=list(fil)
>> for f in fil:
>>   os.remove(line.strip())
$ rm files
$ ls >files
$ python ../r_rename.py
>> import os
>> n=0
>> for f in list(open('files','r')):
>>   nam='0000'+str(n)
>>   if '.' in f: os.rename(f.strip(),nam[len(nam)-4:]+'.png')
>>   n+=1
$ rm files
$ cd ..

$ cd left
$ ls >files
$ nano files --> delete any unwanted frames from the list
$ python ../r_delete.py
>> import os
>> n=0
>> for f in list(open('files','r')):
>>   nam='0000'+str(n)
>>   os.remove(line.strip())
>>   n+=1
$ rm files
$ cd ..
$ python radioactive.py
>> import pygame,os
>> from pygame.locals import *
>> from time import sleep
>> pygame.init()
>> w=640; h=480
>> window = pygame.display.set_mode((w,h))
>> pygame.display.set_caption(str(w)+","+str(h))
>> screen = pygame.display.get_surface()
>> tracklen=3465
>> os.mkdir('output')
>> def mix(src1,src2):
>>   dst=''
>>   for n in range(len(src1)):
>>     s1=ord(src1[n])
>>     s2=ord(src2[n])
>>     dst=dst+chr(s1|s2)
>>   return dst
>> for n in range(tracklen+1):
>>   nam='0000'+str(n)
>>   if os.path.isfile('lyrics/'+nam[len(nam)-4:]+'.png'):
>>     img=pygame.image.load('lyrics/'+nam[len(nam)-4:]+'.png')
>>     scl=pygame.transform.scale(img,(w,h))
>>     lyric=pygame.image.tostring(scl,'RGB')
>>   else:
>>     lyric=''
>>   if os.path.isfile('left/'+nam[len(nam)-4:]+'.png'):
>>     img=pygame.image.load('left/'+nam[len(nam)-4:]+'.png')
>>     scl=pygame.transform.scale(img,(w,h))
>>     left=pygame.image.tostring(scl,'RGB')
>>   else:
>>     left=''
>>   if os.path.isfile('right/'+nam[len(nam)-4:]+'.png'):
>>     img=pygame.image.load('right/'+nam[len(nam)-4:]+'.png')
>>     scl=pygame.transform.scale(img,(w,h))
>>     right=pygame.image.tostring(scl,'RGB')
>>   else:
>>     right=''
>>   if os.path.isfile('face/'+nam[len(nam)-4:]+'.png'):
>>     img=pygame.image.load('face/'+nam[len(nam)-4:]+'.png')
>>     scl=pygame.transform.scale(img,(w,h))
>>     face=pygame.image.tostring(scl,'RGB')
>>   else:
>>     face=''
>>   print nam[len(nam)-4:]+'.png'+' lyric:'+str(len(lyric))+' left:'+str(len(left))+' right:'+str(len(right))+' face:'+str(len(face))
>>   if lyric!='':
>>     out=lyric
>>     if left!='': out=mix(out,left)
>>     if right!='': out=mix(out,right)
>>     if face!='': out=mix(out,face)
>>     surf=pygame.image.fromstring(out,(640,480),'RGB')
>>     pygame.image.save(surf,'output/'+nam[len(nam)-4:]+'.png')
>>     screen.blit(surf,(0,0))
>>     pygame.display.flip()

$ cd output
$ avconv -r 15 -i %04d.png output.mp4
$ avconv -i output.mp4 -i radioactive.aac -map 0:0 -map 1:0 -vcodec copy -acodec copy radioactive.mp4
$ mplayer radioactive.mp4