Skip to content

Commit

Permalink
feat: enhance vidinfo to handle mkv files and improve duration display
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Nov 13, 2024
1 parent 23d74fd commit 242b97d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Running tox will install hooks into the .tox directory. Keep this in my if you a
TODO: Add a cleanup function to undo this.

# Release Notes
* 1.5.3: `vidinfo` is now more robust and can now handle mkv files without crashing.
* 1.5.2: `codeup` now defaults for "yes" when asking if to include files.
* 1.5.0: New better `codeup`
* 1.4.100: Added `-y` to invocation of vidclip static_ffmpeg.
Expand Down
36 changes: 31 additions & 5 deletions src/zcmds/cmds/common/vidinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def get_videostream_info(videstream: dict) -> str:
lines.append(
f" Encoder: {videstream['codec_long_name']}, {videstream['codec_tag_string']}"
)

def get_duration_str() -> str:
dur = videstream.get("duration")
if not dur:
return "N/A"
duration = float(dur)
return format_duration(duration)

duration_string = get_duration_str()

# pix format
pix_fmt = videstream["pix_fmt"]
lines.append(f" Pixel format: {pix_fmt}")
Expand All @@ -69,13 +79,17 @@ def get_videostream_info(videstream: dict) -> str:
lines.append(f" B-Frames: {has_bframes}")
lines.append(f" Height: {videstream['height']}")
lines.append(f" Width: {videstream['width']}")
lines.append(f" Duration: {format_duration(float(videstream['duration']))}")
video_bitrate = videstream["bit_rate"]
lines.append(f" Duration: {duration_string}")
# video_bitrate = videstream["bit_rate"]
video_bitrate = videstream.get("bit_rate", "N/A")
if video_bitrate.isdigit():
video_bitrate = int(video_bitrate)
video_bitrate_str = f"{video_bitrate / 1000000:.2f} Mbps"
else:
video_bitrate_str = "N/A"
nb_frames_str = videstream.get("nb_frames", "N/A")
lines.append(f" Bitrate: {video_bitrate_str}")
lines.append(f" Frame count: {videstream['nb_frames']}")
lines.append(f" Frame count: {nb_frames_str}")
fr_num = int(videstream["r_frame_rate"].split("/")[0])
fr_den = int(videstream["r_frame_rate"].split("/")[1])
framerate = float(fr_num) / float(fr_den)
Expand All @@ -90,13 +104,25 @@ def get_audiostream_info(audiostream: dict) -> str:
lines.append(
f" Encoder: {audiostream['codec_long_name']}, {audiostream['codec_tag_string']}"
)

def get_duration_str() -> str:
dur = audiostream.get("duration")
if not dur:
return "N/A"
duration = float(dur)
return format_duration(duration)

duration_str = get_duration_str()
lines.append(f" Channels: {audiostream['channels']}")
lines.append(f" Duration: {format_duration(float(audiostream['duration']))}")
lines.append(f" Duration: {duration_str}")
lines.append(f" Sample rate: {audiostream['sample_rate']}")
audio_bitrate = audiostream["bit_rate"]
# audio_bitrate = audiostream["bit_rate"]
audio_bitrate = audiostream.get("bit_rate", "N/A")
if audio_bitrate.isdigit():
audio_bitrate = int(audio_bitrate)
audio_bitrate_str = f"{audio_bitrate / 1000:.2f} kbps"
else:
audio_bitrate_str = "N/A"
lines.append(f" Bitrate: {audio_bitrate_str}")
return "\n".join(lines)

Expand Down
2 changes: 1 addition & 1 deletion src/zcmds/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Just holds the version for the app"""

# Also change version in pyproject.toml
VERSION = "1.5.2" # pylint: disable=R0801
VERSION = "1.5.3" # pylint: disable=R0801
__version__ = VERSION

0 comments on commit 242b97d

Please sign in to comment.