Skip to content

Commit 82941e5

Browse files
added screenshare video in final video file
1 parent 451944b commit 82941e5

File tree

2 files changed

+64
-30
lines changed

2 files changed

+64
-30
lines changed

src/download.py

+42-27
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
LOGFILE = LOGS + meetingId + '.log'
3434
ffmpeg.set_logfile(LOGFILE)
3535
source_events = '/var/bigbluebutton/recording/raw/' + meetingId + '/events.xml'
36+
# Deskshare
37+
SOURCE_DESKSHARE = source_dir + 'deskshare/deskshare.webm'
38+
TMP_DESKSHARE_FILE = temp_dir + 'deskshare.mp4'
39+
3640

3741
def extract_timings(bbb_version):
3842
doc = minidom.parse(events_file)
@@ -42,14 +46,15 @@ def extract_timings(bbb_version):
4246

4347
for image in doc.getElementsByTagName('image'):
4448
path = image.getAttribute('xlink:href')
49+
4550
if j == 0 and '2.0.0' > bbb_version:
4651
path = u'/usr/local/bigbluebutton/core/scripts/logo.png'
4752
j += 1
4853

4954
in_times = str(image.getAttribute('in')).split(' ')
5055
out_times = image.getAttribute('out').split(' ')
5156

52-
temp = float( out_times[len(out_times) - 1] )
57+
temp = float(out_times[len(out_times) - 1])
5358
if temp > total_length:
5459
total_length = temp
5560

@@ -67,18 +72,17 @@ def create_slideshow(dictionary, length, result, bbb_version):
6772
times = dictionary.keys()
6873
times.sort()
6974

75+
ffmpeg.webm_to_mp4(SOURCE_DESKSHARE, TMP_DESKSHARE_FILE)
76+
77+
print >> sys.stderr, "-=create_slideshow=-"
7078
for i, t in enumerate(times):
71-
print >> sys.stderr, "_create_slideshow_"
72-
print >> sys.stderr, (i, t)
79+
# print >> sys.stderr, (i, t)
7380

74-
#if i < 1 and '2.0.0' > bbbversion:
81+
# if i < 1 and '2.0.0' > bbbversion:
7582
# continue
7683

77-
78-
print >> sys.stderr, "_create_slideshow_after_skip_"
79-
print >> sys.stderr, (i, t)
80-
8184
tmp_name = '%d.mp4' % i
85+
tmp_ts_name = '%d.ts' % i
8286
image = dictionary[t]
8387

8488
if i == len(times) - 1:
@@ -87,13 +91,20 @@ def create_slideshow(dictionary, length, result, bbb_version):
8791
duration = times[i + 1] - t
8892

8993
out_file = temp_dir + tmp_name
94+
out_ts_file = temp_dir + tmp_ts_name
95+
96+
if "deskshare.png" in image:
97+
print >> sys.stderr, (0, i, t, duration)
98+
ffmpeg.trim_video_by_seconds(TMP_DESKSHARE_FILE, t, duration, out_file)
99+
ffmpeg.mp4_to_ts(out_file, out_ts_file)
100+
else:
101+
print >> sys.stderr, (1, i, t, duration)
102+
ffmpeg.create_video_from_image(image, duration, out_ts_file)
90103

91-
ffmpeg.create_video_from_image(image, duration, out_file)
92-
f.write('file ' + out_file + '\n')
104+
f.write('file ' + out_ts_file + '\n')
93105
f.close()
94106

95107
ffmpeg.concat_videos(video_list, result)
96-
97108
os.remove(video_list)
98109

99110

@@ -114,16 +125,16 @@ def rescale_presentation(new_height, new_width, dictionary, bbb_version):
114125
times = dictionary.keys()
115126
times.sort()
116127
for i, t in enumerate(times):
117-
#?
118-
print >> sys.stderr, "_rescale_presentation_"
119-
print >> sys.stderr, (i, t)
128+
# ?
129+
#print >> sys.stderr, "_rescale_presentation_"
130+
#print >> sys.stderr, (i, t)
120131

121132
if i < 1 and '2.0.0' > bbb_version:
122133
continue
123134

124-
print >> sys.stderr, "_rescale_presentation_after_skip_"
125-
print >> sys.stderr, (i, t)
126-
135+
#print >> sys.stderr, "_rescale_presentation_after_skip_"
136+
#print >> sys.stderr, (i, t)
137+
127138
ffmpeg.rescale_image(dictionary[t], new_height, new_width, dictionary[t])
128139

129140

@@ -170,14 +181,14 @@ def prepare(bbb_version):
170181

171182
shutil.copytree("presentation", temp_dir + "presentation")
172183
dictionary, length = extract_timings(bbb_version)
173-
#debug
184+
# debug
174185
print >> sys.stderr, "dictionary"
175186
print >> sys.stderr, (dictionary)
176187
print >> sys.stderr, "length"
177188
print >> sys.stderr, (length)
178189
dims = get_different_presentations(dictionary)
179-
#debug
180-
print >> sys.stderr, "dims"
190+
# debug
191+
print >> sys.stderr, "dims"
181192
print >> sys.stderr, (dims)
182193
check_presentation_dims(dictionary, dims, bbb_version)
183194
return dictionary, length, dims
@@ -190,8 +201,8 @@ def get_different_presentations(dictionary):
190201
presentations = []
191202
dims = {}
192203
for t in times:
193-
#?if t < 1:
194-
#? continue
204+
# ?if t < 1:
205+
# ? continue
195206

