def create_slideshow(dictionary, length, result): video_list = 'video_list.txt' f = open(video_list, 'w') times = dictionary.keys() times.sort() for i, t in enumerate(times): if i < 1: continue tmp_name = '%d.mp4' % i image = dictionary[t] if i == len(times) - 1: duration = length - t else: duration = times[i + 1] - t out_file = temp_dir + tmp_name ffmpeg.create_video_from_image(image, duration, out_file) f.write('file ' + out_file + '\n') f.close() ffmpeg.concat_videos(video_list, result) os.remove(video_list)
def create_slideshow(self): video_list = self.meeting.source_dir / 'video_list.txt' f = video_list.open('w') ffmpeg.webm_to_mp4(self.meeting.deskshare_src_file, self.meeting.deskshare_tmp_file) print("-=create_slideshow=-", file=sys.stderr) for i, slide in enumerate(self.meeting.slides): tmp_name = '%d.mp4' % i tmp_ts_name = '%d.ts' % i image = slide['full_path'] duration = slide['duration'] out_file = self.meeting.temp_dir / tmp_name out_ts_file = self.meeting.temp_dir / tmp_ts_name if "deskshare.png" == image.name: print(0, i, slide['in'], duration, file=sys.stderr) ffmpeg.trim_video_by_seconds(self.meeting.deskshare_tmp_file, slide['in'], duration, out_file) ffmpeg.mp4_to_ts(out_file, out_ts_file) else: print(1, i, slide['in'], duration, file=sys.stderr) ffmpeg.create_video_from_image(image, duration, out_ts_file) f.write('file ' + str(out_ts_file) + '\n') f.close() ffmpeg.concat_videos(video_list, self.meeting.slideshow_file) video_list.unlink()
def create_slideshow(dictionary, length, result): video_list = 'video_list.txt' f = open(video_list, 'w') times = dictionary.keys() times.sort() for i, t in enumerate(times): if i < 1: continue tmp_name = '%d.mp4' % i image = dictionary[t] if i == len(times) - 1: duration = length - t else: duration = times[i + 1] - t out_file = temp_dir + tmp_name ffmpeg.create_video_from_image(image, duration, out_file) f.write('file ' + out_file + '\n') f.close() ffmpeg.concat_videos(video_list, result) os.remove(video_list)
def create_slideshow(dictionary, length, result, bbb_version): video_list = 'video_list.txt' f = open(video_list, 'w') times = dictionary.keys() times.sort() for i, t in enumerate(times): print >> sys.stderr, "_create_slideshow_" print >> sys.stderr, (i, t) #if i < 1 and '2.0.0' > bbbversion: # continue print >> sys.stderr, "_create_slideshow_after_skip_" print >> sys.stderr, (i, t) tmp_name = '%d.mp4' % i image = dictionary[t] if i == len(times) - 1: duration = length - t else: duration = times[i + 1] - t out_file = temp_dir + tmp_name ffmpeg.create_video_from_image(image, duration, out_file) f.write('file ' + out_file + '\n') f.close() ffmpeg.concat_videos(video_list, result) os.remove(video_list)
def create_slideshow(dictionary, length, result, bbb_version): try: video_list = 'video_list.txt' f = open(video_list, 'w') times = dictionary.keys() times.sort() ffmpeg.webm_to_mp4(SOURCE_DESKSHARE, TMP_DESKSHARE_FILE) print >> sys.stderr, "-=create_slideshow=-" for i, t in enumerate(times): print >> sys.stderr, (i, t) # if i < 1 and '2.0.0' > bbbversion: # continue tmp_name = '%d.mp4' % i tmp_ts_name = '%d.ts' % i image = dictionary[t] print >> sys.stderr, times print >> sys.stderr, length if i == len(times) - 1: duration = length - t else: duration = times[i + 1] - t out_file = temp_dir + tmp_name out_ts_file = temp_dir + tmp_ts_name if "deskshare.png" in image: print >> sys.stderr, (0, i, t, duration) ffmpeg.trim_video_by_seconds(TMP_DESKSHARE_FILE, t, duration, out_file) ffmpeg.mp4_to_ts(out_file, out_ts_file) else: print >> sys.stderr, (1, i, t, duration) ffmpeg.create_video_from_image(image, duration, out_ts_file) f.write('file ' + out_ts_file + '\n') f.close() ffmpeg.concat_videos(video_list, result) os.remove(video_list) except: print >> sys.stderr, "Exception create_slideshow" print >> sys.stderr, dictionary.keys() print >> sys.stderr, image
def create_slideshow(dictionary, length, result): video_list = 'video_list.txt' video_list_tmp = [] video_list_fn = [] f = open(video_list, 'w') times = list(dictionary.keys()) times.sort() ffmpeg.webm_to_mp4(SOURCE_DESKSHARE, TMP_DESKSHARE_FILE) print("-=create_slideshow=-") for i, t in enumerate(times): tmp_name = '%d.mp4' % i tmp_ts_name = '%d.ts' % i image = dictionary[t] if i == len(times) - 1: duration = length - t else: duration = times[i + 1] - t out_file = temp_dir + tmp_name out_ts_file = temp_dir + tmp_ts_name if "deskshare.png" in image: print(sys.stderr, (0, i, t, duration)) ffmpeg.trim_video_by_seconds(TMP_DESKSHARE_FILE, t, duration, out_file) ffmpeg.mp4_to_ts(out_file, out_ts_file) else: print(sys.stderr, (1, i, t, duration)) ffmpeg.create_video_from_image(image, duration, out_ts_file) video_list_fn.append(out_ts_file) f.write('file ' + out_ts_file + '\n') video_list_tmp.append(out_ts_file) f.close() height = 1080 # Scale video files with open(video_list, 'w') as f: for entry in video_list_fn: out_file = temp_dir + entry.split('/')[-1].split( '.')[0] + '_new.ts' ffmpeg.scale_fixed(entry, out_file) f.write('file ' + out_file + '\n') ffmpeg.concat_videos(video_list, result) return height
def create_drawing(result): try: print >> sys.stderr, "[" + meetingId + "]-=create_drawing=-" copy_mp4(SOURCE_DESKSHARE, TMP_DESKSHARE_FILE) drawing_list = temp_dir + 'drawing_list.txt' f = open(drawing_list, 'w') tree = ET.parse(source_dir + 'cursor.xml') cursor = {} for child in tree.findall('event'): cord = child.find('cursor').text.split() cursor[round(float(child.get('timestamp')), 1)] = { 'x': float(cord[0]), 'y': float(cord[1]) } images = [] svg = collections.OrderedDict() html = open(source_dir + "shapes.svg", "r") parsed_html = BeautifulSoup(html, 'lxml') for elem in parsed_html.svg: if elem.name == 'image': images.append(elem) id = elem['id'] if elem.name == 'g': for elem_2nd in elem: if elem_2nd.name == 'g': if id in svg: svg[id].append(elem_2nd) else: svg[id] = [elem_2nd] for img in images: bild = collections.OrderedDict() video_list = [] duration_list = [] duration = 0.1 image_not_changed = True if "deskshare.png" in img['xlink:href']: ffmpeg.trim_video_by_seconds( TMP_DESKSHARE_FILE, round(float(img['in']), 1), round(float(img['out']), 1) - round(float(img['in']), 1), temp_dir + "draw_" + str(img['id']) + ".mp4") ffmpeg.mp4_to_ts(temp_dir + "draw_" + str(img['id']) + ".mp4", temp_dir + "draw_" + str(img['id']) + ".ts") f.write('file ' + temp_dir + "draw_" + str(img['id']) + ".ts" + '\n') else: background = "<image width='" + img['width'] + "' height='" + img[ 'height'] + "' xlink:href='data:image/png;base64," + base64.b64encode( open(img['xlink:href'], "rb").read()) + "'/>" bild.update({'background': background}) for time in numpy.arange(round(float(img['in']), 1), round(float(img['out']), 1), 0.1): time = round(time, 1) before = bild.copy() if time in cursor: bild.update({'cursor': cursor[time]}) if img['id'] in svg: for draw in svg[img['id']]: if "poll" in str(draw): poll_base = "data:image/svg+xml;base64," + base64.b64encode( open(draw.image['xlink:href'], "rb").read()) if round(float(draw['timestamp']), 1) == time or ( round(float(draw['timestamp']), 1) < round(float(img['in']), 1) and draw['undo'] == '-1'): bild.update({ draw['shape']: str(draw).replace( 'visibility:hidden;', '').replace( 'style="visibility:hidden"', ''). replace('visibility:hidden', '').replace('\n', '').replace( draw.image['xlink:href'], poll_base) }) if round(float(draw['undo']), 1) == time: bild.update({draw['shape']: ''}) else: if round(float(draw['timestamp']), 1) == time or ( round(float(draw['timestamp']), 1) < round(float(img['in']), 1) and draw['undo'] == '-1'): bild.update({ draw['shape']: str(draw).replace( 'visibility:hidden;', '').replace( 'style="visibility:hidden"', '').replace( 'visibility:hidden', '').replace('\n', '') }) if round(float(draw['undo']), 1) == time: bild.update({draw['shape']: ''}) if before != bild: image_not_changed = False write_svg_file = temp_dir + "draw_" + str( time) + img['id'] + ".svg" write_svg = open(write_svg_file, 'a+') write_svg.write( "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='" + str(img['width']) + "' height='" + str(img['height']) + "'>") if len(bild) >= 1: for k, v in bild.items(): if v and k != 'cursor': write_svg.write(v) if 'cursor' in bild: write_svg.write( "<circle r='8' cx='" + str( int(img['width']) * float(bild['cursor']['x'])) + "' cy='" + str( int(img['height']) * float(bild['cursor']['y'])) + "' style='fill:red;stroke:gray;stroke-width:0.1'/>" ) write_svg.write("</svg>") write_svg.close() if len(video_list) != 0: duration_list.append(round(duration, 1)) duration = 0.1 video_list.append(write_svg_file) else: duration = duration + 0.1 if time == round(float(img['out']) - 0.1, 1): if image_not_changed: write_svg_file = temp_dir + "draw_" + str( time) + img['id'] + ".svg" write_svg = open(write_svg_file, 'a+') write_svg.write( "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='" + str(img['width']) + "' height='" + str(img['height']) + "'>") if len(bild) >= 1: for k, v in bild.items(): if v and k != 'cursor': write_svg.write(v) if 'cursor' in bild: write_svg.write( "<circle r='8' cx='" + str( int(img['width']) * float(bild['cursor']['x'])) + "' cy='" + str( int(img['height']) * float(bild['cursor']['y'])) + "' style='fill:red;stroke:gray;stroke-width:0.1'/>" ) write_svg.write("</svg>") write_svg.close() video_list.append(write_svg_file) duration_list.append(round(duration, 1)) duration = 0.1 for i in range(0, len(video_list)): ffmpeg.create_video_from_image( video_list[i], round(float(duration_list[i]), 1), video_list[i] + ".ts") f.write('file ' + video_list[i] + ".ts" + '\n') f.close() ffmpeg.concat_videos(drawing_list, result) os.remove(drawing_list) except Exception, e: print(e) print >> sys.stderr, "[" + meetingId + "]Exception create_drawing"