Spaces:
Sleeping
Sleeping
cleanup
Browse files
app.py
CHANGED
|
@@ -19,20 +19,14 @@ def get_audio_metadata(file_path):
|
|
| 19 |
# Parse output for metadata
|
| 20 |
output = result.stderr
|
| 21 |
metadata = {
|
| 22 |
-
"Codec": None,
|
| 23 |
"Container": None,
|
|
|
|
| 24 |
"Channels": None,
|
|
|
|
| 25 |
"Sample Rate": None,
|
| 26 |
"Bitrate": None,
|
| 27 |
}
|
| 28 |
|
| 29 |
-
# Extract codec
|
| 30 |
-
if "Audio:" in output:
|
| 31 |
-
audio_line = [line for line in output.splitlines() if "Audio:" in line]
|
| 32 |
-
if audio_line:
|
| 33 |
-
audio_info = audio_line[0].split()
|
| 34 |
-
metadata["Codec"] = audio_info[audio_info.index("Audio:") + 1]
|
| 35 |
-
|
| 36 |
# Extract container format
|
| 37 |
if "Input #0," in output:
|
| 38 |
container_line = [line for line in output.splitlines() if "Input #0," in line]
|
|
@@ -40,10 +34,14 @@ def get_audio_metadata(file_path):
|
|
| 40 |
container_info = container_line[0].split()
|
| 41 |
metadata["Container"] = container_info[2].strip(',')
|
| 42 |
|
| 43 |
-
# Extract channels, sample rate, and bitrate
|
| 44 |
-
|
| 45 |
-
if "Audio:" in line
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
for item in audio_info:
|
| 48 |
if "Hz" in item:
|
| 49 |
metadata["Sample Rate"] = item.strip()
|
|
@@ -51,6 +49,8 @@ def get_audio_metadata(file_path):
|
|
| 51 |
metadata["Bitrate"] = item.strip()
|
| 52 |
if "stereo" in item or "mono" in item:
|
| 53 |
metadata["Channels"] = item.strip()
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return metadata
|
| 56 |
except Exception as e:
|
|
@@ -70,8 +70,8 @@ def create_interface():
|
|
| 70 |
fn=process_audio,
|
| 71 |
inputs=inputs,
|
| 72 |
outputs=outputs,
|
| 73 |
-
title="
|
| 74 |
-
description="Upload an audio file to extract its
|
| 75 |
)
|
| 76 |
return interface
|
| 77 |
|
|
|
|
| 19 |
# Parse output for metadata
|
| 20 |
output = result.stderr
|
| 21 |
metadata = {
|
|
|
|
| 22 |
"Container": None,
|
| 23 |
+
"Codec": None,
|
| 24 |
"Channels": None,
|
| 25 |
+
"Sample Format": None,
|
| 26 |
"Sample Rate": None,
|
| 27 |
"Bitrate": None,
|
| 28 |
}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Extract container format
|
| 31 |
if "Input #0," in output:
|
| 32 |
container_line = [line for line in output.splitlines() if "Input #0," in line]
|
|
|
|
| 34 |
container_info = container_line[0].split()
|
| 35 |
metadata["Container"] = container_info[2].strip(',')
|
| 36 |
|
| 37 |
+
# Extract codec, channels, sample format, sample rate, and bitrate
|
| 38 |
+
if "Audio:" in output:
|
| 39 |
+
audio_line = [line for line in output.splitlines() if "Audio:" in line]
|
| 40 |
+
if audio_line:
|
| 41 |
+
audio_info = audio_line[0].split()
|
| 42 |
+
metadata["Codec"] = audio_info[audio_info.index("Audio:") + 1]
|
| 43 |
+
|
| 44 |
+
audio_info = audio_line[0].split(",")
|
| 45 |
for item in audio_info:
|
| 46 |
if "Hz" in item:
|
| 47 |
metadata["Sample Rate"] = item.strip()
|
|
|
|
| 49 |
metadata["Bitrate"] = item.strip()
|
| 50 |
if "stereo" in item or "mono" in item:
|
| 51 |
metadata["Channels"] = item.strip()
|
| 52 |
+
if "s32" in item or "s16" in item or "flt" in item:
|
| 53 |
+
metadata["Sample Format"] = item.strip()
|
| 54 |
|
| 55 |
return metadata
|
| 56 |
except Exception as e:
|
|
|
|
| 70 |
fn=process_audio,
|
| 71 |
inputs=inputs,
|
| 72 |
outputs=outputs,
|
| 73 |
+
title="FFmpeg.info",
|
| 74 |
+
description="Upload an audio file to extract its container, codec, channels, sample format, sample rate, and bitrate using ffmpeg."
|
| 75 |
)
|
| 76 |
return interface
|
| 77 |
|