Beispiel #1
0
def SCD_Using_ECR(video, tmp_path=getcwd(), fmt='_%05d.jpg',
                  global_threshold=80, degradation=5):
    """
    Scene Cut Detection using Edge Change Ratio of a given Video
    :param video: Path to Video
    :return: None
    """
    tmp_folder = mkdtemp(dir=tmp_path)  # Create a temp dir
    tmp_filename = splitext(basename(video))[0]  # Get name from video
    output_path = pathjoin(tmp_folder, tmp_filename)  # Join
    video_to_images(video, output_path, fmt, degradation,
                    wait=False)  # Convert Video to Images

    video_info = ffprobe_video(video)
    print video_info
    # Default 00:00:00:00 Source In Timecode
    begin_timecode = PyTimeCode(video_info['fps'], '00:00:00:00')
    # Source's Running Timecode
    video_timecode = PyTimeCode(video_info['fps'], '00:00:00:00')
    # Source's Start Timecode else Defaults to 00:00:00:00
    start_timecode = PyTimeCode(video_info['fps'], video_info['start_timecode'])
    # Source's Duration in Timecode
    end_timecode = PyTimeCode(video_info['fps'],
                              '00:00:00:00') + video_info['frames']
    edit_list = list()

    with open(pathjoin(getcwd(), '%s.txt' % tmp_filename), 'w+') as fp:
        vstream = ImgSeqStream(tmp_folder, tmp_filename, fmt)
        for i, current_frame in enumerate(vstream):
            if i > 0:
                ecr = edge_change_ratio(previous_frame, current_frame,
                                        float_accuracy=2)
                print video_timecode, i, ecr
                if ecr > global_threshold:
                    fp.writelines('{2},{0},{1},CUT!\n'.format(i, ecr,
                                                              video_timecode))
                    edit_list.append(video_timecode)
                else:
                    fp.writelines('{2},{0},{1}\n'.format(i, ecr,
                                                         video_timecode))
            previous_frame = current_frame
            video_timecode += 1

    rmtree(tmp_folder, True)
    print edit_list
    createEDL(begin_timecode, start_timecode, end_timecode, edit_list,
              tmp_filename, '%s.edl' % tmp_filename)
Beispiel #2
0
 def tc2tc_obj(self, tc):
     """Generate TimeCode object from a timecode string"""
     return PyTimeCode(self.fr_str, start_timecode=tc, drop_frame=self.df)
Beispiel #3
0
 def ts2tc_obj(self, ts):
     """Generate TimeCode object from a timestamp"""
     return PyTimeCode(self.fr_str,
                       frames=self.ts2frame(ts),
                       drop_frame=self.df)
Beispiel #4
0
from edl.edl import Parser
from pytimecode import PyTimeCode
import json

parser = Parser('29.97')
tc = PyTimeCode('29.97')

f = open('edit.edl')
edl = parser.parse(f)
f.close()

f = open("source_data.json")
source_data = json.load(f)
f.close()

#source_data = json.dumps(source_data, sort_keys=True, indent=4)

prev_name = ""
prev_out = 0

out_data = []

for event in edl.events:

    if event.next_event == None or event.clip_name != event.next_event.clip_name:

        name = event.clip_name

        tc.set_timecode(str(event.rec_end_tc))
        end = tc.mins * 60 + tc.secs + (tc.frs / 29.97)