This commit is contained in:
simon987 2020-06-14 21:48:19 -04:00
parent 5443308bf7
commit 838381ea89
6 changed files with 237 additions and 11 deletions

43
flac2mp3_V0 Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/bash python3
import os
from shutil import copyfile
import pathlib
from multiprocessing import Pool, Value
SRC = "/mnt/merger/audio/music"
DST = "/mnt/merger/audio/music_[V0]"
to_convert = []
counter = Value("d")
def convert(path):
global counter
destination = DST + path[len(SRC):]
destination = os.path.splitext(destination)[0] + ".mp3"
pathlib.Path(os.path.split(destination)[0]).mkdir(parents=True, exist_ok=True)
if not os.path.exists(destination):
os.system("ffmpeg -i \"" + path + "\" -c:a libmp3lame -q:a 0 -y \"" + destination + "\" -loglevel panic")
print("[%.2f%%] - " % (counter.value / len(to_convert) * 100) + destination)
counter.value += 1
def recursive_convert(path):
for item in os.listdir(path):
full_path = path + os.sep + item
if os.path.isdir(full_path):
recursive_convert(full_path)
else:
if os.path.splitext(item)[1] in [".mp3", ".flac", ".m4a", ".ape"]:
to_convert.append(full_path)
recursive_convert(SRC)
print("Converting " + str(len(to_convert)) + " files...")
pool = Pool(processes=4)
pool.map(convert, to_convert)

46
flac2opus Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
import os
from shutil import copyfile
import pathlib
from multiprocessing import Pool, Value
SRC = "/mnt/merger/audio/music"
DST = "/mnt/merger/audio/music_opus"
to_convert = []
counter = Value("d")
def convert(path):
global counter
destination = DST + path[len(SRC):]
destination = os.path.splitext(destination)[0] + ".opus"
pathlib.Path(os.path.split(destination)[0]).mkdir(parents=True, exist_ok=True)
if not os.path.exists(destination):
if path.endswith("flac"):
os.system("opusenc \"" + path + "\" --bitrate 80 \"" + destination + "\" --quiet")
else:
os.system("ffmpeg -i \"" + path + "\" -f flac -loglevel panic - | opusenc - \"" + destination + "\" --quiet")
print("[%.2f%%] - " % (counter.value / len(to_convert) * 100) + destination)
counter.value += 1
def recursive_convert(path):
for item in os.listdir(path):
full_path = path + os.sep + item
if os.path.isdir(full_path):
recursive_convert(full_path)
else:
if os.path.splitext(item)[1] in [".mp3", ".flac", ".m4a", ".ape"]:
to_convert.append(full_path)
recursive_convert(SRC)
print("Converting " + str(len(to_convert)) + " files...")
pool = Pool(processes=4)
pool.map(convert, to_convert)

View File

@ -1,5 +1,5 @@
sudo pacman -S archlinux-keyring
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman-key --refresh-keys
sudo pacman -Syyu
sudo pacman -S archlinux-keyring --noconfirm
sudo pacman-key --init --noconfirm
sudo pacman-key --populate archlinux --noconfirm
sudo pacman-key --refresh-keys --noconfirm
sudo pacman -Syyu --noconfirm

55
send_mail Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env python3
import argparse
import smtplib
import subprocess
import sys
import time
from email.message import Message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formatdate
from pathlib import Path
parser = argparse.ArgumentParser(description="mail")
parser.add_argument("--subject", "-s",
action="store", type=str, required=True,
help="Message subject")
parser.add_argument("--message", "-m",
action="store", type=str, required=True,
help="Message body")
parser.add_argument("--sender", "-f",
action="store", type=str, default="me@simon987.net",
help="Source address")
parser.add_argument("--to", "-t",
action="store", type=str, required=True,
help="Destination address")
parser.add_argument("--smtp_server",
action="store", type=str, default="mail.simon987.net",
help="SMTP server")
parser.add_argument("--smtp_password", "-p",
action="store", type=str, required=True,
help="SMTP password")
args = parser.parse_args()
HOME = str(Path.home())
if args.message == "-":
text = sys.stdin.read()
else:
text = args.message
msg = MIMEText(text).as_string().replace("\n", "\r\n")
msg["From"] = args.sender
msg["Subject"] = args.subject
msg["To"] = args.to
msg["Date"] = formatdate(time.time(), True)
s = smtplib.SMTP(args.smtp_server, port=587, )
s.starttls()
s.login(args.sender, args.smtp_password)
s.sendmail(args.sender, args.to, msg.as_string())
s.quit()

