Skip to content

Commit

Permalink
solved cut output format bug
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-g99 committed Oct 16, 2024
1 parent fcff3f0 commit 5d56575
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def on_download():

def on_trim():
try:
_trim_video(file_path=cut_file_path.get(), output_dir=cut_output_dir_path.get(), start_time=start_time.get(), end_time=end_time.get(), output_filename=cut_output_filename.get())
_trim_video(file_path=cut_file_path.get(), output_dir=cut_output_dir_path.get(), start_time=start_time.get(), end_time=end_time.get(), output_filename=cut_output_filename.get(), output_format=cut_format_var.get())
messagebox.showinfo("Success", "Video trimmed successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to trim video: {str(e)}")
Expand Down
28 changes: 2 additions & 26 deletions tubecut/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _download_video(url, output_dir, filename, format="mp4", audio_only=False):
ydl.download([url])
print(f"Download complete: {filename}.{format}")

def _trim_video(file_path, output_dir, start_time, end_time, output_filename):
def _trim_video(file_path, output_dir, start_time, end_time, output_filename, output_format):
if (start_time == "") and (end_time == ""):
raise Exception('Start Time and End Time cannot be both empty.')

Expand All @@ -42,11 +42,8 @@ def _trim_video(file_path, output_dir, start_time, end_time, output_filename):
os.makedirs(output_dir)

# Construct the full output file path and infer the output format
output_file = os.path.join(output_dir, output_filename)
output_file = os.path.join(output_dir, f'{output_filename}.{output_format}')

# Get the output format from the file extension (e.g., mp4, mp3, etc.)
output_format = output_filename.split('.')[-1] # Extract file extension (e.g., 'mp4', 'mp3')

# Trim the input file based on start_time and end_time
input_args = {}
if start_time != "":
Expand All @@ -59,24 +56,3 @@ def _trim_video(file_path, output_dir, start_time, end_time, output_filename):

print(f"Trimmed video/audio saved to: {output_file}")

# def _trim_video(file_path, output_dir, start_time, end_time, output_filename):

# if (start_time == "") and (end_time == ""):
# raise Exception('Start Time and End Time cannot be both empty.')

# # Ensure the output directory exists
# if not os.path.exists(output_dir):
# os.makedirs(output_dir)

# # Construct the full output file path
# output_file = os.path.join(output_dir, f'{output_filename}.mp4')


# if (start_time == ""):
# ffmpeg.input(file_path, to=end_time).output(output_file).run()
# elif (end_time == ""):
# ffmpeg.input(file_path, ss=start_time).output(output_file).run()
# else:
# ffmpeg.input(file_path, ss=start_time, to=end_time).output(output_file).run()


0 comments on commit 5d56575

Please sign in to comment.