import os
import subprocess

def ffmpeg_version():
    p = subprocess.Popen(["ffmpeg", "-version"], stdout=subprocess.PIPE)
    out = p.stdout.read()

    return out

def ffmpeg_thumbnail(video_file_path, tumbnail_path):
    print("Creating thumbnail...")
    cmd = [
        "ffmpeg",
        "-i",
        video_file_path,
        "-ss",
        "00:00:01.000",
        "-vframes",
        "1",
        tumbnail_path
    ]
    print(f"Command: {cmd}")
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    out = p.stdout.read()

    return out

def ffmpeg_gif(video_file_path, gif_path):
    print("Creating gif...")
    cmd = [
        "ffmpeg",
        "-i",
        video_file_path,
        "-ss",
        "1.0",
        "-t",
        "2.0",
        "-f",
        "gif",
        gif_path
    ]
    print(f"Command: {cmd}")
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    out = p.stdout.read()

    return out