11
webmenc
View File

@ -1,9 +1,8 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
source $(dirname $0)/lib/argparse || exit 1
argparse "$@" <<EOF || exit 1
parser.add_argument('infile')
parser.add_argument('-v', '--video-bitrate', type=int,
help='Video bitrate in kbps')
@ -13,9 +12,9 @@ EOF
CRF=30
ffmpeg -i "$1" -y -b:v $VIDEO_BITRATE \
ffmpeg -i "${INFILE}" -y -b:v "${VIDEO_BITRATE}k" \
-quality good -crf $CRF -c:v libvpx-vp9 -an \
-pass 1 -speed 4 -f webm /dev/null &&\
ffmpeg -i "$1" -y -b:v $VIDEO_BITRATE -auto-alt-ref 1 -lag-in-frames 25 \
-quality good -crf $CRF -c:v libvpx-vp9 -c:a libopus -b:a $AUDIO_BITRATE \
-pass 2 -speed 1 "$1.webm"
ffmpeg -i "${INFILE}" -y -b:v "${VIDEO_BITRATE}k" -auto-alt-ref 1 -lag-in-frames 25 \
-quality good -crf $CRF -c:v libvpx-vp9 -c:a libopus -b:a ${AUDIO_BITRATE}k \
-pass 2 -speed 1 "${INFILE}.webm"

83
webmenc_auto Executable file
View File

@ -0,0 +1,83 @@
#!/usr/bin/env bash
width=$(ffprobe "${INFILE}" -show_streams -print_format json 2>/dev/null | jq ".streams[] | select(.width != null) | .width" | head -n 1)
height=$(ffprobe "${INFILE}" -show_streams -print_format json 2>/dev/null | jq ".streams[] | select(.height != null) | .height" | head -n 1)
fps=$(($(ffprobe "${INFILE}" -show_streams -print_format json 2>/dev/null | jq -r ".streams[] | select(.r_frame_rate != null) | .r_frame_rate" | head -n 1)))
if [[ ${width} -lt ${height} ]]; then
tmp=${width}
width=${height}
height=${tmp}
fi
if [[ ${width} -le 320 ]]; then
MIN_VBR=75
CRF=36
TRG_VRB=150
MAX_VBR=218
TILE_COLS=0
THREADS=2
elif [[ $width -le 640 ]]; then
MIN_VBR=375
CRF=33
TRG_VBR=750
MAX_VBR=1088
TILE_COLS=1
THREADS=4
elif [[ $width -le 1280 ]]; then
MIN_VBR=512
CRF=32
TRG_VBR=1024
MAX_VBR=1485
TILE_COLS=2
THREADS=8
elif [[ $width -le 1920 ]]; then
if [[ $fps -le 30 ]]; then
MIN_VBR=900
TRG_VBR=1800
MAX_VBR=2610
else
MIN_VBR=1500
TRG_VBR=3000
MAX_VBR=4350
fi
CRF=31
TILE_COLS=2
THREADS=8
elif [[ $width -le 2560 ]]; then
if [[ $fps -le 35 ]]; then
MIN_VBR=3000
TRG_VBR=6000
MAX_VBR=8700
else
MIN_VBR=4500
TRG_VBR=9000
MAX_VBR=13050
fi
CRF=24
TILE_COLS=3
THREADS=16
else
if [[ $fps -le 35 ]]; then
MIN_VBR=6000
TRG_VBR=12000
MAX_VBR=17400
else
MIN_VBR=9000
TRG_VBR=18000
MAX_VBR=26100
fi
TILE_COLS=3
THREADS=16
CRF=15
fi
ffmpeg -i "${INFILE}" -y -b:v "${TRG_VBR}k" -minrate "${MIN_VBR}k" -maxrate "${MAX_VBR}k" -crf $CRF \
-tile-columns ${TILE_COLS} -threads ${THREADS} \
-quality good -c:v libvpx-vp9 -an \
-pass 1 -speed 4 -f webm /dev/null && \
ffmpeg -i "${INFILE}" -y -b:v "${TRG_VBR}k" -minrate "${MIN_VBR}k" -maxrate "${MAX_VBR}k" -crf $CRF\
-tile-columns ${TILE_COLS} -threads ${THREADS} \
-quality good -c:v libvpx-vp9 -c:a libopus -b:a 32k \
-pass 2 -speed 1 "${INFILE}.webm"