196207
name = dictionary[t].split("/")[7]
197208
# debug
@@ -216,6 +227,7 @@ def serve_webcams():
216227
if os.path.exists('video/webcams.webm'):
217228
shutil.copy2('video/webcams.webm', './download/')
218229

230+
219231
def copy_mp4(result, dest):
220232
if os.path.exists(result):
221233
shutil.copy2(result, dest)
@@ -226,21 +238,23 @@ def zipdir(path):
226238
zipf = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
227239
for root, dirs, files in os.walk(path):
228240
for f in files:
229-
zipf.write(os.path.join(root, f) )
241+
zipf.write(os.path.join(root, f))
230242
zipf.close()
231243

232-
#Create symlink instead so that files are deleted
233-
#if not os.path.exists('/var/bigbluebutton/playback/presentation/download/' + filename):
244+
# Create symlink instead so that files are deleted
245+
# if not os.path.exists('/var/bigbluebutton/playback/presentation/download/' + filename):
234246
# os.symlink(source_dir + filename, '/var/bigbluebutton/playback/presentation/download/' + filename)
235247

248+
236249
def bbbversion():
237250
global bbb_ver
238251
bbb_ver = 0
239252
s_events = minidom.parse(source_events)
240253
for event in s_events.getElementsByTagName('recording'):
241-
bbb_ver = event.getAttribute('bbb_version')
254+
bbb_ver = event.getAttribute('bbb_version')
242255
return bbb_ver
243256

257+
244258
def main():
245259
sys.stderr = open(LOGFILE, 'a')
246260
print >> sys.stderr, "\n<-------------------" + time.strftime("%c") + "----------------------->\n"
@@ -262,12 +276,13 @@ def main():
262276
ffmpeg.trim_audio_start(dictionary, length, audio, audio_trimmed)
263277
ffmpeg.mux_slideshow_audio(slideshow, audio_trimmed, result)
264278
serve_webcams()
265-
#zipdir('./download/')
279+
# zipdir('./download/')
266280
copy_mp4(result, source_dir + meetingId + '.mp4')
267281
finally:
268282
print >> sys.stderr, "Cleaning up temp files..."
269283
cleanup()
270284
print >> sys.stderr, "Done"
271285

286+
272287
if __name__ == "__main__":
273288
main()

src/ffmpeg.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
__author__ = 'palexang'
1+
__author__ = 'CreateWebinar.com'
22

33
# Python wrapper around the ffmpeg utility
44
import os
55
import shutil
66

7+
# FFMPEG = 'ffmpeg'
78
FFMPEG = '/opt/ffmpeg/ffmpeg'
9+
# FFMPEG = '/root/bin/ffmpeg'
810
VID_ENCODER = 'libx264'
911

1012

@@ -37,6 +39,16 @@ def concat_videos(video_list, out_file):
3739
os.system(command)
3840

3941

42+
def mp4_to_ts(input, output):
43+
command = '%s -i %s -c copy -bsf:v h264_mp4toannexb -f mpegts %s 2>> %s' % (FFMPEG, input, output, logfile)
44+
os.system(command)
45+
46+
47+
def concat_ts_videos(input, output):
48+
command = '%s -i %s -c copy -bsf:a aac_adtstoasc %s 2>> %s' % (FFMPEG, input, output, logfile)
49+
os.system(command)
50+
51+
4052
def rescale_image(image, height, width, out_file):
4153
if height < width:
4254
command = '%s -i %s -vf pad=%s:%s:0:oh/2-ih/2 %s -y 2>> %s' % (FFMPEG, image, width, height, out_file, logfile)
@@ -57,7 +69,13 @@ def trim_video(video_file, start, end, out_file):
5769

5870
str1 = '%d:%d:%d' % (start_h, start_m, start_s)
5971
str2 = '%d:%d:%d' % (end_h, end_m, end_s)
60-
command = '%s -ss %s -t %s -i %s -vcodec copy -acodec copy %s 2>> %s' % (FFMPEG, str1, str2, video_file, out_file, logfile)
72+
command = '%s -ss %s -t %s -i %s -vcodec copy -acodec copy %s 2>> %s' % (
73+
FFMPEG, str1, str2, video_file, out_file, logfile)
74+
os.system(command)
75+
76+
77+
def trim_video_by_seconds(video_file, start, end, out_file):
78+
command = '%s -ss %s -i %s -c copy -t %s %s 2>> %s' % (FFMPEG, start, video_file, end, out_file, logfile)
6179
os.system(command)
6280

6381

@@ -102,5 +120,6 @@ def webm_to_mp4(webm_file, mp4_file):
102120

103121

104122
def audio_to_video(audio_file, image_file, video_file):
105-
command = '%s -loop 1 -i %s -i %s -c:v libx264 -tune stillimage -c:a libfdk_aac -pix_fmt yuv420p -shortest %s' % (FFMPEG, image_file, audio_file, video_file)
123+
command = '%s -loop 1 -i %s -i %s -c:v libx264 -tune stillimage -c:a libfdk_aac -pix_fmt yuv420p -shortest %s' % (
124+
FFMPEG, image_file, audio_file, video_file)
106125
os.system(command)

0 commit comments

Comments
 (0)