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

Fix VP8 low bitrate #122

Merged
merged 9 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a small utility to encode a video as scraper would do
  • Loading branch information
benoit74 committed Feb 13, 2024
commit 2fc4061ba5ff7f46dc5fd70f04bb720d23694930
3 changes: 3 additions & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

This folder contains some tooling around zimscraperlib:
- `encode_video.py`: a small utility to encode a video with an existing video preset, just like a scraper would do
42 changes: 42 additions & 0 deletions contrib/encode_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
from pathlib import Path
from typing import List

from zimscraperlib import logger
from zimscraperlib.video import presets, reencode


def encode_video(src_path: Path, dst_path: Path, preset: str):
if not src_path.exists():
raise ValueError(f"{src_path} does not exists")
try:
preset_cls = getattr(presets, preset)
except AttributeError:
logger.error(f"{preset} preset not found")
raise
logger.info(f"Encoding video {src_path} with {preset} version {preset_cls.VERSION}")
success, process = reencode(
src_path=src_path,
dst_path=dst_path,
ffmpeg_args=preset_cls().to_ffmpeg_args(),
with_process=True,
) # pyright: ignore[reportGeneralTypeIssues] (returned type is variable, depending on `with_process` value)
if not success:
logger.error(f"conversion failed:\n{process.stdout}")


def run(args: List[str] = sys.argv):
if len(args) < 4: # noqa: PLR2004
print(f"Usage: {args[0]} <src_path> <dst_path> <preset>") # noqa: T201
print( # noqa: T201
"\t<src_path>\tpath to the video to encode."
"\t<dst_path>\tpath to the store the reencoded video."
"\t<preset>\tname of preset to use."
)
return 1
encode_video(Path(args[1]), Path(args[2]), args[3])
return 0


if __name__ == "__main__":
sys.exit(run())
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ target-version = ['py38']
[tool.ruff]
target-version = "py38"
line-length = 88
src = ["src"]
src = ["src", "contrib"]

[tool.ruff.lint]
select = [
Expand Down Expand Up @@ -235,7 +235,7 @@ exclude_lines = [
]

[tool.pyright]
include = ["src", "tests", "tasks.py"]
include = ["contrib", "src", "tests", "tasks.py"]
exclude = [".env/**", ".venv/**"]
extraPaths = ["src"]
pythonVersion = "3.8"
Expand Down