def ad_debug(videoid): profile = request.args.get("profile", None) tag = freewheel.get_tag(videoid, [0, 90, 180], 500) #return tag return json.dumps(freewheel.get_response(tag))
def stitch(id): logger.info("Stitching for asset: " + id) video_url, cuepoints, length = get_bc_video(id) # TODO only need to pull down the file info if we haven't downloaded the file # We should match the resolution, aspect ration, fps and bitrate fileinfo = get_file_info(video_url) # TODO this assumes the first stream is the video stream so need to check it is # TODO create a new meta extraction function size = str(fileinfo["streams"][0]["width"]) + "x" + str(fileinfo["streams"][0]["height"]) fps = fileinfo["streams"][0]["r_frame_rate"] bitrate = fileinfo["streams"][0]["bit_rate"] # Download local_source = download_file(video_url) mycues = create_bc_cues(cuepoints, length) logger.debug(str(mycues)) splice_commands, splice_files = create_splice_strings(mycues, local_source, length) # TODO this could be tidied a bit to move files and commands into a dict for idx, val in enumerate(splice_files): print "Check " + val if not os.path.exists(val): logger.debug(splice_commands[idx]) p = subprocess.Popen(splice_commands[idx].split(" "), stdout=subprocess.PIPE) text = p.stdout.read() #retcode = p.wait() if len(mycues) == 1: fw_url = freewheel.get_tag(id, mycues, length / 1000) else: # Drop the post roll as we will add it? TODO check this out fw_url = freewheel.get_tag(id, mycues[:-1], length / 1000) adbreaks = freewheel.get_response(fw_url) #print adbreaks break_count = 0 encode_params= [] logger.debug(json.dumps(adbreaks)) for adbreak in adbreaks: logger.debug(json.dumps(adbreak)) if "adbreak" in adbreak: logger.info("Adbreak: " + adbreak["adbreak"]["breakid"]) # Check for pre or post roll status if (adbreak["adbreak"]["breakid"] == "pre"): logger.debug("preroll slot") try: encode_params.append(encode_ad(adbreak["adbreak"]["slots"][0]["creative"]["url"])) except: pass elif (adbreak["adbreak"]["breakid"] == "post"): logger.debug("postroll slot") logger.debug("Splice files length: " + str(len(splice_files))) try: if len(splice_files) > 0: encode_params.append(splice_files[len(splice_files) - 1]) else: encode_params.append(splice_files[len(splice_files)]) encode_params.append(encode_ad(adbreak["adbreak"]["slots"][0])) except: pass else: try: logger.debug("Video source: " + splice_files[break_count]) encode_params.append(splice_files[break_count]) for slot in adbreak["adbreak"]["slots"]: if slot: encode_params.append(encode_ad(slot)) break_count += 1 except: logger.error("Problem with break") # Check for the last slot logger.debyg("Break count: break_count") for encode_file in encode_params: logger.debug("encode file: " + encode_file) stitched_video = stitch_video(encode_params) os.system("open " + stitched_video) return make_dash(stitched_video)
def ad_debug(videoid): profile = request.args.get("profile",None) tag = freewheel.get_tag(videoid, [0,90,180], 500) #return tag return json.dumps(freewheel.get_response(tag))
def stitch(id): logger.info("Stitching for asset: " + id) video_url, cuepoints, length = get_bc_video(id) # TODO only need to pull down the file info if we haven't downloaded the file # We should match the resolution, aspect ration, fps and bitrate fileinfo = get_file_info(video_url) # TODO this assumes the first stream is the video stream so need to check it is # TODO create a new meta extraction function size = str(fileinfo["streams"][0]["width"]) + "x" + str( fileinfo["streams"][0]["height"]) fps = fileinfo["streams"][0]["r_frame_rate"] bitrate = fileinfo["streams"][0]["bit_rate"] # Download local_source = download_file(video_url) mycues = create_bc_cues(cuepoints, length) logger.debug(str(mycues)) splice_commands, splice_files = create_splice_strings( mycues, local_source, length) # TODO this could be tidied a bit to move files and commands into a dict for idx, val in enumerate(splice_files): print "Check " + val if not os.path.exists(val): logger.debug(splice_commands[idx]) p = subprocess.Popen(splice_commands[idx].split(" "), stdout=subprocess.PIPE) text = p.stdout.read() #retcode = p.wait() if len(mycues) == 1: fw_url = freewheel.get_tag(id, mycues, length / 1000) else: # Drop the post roll as we will add it? TODO check this out fw_url = freewheel.get_tag(id, mycues[:-1], length / 1000) adbreaks = freewheel.get_response(fw_url) #print adbreaks break_count = 0 encode_params = [] logger.debug(json.dumps(adbreaks)) for adbreak in adbreaks: logger.debug(json.dumps(adbreak)) if "adbreak" in adbreak: logger.info("Adbreak: " + adbreak["adbreak"]["breakid"]) # Check for pre or post roll status if (adbreak["adbreak"]["breakid"] == "pre"): logger.debug("preroll slot") try: encode_params.append( encode_ad( adbreak["adbreak"]["slots"][0]["creative"]["url"])) except: pass elif (adbreak["adbreak"]["breakid"] == "post"): logger.debug("postroll slot") logger.debug("Splice files length: " + str(len(splice_files))) try: if len(splice_files) > 0: encode_params.append(splice_files[len(splice_files) - 1]) else: encode_params.append(splice_files[len(splice_files)]) encode_params.append( encode_ad(adbreak["adbreak"]["slots"][0])) except: pass else: try: logger.debug("Video source: " + splice_files[break_count]) encode_params.append(splice_files[break_count]) for slot in adbreak["adbreak"]["slots"]: if slot: encode_params.append(encode_ad(slot)) break_count += 1 except: logger.error("Problem with break") # Check for the last slot logger.debyg("Break count: break_count") for encode_file in encode_params: logger.debug("encode file: " + encode_file) stitched_video = stitch_video(encode_params) os.system("open " + stitched_video) return make_dash(stitched_video)