def __init__(self, saveFolder=None): self.file = '' self.file_size = 0 self.frame_rate = 0 self._play_bits = 0 self.overwrite = False self.app_running = True self._not_paused = True self.playing = False self._not_stopped = False self.t_size = 0 self.tt_played = 0 self.volume_val = 1.4 self._seek_int = 0 parent_folder = os.path.dirname(__file__) temp_folder = os.path.join(Paths().temp, 'soloman', 'audio') if saveFolder: self.save_folder = os.path.realpath(saveFolder) else: self.save_folder = os.path.realpath( os.path.join(temp_folder, 'data', 'music', 'saves')) if not os.path.exists(self.save_folder): os.makedirs(self.save_folder) self.ff = FFmpeg(self.save_folder) self.ff.overwrite = False
def __init__(self, parent=None, frames_per=None): super().__init__(parent) temp_f = Paths().temp self.convert_folder = self.fix_splashes(temp_f) + '/soloman/convert' self.temp_folder = self.convert_folder + '/temp' + str(randrange(1, 1000000)) os.makedirs(self.temp_folder) self._same_session = False # FFmpeg self._ffmpeg_inst = FFmpeg() # Video self._source = '' self._curr_file = "" self.folder = "" self._current_frame = '' if frames_per: self.fps = frames_per else: self.fps = 29.97 self._frame_no = 0 self._supported_vid_files = [ 'mp4', "asf", "avi", "flv", "gif", "mov", "3gp", "3gpp", "mkv", "webm"] self._user_stills = False self._stills_content = [] self._curr_stills_index = 0 self._stills_len = 10000000 self._stills_type = "" self._stills_converted = False self.sync = True self._seeked = False self._seek_frame = 0 self._seek_calls = 0 # Audio self._audio_inst = Audio(saveFolder=self.temp_folder) self._has_audio = True self._play_audio = True self._sync_audio = True self.auto_sync_time: int = 3 # controls self._stopped = False self._paused = False # Timer self._start_time = 0 self._total_time = 0 self._total_elapsed_time = 0.0 # Opencv self._cv2_frames_len = 0 self._cv2_tmp_frames_len = 0 self._cv2_session = False # Qml property self._aspect_ratio = True self._current_frame = '' self._delay = 0.0 self._duration: str = '' self._tile = 0 self._tile_enumeration = False
def test_loglevel(): ff = FFmpeg() ff.loglevel = 'fa' path = "./" o = os.path.join(path, 'f.wav') opt = ['-i', i, o] ff.options(opt) assert ff.loglevel != 'fa'
def test_save_directory(): """ Test to see if save directory is used """ sav_dir = 'H:\\FakePath' ffmpeg = FFmpeg(sav_dir) if ffmpeg: assert ffmpeg.save_dir == sav_dir else: assert False
def test_options(): path = os.path.join(cwd, '_test') #i = os.path.join(path, 'f.mp3') o = os.path.join(path, 'f.wav') opt = ['-i', i, o] a = FFmpeg() ret = a.options(opt) #os.remove(o) assert b'' == ret
def test_loglevel(): ff = FFmpeg() ff.loglevel = 'fa' path = os.path.join(cwd, '_test') #i = os.path.join(path, 'f.mp3') o = os.path.join(path, 'f.wav') opt = ['-i', i, o] ff.options(opt) assert ff.loglevel != 'fa'
def download_video(resolution, file_dir, subtitles, prefformat, output_type, vid_url): ff = FFmpeg() current_time = int(time.time()) video = YouTube(vid_url) underscore_name = video.title.replace(" ", "_") if not file_dir: file_dir = os.getcwd() download_object = video.streams.filter(resolution=resolution, file_extension="mp4", progressive=True).first() if download_object: print("[INFO] Progressive stream found. Direct download available") download_object.download(filename=video.title, output_path=file_dir) sg.Popup("Success", "Video successfully downloaded!") else: print( "[INFO] Progressive stream not found. Searching for adaptive streams." ) audio_object = video.streams.filter(only_audio=True, mime_type="audio/mp4").first() video_object = video.streams.filter(resolution=resolution, file_extension="mp4").first() try: print("[INFO] Audio Downloading") audio_object.download(filename=f'audio-{current_time}') print("[INFO] Video Downloading") video_object.download(filename=f'video-{current_time}') except AttributeError as download_error: # It technically shouldn't be possible to get here (using res check) print("[ERROR] Couldn't find stream at desired resolution.") sg.Popup( "Download fail", "Couldn't find a stream at your desired resolution. Choose a lower quality" ) return try: ff.options( f'-i audio-{current_time}.mp4 -i video-{current_time}.mp4 -acodec copy -vcodec copy {file_dir}/{underscore_name}.{prefformat}' ) except: # Horrible hack to fix videos with filenames that break pyffmpeg print( "[WARN] Error whilst converting. Defaulting back to generic filename" ) ff.options( f'-i audio-{current_time}.mp4 -i video-{current_time}.mp4 -acodec copy -vcodec copy {file_dir}/download-{current_time}.{prefformat}' ) print("[INFO] Cleaning up...") os.remove(f'audio-{current_time}.mp4') os.remove(f'video-{current_time}.mp4') sg.Popup("Success!", "Video downloaded!") return
def test_get_ffmpeg_bin(): sys = system() if sys == 'Windows': folder = 'win32\\ffmpeg.exe' elif sys == 'Linux': folder = 'linux/ffmpeg' else: folder = 'darwin/ffmpeg' f_path = os.path.join(cwd, 'pyffmpeg', '.', 'static', 'bin', folder) bin_path = FFmpeg().get_ffmpeg_bin() assert f_path == bin_path
def test_convert(): """ """ path = os.path.join(cwd, '_test') #i = os.path.join(path, 'f.mp3') o = os.path.join(path, 'f.wav') a = FFmpeg() ret = a.convert(i, o) #os.remove(o) assert ret == o
def download_playlist_video(url, resolution, file_dir, prefformat): ff = FFmpeg() if not file_dir: file_dir = os.getcwd() current_time = int(time.time()) print(f'[INFO] Attempting to download {url} at max resolution') video = YouTube(url) underscore_name = video.title.replace(" ", "_") max_res = calculate_available_resolutions(video) if max_res[-1] == "1080p": video_object = video.streams.filter(resolution="1080p", file_extension="mp4").first() audio_object = video.streams.filter(only_audio=True, mime_type="audio/mp4").first() try: video_object.download(filename=f'video-{current_time}') audio_object.download(filename=f'audio-{current_time}') except: sg.Popup("Error", f'Error downloading {video.title}. Sorry!') return try: ff.options( f'-i audio-{current_time}.mp4 -i video-{current_time}.mp4 -acodec copy -vcodec copy {file_dir}/{underscore_name}.{prefformat}' ) os.remove(f'audio-{current_time}.mp4') os.remove(f'video-{current_time}.mp4') print("[INFO] Downloaded and converted 1080p video!") return except: # Horrible hack print( "[WARN] Error whilst converting. Defaulting back to generic filename" ) ff.options( f'-i audio-{current_time}.mp4 -i video-{current_time}.mp4 -acodec copy -vcodec copy {file_dir}/download-{current_time}.{prefformat}' ) os.remove(f'audio-{current_time}.mp4') os.remove(f'video-{current_time}.mp4') print("[INFO] Downloaded and converted 1080p video (generic name)") return else: video_object = video.streams.filter(resolution=max_res[-1], progressive=True, file_extension="mp4").first() print("[INFO] Attempting to download video object") video_object.download(output_path=file_dir) print("[INFO] Video object downloaded") return
def test_options(): path = Paths().home_path o = os.path.join(path, 'f.wav') opt = ['-i', i, o] ff = FFmpeg() print(f'in and out: {i}, {o}') ret = ff.options(opt) if ff.error: if 'Output' in ff.error: assert True else: print(ff.error) assert False else: assert True
def test_convert(): """ """ path = Paths().home_path out = os.path.join(path, 'f.wav') ff = FFmpeg() ff.loglevel = 'info' print(f'in and out: {i}, {out}') ff.convert(i, out) if ff.error: if 'Output' in ff.error: assert True else: print(ff.error) assert False else: assert True
from pyffmpeg import FFmpeg ff = FFmpeg() out = ff.convert('H:\\GitHub\\pyffmpeg\\_test\\f.mp3', 'H:\\GitHub\\pyffmpeg\\_test\\f.wav') fps = ff.get_fps("H:/CS/practice/python/pyffmpeg subproces/vid.mp4") print(out, fps)
def convert(base): ff = FFmpeg() ff.convert(base + '.mp4', base + '.mp3')
def test_get_ffmpeg_bin(): home_path = load_ffmpeg_bin() bin_path = FFmpeg().get_ffmpeg_bin() assert home_path == bin_path