Open aben20807 opened 2 years ago
ffmpeg -y -i input.flv -filter_complex "fps=4,scale=1920:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256[p];[s1][p]paletteuse=dither=bayer" output.gif
scale
and max_colors
impact the output gif's size
ffmpeg -safe 0 -f concat -i <(find . -type f -name '*.mp4' -printf "file '$PWD/%p'\n" | sort) -c copy output.mp4
-c:v h264_nvenc
if there is no GPU driverffmpeg -i A.mp4 -i B.mp4 -filter_complex "concat=n=2:v=1:a=1" -c:v h264_nvenc output.mp4
[Parsed_concat_4 @ 0x55c55ae4d400] Input link in0:v0 parameters (size 1280x720, SAR 1:1) do not match the corresponding output link in0:v0 parameters (1280x720, SAR 8001:8000)
[Parsed_concat_4 @ 0x55c55ae4d400] Failed to configure output pad on Parsed_concat_4
Error reinitializing filters!
Correct the aspect of one of videos first.
ffmpeg -i tmpA.mp4 -aspect 16:9 -c copy A.mp4
find . -iname '*.webp' -exec bash -c 'ffmpeg -y -hide_banner -loglevel error -i "$1" -q:v 1 -qmin 1 -qmax 1 "${1%.*}.jpg"; printf "$1\n"' _ {} \;
轉換完後刪除原檔
find . -iname '*.webp' -exec bash -c 'ffmpeg -y -hide_banner -loglevel error -i "$1" -q:v 1 -qmin 1 -qmax 1 "${1%.*}.jpg"; printf "$1\n" && rm "$1"' _ {} \;
# -*- coding: utf8 -*-
# pip install Pillow tqdm
# python -X utf8 .\webp2jpg.py --dir ../
from pathlib import Path
from multiprocessing import Pool, cpu_count
import argparse
import os, sys
from tqdm import tqdm
from PIL import Image
def process(file):
ori_dir = str(str(file.parent.resolve()).encode("utf8"), encoding="utf8")
new_dir = ori_dir + "_jpg"
os.makedirs(new_dir, exist_ok=True)
ori_file = str(file.resolve())
new_file = ori_file.replace(file.suffix, ".jpg").replace(ori_dir, new_dir)
ori_file = str(bytes(ori_file, encoding="utf8"), encoding="utf8")
new_file = str(bytes(new_file, encoding="utf8"), encoding="utf8")
if not os.path.isfile(new_file):
im = Image.open(ori_file).convert("RGB")
im.save(new_file, "jpeg", subsampling=0, quality=95)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--dir", type=str, required=True)
parser.add_argument("--count", action="store_true")
args = parser.parse_args()
pwd = Path(rf"{args.dir}")
files = [Path(file) for file in pwd.glob("**/*.webp")]
if args.count:
print(f"total: {len(files)}")
sys.exit(0)
with Pool(cpu_count()) as p:
with tqdm(total=len(files), ascii=True, ncols=60) as pbar:
for _ in p.imap_unordered(process, files):
pbar.update()
print(f"total: {len(files)}")
if __name__ == "__main__":
main()
-crf N
: N: 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible-b 800k
: limit the bitrate (optional)ffmpeg -i input.flv -c:v h264_nvenc -crf 30 -c:a aac -b:a 192k -vf format=yuv420p -movflags +faststart output.mp4
ffmpeg -i video.mp4 -i audio.m4a -c copy -map 0:v:0 -map 1:a:0 output.mp4
optional
yt-dlp -F {youtube url}
Convert flv to mp4 without re-encode
Convert unplayable mp4 to samsung supported mp4