Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/cleanup video container/codec options. #341

Merged
merged 5 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<!-- 0.11.0 -->

# Changes
- Add more fine-grained options for video container/codec selection.

## Fixes

## Features

<!-- 0.10.0 -->

# Changes
Expand Down
77 changes: 39 additions & 38 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/usdb_syncer/gui/forms/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label_video_container">
<property name="text">
<string>Container:</string>
<string>Container/codec:</string>
</property>
</widget>
</item>
Expand All @@ -501,6 +501,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;For &lt;span style=&quot; font-weight:700;&quot;&gt;UltraStar deluxe&lt;/span&gt;, &lt;span style=&quot; font-weight:700;&quot;&gt;Performous&lt;/span&gt;, &lt;span style=&quot; font-weight:700;&quot;&gt;Vocaluxe&lt;/span&gt; or other ffmpeg-based karaoke softwares, choose &amp;quot;Best available container/codec&amp;quot; or &amp;quot;mp4 (best available codec)&amp;quot; if you prefer to have an mp4 container.&lt;/p&gt;&lt;p&gt;For &lt;span style=&quot; font-weight:700;&quot;&gt;UltraStar CMD&lt;/span&gt; (Windows), &lt;span style=&quot; font-weight:700;&quot;&gt;Melody Mania&lt;/span&gt; (Windows) and low-power computers, choose &amp;quot;mp4 (AVC/H.264).&lt;/p&gt;&lt;p&gt;Otherwise, select a container/codec option that your software supports.&lt;/p&gt;&lt;p&gt;If the selected container/format option is not available for a given song, the syncer will try to at least get the requested container, and if that is not available either, it will fallback to the best available container/codec.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
Expand Down
34 changes: 22 additions & 12 deletions src/usdb_syncer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,32 +381,42 @@ def cookies(self) -> CookieJar | None:
class VideoContainer(Enum):
"""Video containers that can be requested when downloading with ytdl."""

BEST = "bestvideo"
MP4 = "mp4"
MP4_NO_VP9 = "mp4_no_vp9"
MP4_AV1 = "mp4_av1"
MP4_AVC = "mp4_avc"
MP4_VP9 = "mp4_vp9"
WEBM = "webm"
BEST = "bestvideo"

def __str__(self) -> str:
match self:
case VideoContainer.BEST:
return "Best available container/codec"
case VideoContainer.MP4:
return ".mp4 (any codec)"
case VideoContainer.MP4_NO_VP9:
return ".mp4 (no VP9)"
return ".mp4 (best available codec)"
case VideoContainer.MP4_AV1:
return ".mp4 (AV1 codec)"
case VideoContainer.MP4_AVC:
return ".mp4 (AVC/H.264 codec)"
case VideoContainer.MP4_VP9:
return ".mp4 (VP9 codec)"
case VideoContainer.WEBM:
return ".webm (VP9)"
case VideoContainer.BEST:
return "Best available"
return ".webm (VP9 codec)"
case _ as unreachable:
assert_never(unreachable)

def ytdl_format(self) -> str:
match self:
case VideoContainer.MP4 | VideoContainer.WEBM:
return f"bestvideo*[ext={self.value}]"
case VideoContainer.MP4_NO_VP9:
return "bestvideo*[ext=mp4][vcodec!~='vp0?9']"
case VideoContainer.BEST:
return "bestvideo*"
case VideoContainer.MP4 | VideoContainer.WEBM:
return f"bestvideo*[ext={self.value}]/bestvideo*"
case VideoContainer.MP4_AV1:
return "bestvideo*[ext=mp4][vcodec~='^av01']/bestvideo*[ext=mp4]/bestvideo*"
case VideoContainer.MP4_AVC:
return "bestvideo*[ext=mp4][vcodec~='^(avc|h264)']/bestvideo*[ext=mp4]/bestvideo*"
case VideoContainer.MP4_VP9:
return "bestvideo*[ext=mp4][vcodec~='^vp0?9']/bestvideo*[ext=mp4]/bestvideo*"
case _ as unreachable:
assert_never(unreachable)

Expand Down