import sys, getopt, os
import subprocess
#from pathlib import Path
import glob
import time
import os.path


table_name="2m" #os.getenv('channel_name')

segment = str(sys.argv[1])


#def script_3(table_name,segment):
if os.path.isfile(table_name+'/'+segment) and ".ts" in segment:
    duration = 6
    ts = time.time()
    ts = "."+str(ts).split('.')[0]
    now = str(segment).split('.')[0]
    home = os.path.expanduser("~")
    ffmpeg = 'ffmpeg'
    cwd = os.getcwd()
    cmd = "ffmpeg -y -i "+table_name+'/'+segment+" -vf 'select=gt(scene\,0.10)' -vsync vfr -frame_pts true 2m/iframes_live/"+now+str(ts)+"_%d_"+str(duration)+".png"
    # print(cmd)
    os.system(cmd)