Added tests and more
This commit is contained in:
1 parent
295177be6f
commit
a7a7abf720
9 files changed
+1327
No files matched your search
@@ -0,0 +1,33 @@
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
def get_audio_duration(file_path: Path):
|
||||
"""
|
||||
Get the actual duration of the first audio stream by asking ffprobe
|
||||
to count packets/frames if the stream metadata is missing.
|
||||
Returns duration in seconds.
|
||||
"""
|
||||
|
||||
# As a last resort, use the format duration
|
||||
result = subprocess.run([
|
||||
"ffprobe",
|
||||
"-v", "error",
|
||||
"-select_streams", "a:0",
|
||||
"-show_entries", "stream_tags=DURATION",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||
file_path
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
)
|
||||
result = result.stdout.strip().split(":")[::-1]
|
||||
# if DEBUG: print(f"audio duration: {result}")
|
||||
res = 0
|
||||
if not result:
|
||||
raise ValueError(f"Could not extract length")
|
||||
for i in range(len(result)):
|
||||
res += float(result[i])*(60**i)
|
||||
return res
|
||||
|
||||
printget_audio_duration(Path("/home/honney/mount/Media/tmp/serien/ready/Classroom of the Elite/Season 01/E01_original_audio2.mka"))
|
||||
Reference in new issue
Block a user