-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to allow capture stderr from ffmpeg/ffprobe (#565)
* feat: add option to allow capture stderr from ffmpeg/ffprobe * add tests * fix tests * add comments * fix decoding error * fix * fix
- Loading branch information
Tao Peng
authored
Oct 11, 2022
1 parent
2bb2ef6
commit 2f3331c
Showing
2 changed files
with
151 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from mapillary_tools import ffmpeg | ||
|
||
|
||
def ffmpeg_installed(): | ||
ffmpeg_path = os.getenv("MAPILLARY_TOOLS_FFMPEG_PATH", "ffmpeg") | ||
ffprobe_path = os.getenv("MAPILLARY_TOOLS_FFPROBE_PATH", "ffprobe") | ||
try: | ||
subprocess.run([ffmpeg_path, "-version"]) | ||
# In Windows, ffmpeg is installed but ffprobe is not? | ||
subprocess.run([ffprobe_path, "-version"]) | ||
except FileNotFoundError: | ||
return False | ||
return True | ||
|
||
|
||
is_ffmpeg_installed = ffmpeg_installed() | ||
|
||
|
||
def test_ffmpeg_not_exists(): | ||
if not is_ffmpeg_installed: | ||
pytest.skip("ffmpeg not installed") | ||
|
||
ff = ffmpeg.FFMPEG() | ||
try: | ||
ff.extract_frames(Path("not_exist_a"), Path("not_exist_b"), sample_interval=2) | ||
except ffmpeg.FFmpegCalledProcessError as ex: | ||
assert "STDERR:" not in str(ex) | ||
else: | ||
assert False, "FFmpegCalledProcessError not raised" | ||
|
||
ff = ffmpeg.FFMPEG(stderr=subprocess.PIPE) | ||
try: | ||
ff.extract_frames(Path("not_exist_a"), Path("not_exist_b"), sample_interval=2) | ||
except ffmpeg.FFmpegCalledProcessError as ex: | ||
assert "STDERR:" in str(ex) | ||
else: | ||
assert False, "FFmpegCalledProcessError not raised" | ||
|
||
|
||
def test_ffprobe_not_exists(): | ||
if not is_ffmpeg_installed: | ||
pytest.skip("ffmpeg not installed") | ||
|
||
ff = ffmpeg.FFMPEG() | ||
try: | ||
x = ff.probe_format_and_streams(Path("not_exist_a")) | ||
except ffmpeg.FFmpegCalledProcessError as ex: | ||
# exc from linux | ||
assert "STDERR:" not in str(ex) | ||
except RuntimeError as ex: | ||
# exc from macos | ||
assert "Empty JSON ffprobe output with STDERR: None" == str(ex) | ||
else: | ||
assert False, "RuntimeError not raised" | ||
|
||
ff = ffmpeg.FFMPEG(stderr=subprocess.PIPE) | ||
try: | ||
x = ff.probe_format_and_streams(Path("not_exist_a")) | ||
except ffmpeg.FFmpegCalledProcessError as ex: | ||
# exc from linux | ||
assert "STDERR:" in str(ex) | ||
except RuntimeError as ex: | ||
# exc from macos | ||
assert ( | ||
"Empty JSON ffprobe output with STDERR: b'not_exist_a: No such file or directory" | ||
in str(ex) | ||
) | ||
else: | ||
assert False, "RuntimeError not raised" |