aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.py')
-rw-r--r--src/util.py31
1 files changed, 4 insertions, 27 deletions
diff --git a/src/util.py b/src/util.py
index fd14e2e..7b012a2 100644
--- a/src/util.py
+++ b/src/util.py
@@ -1,6 +1,8 @@
import os
-import av
+import stat
+import ffmpeg
from kivy.utils import platform
+from kivy.app import App
def get_default_download_dir() -> str:
if platform == "android":
@@ -9,30 +11,5 @@ def get_default_download_dir() -> str:
from pathlib import Path
return os.path.join(str(Path.home()), "Downloads")
-# Chatgpt code (:
-# I use av instead of ffmpeg so I can run it on android.
def convert_mp4_to_mp3(input_file: str, output_file: str) -> None:
- # Open the input video file
- with av.open(input_file) as container:
- # Find the audio stream
- audio_stream = next(
- (stream for stream in container.streams if stream.type == 'audio'),
- None
- )
-
- if audio_stream is None:
- raise ValueError("No audio stream found in the input file")
-
- # Open an output file for writing
- with av.open(output_file, 'w') as output_container:
- # Create an audio stream in the output container
- output_audio_stream = output_container.add_stream('mp3')
-
- # Iterate through frames, decode audio, and encode into the output stream
- for frame in container.decode(audio_stream):
- # Encode the frame into the output stream
- output_packet = output_audio_stream.encode(frame)
-
- # Write the encoded packet to the output file
- if output_packet:
- output_container.mux(output_packet)
+ ffmpeg.input(input_file).output(output_file).run()