<commit_before>"""Collection of test helpers."""
from fractions import Fraction
import io

import av
import numpy as np

AUDIO_SAMPLE_RATE = 8000


def generate_h264_video(container_format="mp4", audio_codec=None):
    """
    Generate a test video.

    See: http://docs.mikeboers.com/pyav/develop/cookbook/numpy.html
    """

    def generate_audio_frame(pcm_mulaw=False):
        """Generate a blank audio frame."""
        if pcm_mulaw:
            audio_frame = av.AudioFrame(format="s16", layout="mono", samples=1)
            audio_bytes = b"\x00\x00"
        else:
            audio_frame = av.AudioFrame(format="dbl", layout="mono", samples=1024)
            audio_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00" * 1024
        audio_frame.planes[0].update(audio_bytes)
        audio_frame.sample_rate = AUDIO_SAMPLE_RATE
        audio_frame.time_base = Fraction(1, AUDIO_SAMPLE_RATE)
        return audio_frame

    duration = 5
    fps = 24
    total_frames = duration * fps

    output = io.BytesIO()
    output.name = "test.mov" if container_format == "mov" else "test.mp4"
    container = av.open(output, mode="w", format=container_format)

    stream = container.add_stream("libx264", rate=fps)
    stream.width = 480
    stream.height = 320
    stream.pix_fmt = "yuv420p"

    a_packet = None<commit_msg>Fix I-frame interval in stream test video (#47638)<commit_after>"""Collection of test helpers."""
from fractions import Fraction
import io

import av
import numpy as np

AUDIO_SAMPLE_RATE = 8000


def generate_h264_video(container_format="mp4", audio_codec=None):
    """
    Generate a test video.

    See: http://docs.mikeboers.com/pyav/develop/cookbook/numpy.html
    """

    def generate_audio_frame(pcm_mulaw=False):
        """Generate a blank audio frame."""
        if pcm_mulaw:
            audio_frame = av.AudioFrame(format="s16", layout="mono", samples=1)
            audio_bytes = b"\x00\x00"
        else:
            audio_frame = av.AudioFrame(format="dbl", layout="mono", samples=1024)
            audio_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00" * 1024
        audio_frame.planes[0].update(audio_bytes)
        audio_frame.sample_rate = AUDIO_SAMPLE_RATE
        audio_frame.time_base = Fraction(1, AUDIO_SAMPLE_RATE)
        return audio_frame

    duration = 5
    fps = 24
    total_frames = duration * fps

    output = io.BytesIO()
    output.name = "test.mov" if container_format == "mov" else "test.mp4"
    container = av.open(output, mode="w", format=container_format)

    stream = container.add_stream("libx264", rate=fps)
    stream.width = 480
    stream.height = 320
    stream.pix_fmt = "yuv420p"
    stream.options.update({"g": str(fps), "keyint_min": str(fps)})

    a_packet = None
{'fraction_non_alphanumeric': 0.11951754385964912, 'fraction_numerical': 0.04349415204678363, 'mean_word_length': 3.0789865871833086, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '2956515', 'n_tokens_mistral': 1007, 'n_tokens_neox': 912, 'n_words': 188}