vcsi
vcsi copied to clipboard
Output files including file extensions
Would it be possible to have it so the file extension is not added to the output file name?
for example, if I process Test.mp4 the output file will be Test.mp4.jpg.
Would it be possible to have a flag to remove the video file extension from the output so it would just show Test.jpg?
I made a simple workaround in bash until this request is implemented...
FILE=example.mp4; vcsi "${FILE}" -o "$(basename "${FILE%.*}").jpg"
You can set a function alias for this in your .bashrc
function vcsi-ne() { FILE="${1}"; vcsi "${FILE}" -o "$(basename "${FILE%.*}").jpg"; }
then use it like this
vcsi-ne example.mp4
Had the same problem here, but on windows. I'm using PowerShell in Powertoys and this works, too:
Get-ChildItem -Filter *.mp4 -Recurse | foreach {vcsi $_.FullName -o "$(Get-Item $_.DirectoryName)\$((Get-Item $_.FullName ).Basename).jpg"}
This goes down all folders and executes on every mp4 file.
@pascaldulieu here's a quick hack. It adds a -k
/--keep-video-ext
flag that is off by default.
keep_extension.patch
diff --git a/vcsi/vcsi.py b/vcsi/vcsi.py
index cf9d934..349a77c 100755
--- a/vcsi/vcsi.py
+++ b/vcsi/vcsi.py
@@ -10,6 +10,7 @@ import os
import shutil
import subprocess
import sys
+from pathlib import Path
from argparse import ArgumentTypeError
from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy
@@ -1609,6 +1610,14 @@ def main():
default="{TIME}",
dest="timestamp_format"
)
+ parser.add_argument(
+ "-k",
+ "--keep-video-ext",
+ help="Preserve the video file's original extension, e.g. 'video.mp4.png'",
+ action="store_true",
+ default=False,
+ dest="keep_ext",
+ )
args = parser.parse_args()
@@ -1670,9 +1679,14 @@ def process_file(path, args):
output_path = args.output_path
if not output_path:
- output_path = path + "." + args.image_format
+ output_path = path
elif os.path.isdir(output_path):
- output_path = os.path.join(output_path, os.path.basename(path) + "." + args.image_format)
+ output_path = os.path.join(output_path, os.path.basename(path))
+
+ if not args.keep_ext:
+ output_path = str(Path(output_path).with_suffix("." + args.image_format))
+ else:
+ output_path += f".{args.image_format}"
if args.no_overwrite:
if os.path.exists(output_path):
@@ -1784,13 +1798,23 @@ def process_file(path, args):
if thumbnail_output_path is not None:
os.makedirs(thumbnail_output_path, exist_ok=True)
print("Copying thumbnails to {} ...".format(thumbnail_output_path))
- for i, frame in enumerate(sorted(selected_frames, key=lambda x_frame: x_frame.timestamp)):
+ for i, frame in enumerate(
+ sorted(selected_frames, key=lambda x_frame: x_frame.timestamp)
+ ):
print(frame.filename)
thumbnail_file_extension = frame.filename.lower().split(".")[-1]
- thumbnail_filename = "{filename}.{number}.{extension}".format(filename=os.path.basename(path),
- number=str(i).zfill(4),
- extension=thumbnail_file_extension)
- thumbnail_destination = os.path.join(thumbnail_output_path, thumbnail_filename)
+ if args.keep_ext:
+ fname_base: str = os.path.basename(path)
+ else:
+ fname_base: str = str(Path(path).stem)
+ thumbnail_filename = "{filename}.{number}.{extension}".format(
+ filename=fname_base,
+ number=str(i).zfill(4),
+ extension=thumbnail_file_extension,
+ )
+ thumbnail_destination = os.path.join(
+ thumbnail_output_path, thumbnail_filename
+ )
shutil.copyfile(frame.filename, thumbnail_destination)
print("Cleaning up temporary files...")