def test_compress_video():

    # Test series of video compressions and plot results
    data = load_cuprite()
    original_size = data.dtype.itemsize * data.size
    rel_errors = []
    compression_factors = []

    for quality in range(0, 55, 5):
        print(quality)
        start = time()
        compressed = other_compression.compress_video(data,
                                                      crf=quality,
                                                      preset="ultrafast")
        print("Time elapsed:", time() - start)
        decompressed = other_compression.decompress_video(compressed)
        rel_errors.append(
            np.linalg.norm(data - decompressed) / np.linalg.norm(data))
        compression_factors.append(
            original_size /
            other_compression.get_compress_video_size(compressed))
        print(rel_errors[-1])
        print(compression_factors[-1])

    print("rel_errors =", rel_errors)
    print("compression_factors =", compression_factors)
    plt.plot(rel_errors, compression_factors, "bo")
    plt.plot(rel_errors, compression_factors, "b")
    plt.show()
def make_video_mauna_kea_raw():

    data = load_mauna_kea_raw()
    quality = 0
    compressed = other_compression.compress_video(data, quality)

    with open("../data/mauna_kea_raw.mkv", "wb") as f:
        f.write(compressed[0])
def make_video_mauna_kea():

    data = load_mauna_kea()
    quality = 0
    compressed = other_compression.compress_video(data, quality)

    with open("../data/mauna_kea.mkv", "wb") as f:
        f.write(compressed[0])

    print(rel_error(other_compression.decompress_video(compressed), data))
def compare_times():

    data = load_cuprite()
    original_size = data.dtype.itemsize * data.size

    st_hosvd.print_compression_rate_tucker(
        data, st_hosvd.compress_tucker(data, 0.025))
    start = time()
    compressed = st_hosvd.compress_quantize2(
        st_hosvd.compress_tucker(data, 0.025))
    print("Time for compression:", time() - start)
    start = time()
    decompressed = st_hosvd.decompress_tucker(
        st_hosvd.decompress_quantize2(compressed))
    print("Time for decompression:", time() - start)
    st_hosvd.print_compression_rate_quantize2(data, compressed)
    print_difference(data, decompressed)

    start = time()
    compressed = other_compression.compress_jpeg(data, 50)
    print("Time for compression:", time() - start)
    start = time()
    decompressed = other_compression.decompress_jpeg(compressed)
    print("Time for decompression:", time() - start)
    print("Compressed size:",
          other_compression.get_compress_jpeg_size(compressed))
    print("Compression ratio:",
          other_compression.get_compress_jpeg_size(compressed) / original_size)
    print_difference(data, decompressed)

    start = time()
    compressed = other_compression.compress_video(data, 28)
    print("Time for compression:", time() - start)
    start = time()
    decompressed = other_compression.decompress_video(compressed)
    print("Time for decompression:", time() - start)
    print("Compressed size:",
          other_compression.get_compress_video_size(compressed))
    print(
        "Compression ratio:",
        other_compression.get_compress_video_size(compressed) / original_size)
    print_difference(data, decompressed)