<commit_before># mosh.py: pymosh example
#
# This example uses pymosh to perform "standard" datamoshing: removing
# every I-frame but the first to blend all the motion in the video.
#
# Usage:
#   python mosh.py input_filename > output_filename

from pymosh.avi import AVIFile
from pymosh.mpeg4 import is_iframe
import sys

def mosh(filename):
    f = AVIFile(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:
            buf[0] = frame
        else:
            if is_iframe(frame):
                frame = buf[0]
            else:
                buf[0] = frame
        return frame

    # Modify the streams in place so the file can be rewritten.
    for i in range(len(f.streams)):
        stream = f.streams[i]
        if stream.type == 'vids':
            # Each I-frame is replaced by the following P-frame. Going
            # backwards makes this much less awkward. The first frame is kept
            # intact.
            f.streams[i] = map(process_frame, reversed(stream[1:])) + stream[:1]
            # Flip the frames back to the right order.
            f.streams[i].reverse()

    # Call rebuild_riff to recombine the modified streams and replace the AVI
    # index.<commit_msg>Cleaned up the example a little<commit_after># mosh.py: pymosh example
#
# This example uses pymosh to perform "standard" datamoshing: removing
# every I-frame but the first to blend all the motion in the video.
#
# Usage:
#   python mosh.py input_filename > output_filename

from pymosh.avi import AVIFile
from pymosh.mpeg4 import is_iframe
import sys

def mosh(filename):
    f = AVIFile(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

    # Modify the streams in place so the file can be rewritten.
    for stream in f:
        if stream.type == 'vids':
            # 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_riff to recombine the modified streams and replace the AVI
    # index.
{'fraction_non_alphanumeric': 0.08056872037914692, 'fraction_numerical': 0.004739336492890996, 'mean_word_length': 2.314009661835749, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6911809', 'n_tokens_mistral': 796, 'n_tokens_neox': 773, 'n_words': 313}