Skip to content
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ The built-in help provides handles and default values for implemented functions
```bash
(venv) ~/ffmpeg2obj$ ffmpeg2obj --help
usage: ffmpeg2obj [-h] [-v] [--noop] [--force-cleanup] [-s SRC_DIR] [-d DST_DIR] [-i IGNORED_SUBDIR] [-o OBJ_PREFIX]
[--source-file-extension SOURCE_FILE_EXTENSION] [-e FILE_EXTENSION] [-vc VIDEO_CODEC] [--pix-fmt PIX_FMT]
[-l LANGS] [--width TARGET_WIDTH] [--resize] [--concat] [--height TARGET_HEIGHT]
(-b BUCKET_NAME | --disable-upload) [-qp TARGET_QP | -crf TARGET_CRF]
[--source-file-extension SOURCE_FILE_EXTENSION] [-e FILE_EXTENSION] [-vc VIDEO_CODEC] [--pix-fmt PIX_FMT] [-l LANGS]
[-ll] [--width TARGET_WIDTH] [--resize] [--concat] [--height TARGET_HEIGHT] (-b BUCKET_NAME | --disable-upload)
[-qp TARGET_QP | -crf TARGET_CRF]

Simple tool to compress blu ray movie library and store it in obj

Expand All @@ -84,6 +84,8 @@ options:
--pix-fmt PIX_FMT pix fmt for transcoding of the media files
-l LANGS, --languages LANGS
selected languages transcoding of the media files, all keeps every track
-ll, --loose-languages
prevents ffmpeg failures if media to be transcoded lack requested languages
--width TARGET_WIDTH target width for the media files to be transcoded
--resize scale input files to height x width
--concat concatenates files within same directory
Expand Down
26 changes: 22 additions & 4 deletions src/ffmpeg2obj/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tempfile
import time
from datetime import timedelta
from typing import Any
from typing import Any, Optional

import boto3
import botocore
Expand All @@ -35,13 +35,15 @@ def __init__(
video_codec: str,
pix_fmt: str,
langs: list[str],
loose_langs: bool,
target_qp: int,
target_crf: int,
) -> None:
self.resize = resize
self.video_codec = video_codec
self.pix_fmt = pix_fmt
self.langs = langs
self.loose_langs = loose_langs
self.target_qp = target_qp
self.target_crf = target_crf
self.target_res: list[int] = [target_width, target_height]
Expand Down Expand Up @@ -77,6 +79,7 @@ def __init__(
self.dst_hashed_path: str = (
self.dst_dir + self.hashed_name + "." + self.file_extension
)
self.probe_result: Optional[dict] = None

def __str__(self) -> str:
out = []
Expand All @@ -102,9 +105,10 @@ def update(self, obj_config: dict, bucket_name: str) -> None:

def get_coded_res(self) -> list[int]:
"""Returns height and width for the file from real_path"""
probe_result = ffmpeg.probe(self.real_paths[0])
if self.probe_result is None:
self.probe_result = ffmpeg.probe(self.real_paths[0])
video_stream = list(
filter(lambda x: x["codec_type"] == "video", probe_result["streams"])
filter(lambda x: x["codec_type"] == "video", self.probe_result["streams"])
)[0]
coded_res = [video_stream["coded_width"], video_stream["coded_height"]]
return coded_res
Expand All @@ -131,8 +135,22 @@ def convert(self, verbose: bool = False) -> tuple[str, str, bool, timedelta]:
elif self.processing_params.target_qp is not None:
opts_dict.update({"qp": str(self.processing_params.target_qp)})
if self.processing_params.langs != ["all"]:
requested_langs = set(self.processing_params.langs)
if self.processing_params.loose_langs:
langs = set()
if self.probe_result is None:
self.probe_result = ffmpeg.probe(self.real_paths[0])
for stream in self.probe_result["streams"]:
try:
lang = stream["tags"]["language"]
if lang in requested_langs:
langs.add(lang)
except KeyError:
pass
else:
langs = requested_langs
lang_map = []
for lang in self.processing_params.langs:
for lang in langs:
lang_map.append("0:m:language:" + lang)
lang_dict = {"map": tuple(lang_map)}
opts_dict.update(lang_dict)
Expand Down
10 changes: 10 additions & 0 deletions src/ffmpeg2obj/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ def parse_args() -> argparse.Namespace:
help="selected languages transcoding of the media files, all keeps every track",
)

parser.add_argument(
"-ll",
"--loose-languages",
dest="loose_langs",
action="store_true",
default=False,
help="prevents ffmpeg failures if media to be transcoded lack requested languages",
)

parser.add_argument(
"--width",
dest="target_width",
Expand Down Expand Up @@ -471,6 +480,7 @@ def main():
args.video_codec,
args.pix_fmt,
args.langs,
args.loose_langs,
args.target_qp,
args.target_crf,
)
Expand Down