Exemplo n.º 1
0
def overlay(old_filename_1, old_filename_2, new_filename):
    '''Creates an avi where the motion of old_filename_2 is layed over old_filename_1'''
    size = find_image_size(old_filename_1)
    if size != find_image_size(old_filename_2): #If the avi's have different dimensions, send an error and terminate function
        return 'Please only overlay gifs of the same dimensions'
    e = Index(old_filename_1) #Allows first old avi to be accessed by pymosh
    f = Index(old_filename_2) #Allows second old avi to be accessed by pymosh
    write_shell(count_frames(e)+count_frames(f), find_frame_duration(old_filename_1), size) #Creates a blank avi to be written into

    buf = [None] #Stores most recent p-frame, to be used when processing frames

    g = Index("shell.avi") #Allows the shell avi to be written into by pymosh
    newstream = [] #A list to store frames in, is later turned into the final avi
    for stream in e.video: #Puts all of first avi's frames into newstream, processing each frame
        newstream.append(process_frame(stream[0], buf))
        ix = 0
        for i in stream[1:]:
            ix+=1
            newstream.append(process_frame(stream[ix], buf))
    for stream in f.video: #Puts all of second avi's frames into newstream, processing each frame
        ix = 0
        for i in stream:
            newstream.append(process_frame(stream[ix], buf))
            ix+=1
    for stream in g.video: #Replaces shell's black frames with old avi's frames
        stream.replace(newstream)
    g.rebuild()
    g.write(new_filename) #Writes final avi
    os.remove(os.getcwd() + "/shell.avi") #Deletes shell avi created by write_shell
Exemplo n.º 2
0
def mosh(filename):
    f = Index(filename)

    buf = [None]  # So I can assign to the closed-over buffer

    def process_frame(frame):
        """Process a frame, holding onto one P-frame at a time, which is used to
        replace any I-frames encountered."""
        if buf[0] == None or not is_iframe(frame):
            buf[0] = frame
        else:
            frame = buf[0]
        return frame

    for stream in f.video:
        # Each I-frame is replaced by the following P-frame. Going
        # backwards makes this much less awkward. The first frame is kept
        # intact.
        newstream = map(process_frame, reversed(stream[1:])) + stream[:1]
        # Flip the frames back to the right order.
        newstream.reverse()
        stream.replace(newstream)

    # Call rebuild to recombine the modified streams and perform any other
    # maintenance the file format needs for clean output.
    f.rebuild()

    # Finally, write the modified file to stdout.
    f.write(sys.stdout)
Exemplo n.º 3
0
def avi_sort(filename):
    f = Index(filename)

    for stream in f.video:
        sorted_stream = sorted(stream, key=len, reverse=True)
        stream.replace(sorted_stream)

    f.rebuild()
    f.write(sys.stdout)
Exemplo n.º 4
0
def shmear(old_filename, new_filename):
    '''Creates an avi with each of the P-frames doubled.'''
    f = Index(old_filename) #Allows original avi to be accessed by pymosh
    write_shell(count_frames(f)*2-1, find_frame_duration(old_filename), find_image_size(old_filename)) #Creates a blank avi to be written into

    buf = [None] #Stores most recent p-frame, to be used when processing frames

    g = Index("shell.avi") #Allows the shell avi to be written into by pymosh
    for stream in f.video: #Puts each motion frame from the old avi twice into the new avi
        newstream = []
        newstream.append(stream[0])
        ix = 0
        for i in stream[1:]:
            ix+=1
            newstream.append(process_frame(stream[ix], buf))
            newstream.append(process_frame(stream[ix], buf))
        for gstream in g.video: #Replaces shell's black frames with old avi's frames
            gstream.replace(newstream)
    g.rebuild()
    g.write(new_filename) #Writes final avi
    os.remove(os.getcwd() + "/shell.avi") #Deletes shell avi created by write_shell
