Skip to content

Commit

Permalink
Merge pull request #145 from openzim/ffmpeg_args
Browse files Browse the repository at this point in the history
Do not modify ffmpeg original arguments but a copy
  • Loading branch information
benoit74 authored Feb 27, 2024
2 parents 453afc0 + a368d78 commit 3d47984
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Set a user-agent for `handle_user_provided_file` #103

### Changed

- Migrate to generic syntax in all std collections #140

### Fixed

- Do not modify the ffmpeg_args in reencode function #144

## [3.3.0] - 2024-02-14

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/zimscraperlib/video/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import subprocess
import tempfile
from copy import deepcopy
from typing import Optional

from zimscraperlib import logger
Expand All @@ -19,6 +20,7 @@ def _build_ffmpeg_args(
ffmpeg_args: list[str],
threads: Optional[int],
) -> list[str]:
ffmpeg_args = deepcopy(ffmpeg_args)
if threads:
if "-threads" in ffmpeg_args:
raise AttributeError("Cannot set the number of threads, already set")
Expand Down
16 changes: 16 additions & 0 deletions tests/video/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

import re
from copy import deepcopy
from pathlib import Path
from typing import Optional

import pytest

from zimscraperlib.video.encoding import _build_ffmpeg_args
from zimscraperlib.video.presets import VideoWebmLow


@pytest.mark.parametrize(
Expand Down Expand Up @@ -94,3 +96,17 @@ def test_build_ffmpeg_args(
ffmpeg_args=ffmpeg_args,
threads=threads,
)


def test_ffmpeg_args_not_modified():
"""_build_ffmpeg_args hould not alter the original ffmpeg_args"""
preset = VideoWebmLow()
ffmpeg_args = preset.to_ffmpeg_args()
ffmpeg_args_orig = deepcopy(ffmpeg_args)
src_path = Path("file1.mp4")
tmp_path = Path("file2.mp4")

_build_ffmpeg_args(
src_path=src_path, tmp_path=tmp_path, ffmpeg_args=ffmpeg_args, threads=1
)
assert ffmpeg_args == ffmpeg_args_orig

0 comments on commit 3d47984

Please sign in to comment.