forked from afrum/my_ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlipsync
139 lines (99 loc) · 4.5 KB
/
lipsync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# using cartoon lip sync software and bash commands (my video https://youtu.be/ffyfdT4OJCk)
# github: https://github.com/DanielSWolf/rhubarb-lip-sync
# download program: https://github.com/DanielSWolf/rhubarb-lip-sync/releases
# Step 1:Installation
#-----------------------------------
# I found opensource program on github:
# https://github.com/DanielSWolf/rhubarb-lip-sync
# I had trouble with the repository so I downloaded the zip file
# https://github.com/DanielSWolf/rhubarb-lip-sync/releases
unzip Rhubarb-Lip-Sync-1.11.0-Linux.zip
# Step 2: prepare audio and run rhubarb
#--------------------------------------
# command to change .mp3 to .wav (the program requires .wav or .ogg
ffmpeg -i voice.mp3 voice.wav
# run rhubarb
./rhubarb -o output.txt voice.wav
# Step 3 prepare mouth image files
#---------------------------------
# draw different mouths (there is a sample of mouth shapes here)
# https://github.com/DanielSWolf/rhubarb-lip-sync/tree/master/img
# Step 4 bash commands to make movie of mouth and add audio
#-----------------------------------------------------------
# (this is for a 24fps movie)
# the program outputs the start time (seconds) and mouth letter
# I also want the finish time for each image which is the start
# frame for the next mouth image -1.
awk 'NR!=1 {print int(($1*24)-1)}' output.txt > output2.txt
# add last record
awk 'END{print int($1*24)}' output.txt >> output2.txt
# combine the 2 files
awk 'NR==FNR{a[NR]=$0;next}{print a [FNR],$0}' output2.txt output.txt > output3.txt
# making commands
awk '{print "for ((i="int($2*24)"; i<="$1"; i++)); do convert lisa-"$3".png output_$(printf %05d $i).png ; done"}' output3.txt > output.sh
# add #! /bin/bash to output.sh
chmod +x output.sh
./output.sh
# add any optional commands see after "combine video and audio" commands
# concatenate images
# I was using the commented out command but I found a new one below that
# the new command is good with .png that have transparency and making a .mov
# will keep the transparent parts in the video and then you can overlay the video
#cat *.png | ffmpeg -framerate 24 -f image2pipe -i - output.MOV
ffmpeg -framerate 24 -i output_%05d.png -vcodec png output.mov
# combine video and audio
ffmpeg -i output.MOV -i voice.wav -map 1:0 -map 0:0 final.MOV
# thanks for watching
#-----------------------------------------------------------
#-----------OPTIONAl--------BEGIN---------------------------
# for these examples I had image files called
# output_00000.png to output_20465.png
# quarterhead.png, quarterhair.png,
# quartereyesclosed.png and quartereyesonly.png
#if you have different images with head, mouth, hair
#---------------------------------------adding mouth to head
#make sure head image in in correct folder
#if you want your new output to be in a new folder
#you need to create the folder and state the address to
#the folder
mkdir newdir
for VAR in $(ls output_*); do echo $VAR; composite $VAR quarterhead.png newdir/$VAR; done
#----------------------------------------add hair
# make sure hair image is in the folder
# if you want to replace the image with the new image
# then you don't need to make a new folder
cd newdir/
for VAR in $(ls output_*); do echo $VAR; composite quarterhair.png $VAR $VAR; done
#------------------------adding multiple layer images
for VAR in $(ls output_*); do echo $VAR;
composite $VAR quarterhead.png newdir/$VAR
composite quartereyesclosed.png newdir/$VAR newdir/$VAR
composite quarterhair.png newdir/$VAR newdir/$VAR; done
#------------------------------------------------------------
#-----------------adding blinking by using nested for loop
#--------breaking up the incremental number of the
# output image file so every 200 image frames are
# thirteen closed eyes frames.
for i in $(seq -w 000 2 204)
do
for j in $(seq -w 00 1 13 )
do
echo $i$j
composite newdir/newdir/output_$i$j.png quarterhead.png newdir/newdir/output_$i$j.png
composite quartereyesclosed.png newdir/newdir/output_$i$j.png newdir/newdir/output_$i$j.png
composite quarterhair.png newdir/newdir/output_$i$j.png newdir/newdir/output_$i$j.png
done
done
#----------------making a set of images transparent
for i in {05079..11796}
do
echo $i
convert output_$i.png -matte -channel A +level 0,50% +channel transprnt/output_$i.png
done
#--------------adding images to bottom right of background image
for i in {11797..20465}
do
echo $i
composite -gravity SouthEast newdir/output_$i.png slideframes/out$i.png newdir/finished/final_$i.png
done
#------------OPTIONAL--------END-----------------------------