Exemplo n.º 1
0
def test_stream_video_override():
    '''Ensure that streams do not override video files.'''
    TMP_FILE = get_tmp_file(extension='.raw')
    s = Stream(
        input_type='usb', id=SAMPLE_VIDEO, input_config={'fps': 10},
        output_type='raw', path=TMP_FILE,
        reading=False, writing=False,
    )
    s.start_reading()
    s.start_writing()
    time.sleep(2)
    s.stop_writing()
    s.stop_reading()

    time.sleep(1)

    s.start_reading()
    s.start_writing()
    tmp_path = s.writer.output.tmp_path
    time.sleep(2)
    s.stop_writing()
    s.stop_reading()

    s.stop()

    assert os.stat(TMP_FILE).st_size > 0
    assert os.stat(tmp_path).st_size > 0
    rm_tmp_dir()
Exemplo n.º 2
0
 def __init_file(self):
     # Create file if not exists
     # XXX implement rename_no_replace, this is a race with user creation
     if not os.path.exists(self.file_path):
         # Use rename to avoid inotify crate event event
         tmp = utils.get_tmp_file()
         open(tmp, 'w').close()
         os.rename(tmp, self.file_path)
Exemplo n.º 3
0
def wav_to_mp3(path):
    """Converts a WAVE file to an MP3 file.

  Args:
    pat: The path to a WAVE file.

  Returns:
    The generated MP3 file.
  """
    tmp_file = utils.get_tmp_file(path)
    os.system("/course/cs4500f13/bin/lame -h --quiet {0} {1}".format(utils.quote(path), utils.quote(tmp_file.name)))
    return tmp_file
def test_stream():
    '''
    Test an ffmeg stream: ffmpeg -> file
    '''
    try:
        s = Stream(
            input_type='ffmpeg',
            id=0,
            output_type='file',
            path=get_tmp_file(),
            reading=True,
            writing=True,
        )
    except Exception as e:
        pytest.skip(
            f'Test could not be run; stream initialization failed with error: {e}'
        )

    time.sleep(2)

    s.stop()

    assert os.stat(get_tmp_file()).st_size > 0
    rm_tmp_dir()
Exemplo n.º 5
0
def mp3_to_wav(path):
    """Converts an MP3 file to a WAVE file.

  Args:
    path: The path to an MP3 file.

  Returns:
    The generated WAVE file.
  """
    tmp_file = utils.get_tmp_file(path)
    os.system(
        "/course/cs4500f13/bin/lame --decode --mp3input --quiet {0} {1}".format(
            utils.quote(path), utils.quote(tmp_file.name)
        )
    )
    return tmp_file
Exemplo n.º 6
0
def stream_with_extension(extension):
    tmp_path = get_tmp_file(extension=extension)

    s = Stream(
        input_type='usb',
        id=SAMPLE_VIDEO,
        output_type='file',
        path=tmp_path,
        reading=True,
        writing=True,
    )
    time.sleep(2)

    s.stop()

    assert os.stat(tmp_path).st_size > 0
    rm_tmp_dir()
Exemplo n.º 7
0
def test_stream():
    '''
    Test an usb stream: usb -> file
    '''
    TMP_FILE = get_tmp_file(extension='.raw')
    s = Stream(
        input_type='raw_video',
        id=SAMPLE_RAW_VIDEO,
        output_type='file',
        path=TMP_FILE,
        reading=True,
        writing=True,
    )

    time.sleep(2)

    s.stop()

    assert os.stat(TMP_FILE).st_size > 0
    rm_tmp_dir()
Exemplo n.º 8
0
def normalize_wave_file(path):
    """Normalizes a WAVE file to single channel WAVE.

  Args:
    path: The path to a WAVE file.

  Returns:
    The normalized WAVE file.
  """
    global FREQUENCY, NUM_CHANNELS, SAMPLE_WIDTH
    # Read WAVE data
    wf = wave.open(path, "rb")
    (nchannels, sampwidth, framerate, nframes, comptype, compname) = wf.getparams()
    frames = wf.readframes(nframes)
    wf.close()
    # Create a temporary copy of it with new parameters
    tmp_file = utils.get_tmp_file(path)
    wf = wave.open(tmp_file.name, "wb")
    wf.setparams((NUM_CHANNELS, SAMPLE_WIDTH, FREQUENCY, nframes, "NONE", "NONE"))
    if nchannels != 1:
        frames = audioop.tomono(frames, sampwidth, 1, 1)
    wf.writeframes(frames)
    wf.close()
    return tmp_file
Exemplo n.º 9
0
 def test_file_deletion(self):
   """Tests that the file is deleted when it is closed."""
   self.tmp_file2 = utils.get_tmp_file('-')
   self.assertTrue(os.path.isfile(self.tmp_file2.name))
   self.tmp_file2.close()
   self.assertFalse(os.path.isfile(self.tmp_file2.name))
Exemplo n.º 10
0
 def setUp(self):
   """Creates a temporary file."""
   self.tmp_file = utils.get_tmp_file('_')