示例#1
0
文件: mosh.py 项目: gsiegman/pymosh
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)
示例#2
0
文件: sort.py 项目: gsiegman/pymosh
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)
示例#3
0
def mosh(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
        interval = 2
        #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(open("moshed_" + filename,"w"))