Exemplo n.º 5
0
def mosh(filename):
    f = Index(filename)
    buf = [None]  # So I can assign to the closed-over buffer

    def process_frame(frame):
        """Process a frame, holding onto one P-frame at a time, which is used to
		replace any I-frames encountered."""
        if buf[0] == None or not is_iframe(frame):
            buf[0] = frame
        else:
            frame = buf[0]
            print(frame)
        return frame

    for stream in f.video:
        # Each I-frame is replaced by the following P-frame. Going
        # backwards makes this much less awkward. The first frame is kept
        # intact.
        newstream = map(process_frame, reversed(stream[1:])) + stream[:1]
        # Flip the frames back to the right order.
        newstream.reverse()
        print(f)
        stream.replace(newstream)
        # Call rebuild to recombine the modified streams and perform any other
        # maintenance the file format needs for clean output.
    f.rebuild()
    print(stream)
    # Finally, write the modified file to stdout.
    f.write(sys.stdout)
    write_data = time.strftime("%I%M%S")
Exemplo n.º 6
0
def bloom(old_filename, new_filename, wait, bloom):
    '''Creates an avi that behaves normally for (wait) frames, copies the frame after the wait for (bloom) frames, and then continues normally until the end of the avi''' 
    f = Index(old_filename) #Allows original avi to be accessed by pymosh
    write_shell(count_frames(f)+bloom, find_frame_duration(old_filename), find_image_size(old_filename)) #Creates a blank avi to be written into

    buf = [None] #Stores most recent p-frame, to be used when processing frames
    
    g = Index("shell.avi") #Allows the shell avi to be written into by pymosh
    for stream in f.video: #Puts the frames from the old avi in the desired order in newstream
        newstream = []
        newstream.append(stream[0])
        ix = 0
        for i in stream[1:]:
            ix+=1
            newstream.append(process_frame(stream[ix], buf))
            if ix == wait:
                for i in range(bloom):
                    newstream.append(newstream[-1])
        for gstream in g.video: #Replaces shell's black frames with old avi's frames
            gstream.replace(newstream)
    g.rebuild()
    g.write(new_filename) #Writes final avi
    os.remove(os.getcwd() + "/shell.avi") #Deletes shell avi created by write_shell
Exemplo n.º 7
0
def process_streams(in_filename, out_filename, func, *args, **kwargs):
    f = Index(in_filename)

    for stream in f.video:
        drifted = list(func(stream, *args, **kwargs))
        stream.replace(drifted)

    f.rebuild()
    f.write(open(out_filename, 'wb'))
Exemplo n.º 8
0
def avi_sort(filename):
    f = Index(filename)

    for stream in f.video:
        sorted_stream = sorted(stream, key=len, reverse=True)
        stream.replace(sorted_stream)

    f.rebuild()
    f.write(sys.stdout)
Exemplo n.º 9
0
def mosh(interval, filename):
    f = Index(filename) #loads in the index of frames in the given avi file

    buf = [None] # So I can assign to the closed-over buffer
    def process_frame(frame):
        """Process a frame, holding onto one P-frame at a time, which is used to
        replace any I-frames encountered."""
        #if there is no frame in buf or the frame is not i-frame
        if buf[0] == None or not is_iframe(frame):
            #then buf is the seen p-frame 
            buf[0] = frame 
        else:
            #if it IS an iframe then use the buf'ers pframe
            frame = buf[0]
        #return the frame
        return frame
    #we use the list of frames in the loaded file
    for stream in f.video:
        #make a new list to put in frames YOU decide
        newstream = []
        #append it with a i-frame to make it load fine in video player
        newstream.append(stream[0])
        #two variables for counting frames and interval
        ix = 0
        jx = 0
        #stream is reduced by one since we have allready added one frame above
        for i in stream[1:]:
            ix += 1
            jx += 1
            #if ix the counter of interval is < interval select normal frames
            if ix < interval:
                newstream.append(process_frame(stream[jx]))
            #else bleed the reached frame for interval time
            else:
                newstream.append(newstream[-1])
            #init interval
            if ix > interval * 2:
                ix = 0
        #replace original stream with same length newstream
        stream.replace(newstream)

    # Call rebuild to recombine the modified streams and perform any other
    # maintenance the file format needs for clean output.
    f.rebuild()

    # Finally, write the modified file .
    f.write("moshed_" + os.path.basename(filename))