Skip to content

Commit 3d47984

Browse files
authored
Merge pull request #145 from openzim/ffmpeg_args
Do not modify ffmpeg original arguments but a copy
2 parents 453afc0 + a368d78 commit 3d47984

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Set a user-agent for `handle_user_provided_file` #103
13+
14+
### Changed
15+
16+
- Migrate to generic syntax in all std collections #140
17+
18+
### Fixed
19+
20+
- Do not modify the ffmpeg_args in reencode function #144
21+
1022
## [3.3.0] - 2024-02-14
1123

1224
### Added

src/zimscraperlib/video/encoding.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import subprocess
99
import tempfile
10+
from copy import deepcopy
1011
from typing import Optional
1112

1213
from zimscraperlib import logger
@@ -19,6 +20,7 @@ def _build_ffmpeg_args(
1920
ffmpeg_args: list[str],
2021
threads: Optional[int],
2122
) -> list[str]:
23+
ffmpeg_args = deepcopy(ffmpeg_args)
2224
if threads:
2325
if "-threads" in ffmpeg_args:
2426
raise AttributeError("Cannot set the number of threads, already set")

tests/video/test_encoding.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

33
import re
4+
from copy import deepcopy
45
from pathlib import Path
56
from typing import Optional
67

78
import pytest
89

910
from zimscraperlib.video.encoding import _build_ffmpeg_args
11+
from zimscraperlib.video.presets import VideoWebmLow
1012

1113

1214
@pytest.mark.parametrize(
@@ -94,3 +96,17 @@ def test_build_ffmpeg_args(
9496
ffmpeg_args=ffmpeg_args,
9597
threads=threads,
9698
)
99+
100+
101+
def test_ffmpeg_args_not_modified():
102+
"""_build_ffmpeg_args hould not alter the original ffmpeg_args"""
103+
preset = VideoWebmLow()
104+
ffmpeg_args = preset.to_ffmpeg_args()
105+
ffmpeg_args_orig = deepcopy(ffmpeg_args)
106+
src_path = Path("file1.mp4")
107+
tmp_path = Path("file2.mp4")
108+
109+
_build_ffmpeg_args(
110+
src_path=src_path, tmp_path=tmp_path, ffmpeg_args=ffmpeg_args, threads=1
111+
)
112+
assert ffmpeg_args == ffmpeg_args_orig

0 commit comments

Comments
 (0)