Ma vidéo, enregistrée avec VirtualBox, est au format 1280×800 mais l’image est entourée de noir que je veux supprimer. La partie centrale qui m’intéresse est au format 640×400. Je fais donc un crop centré.
Pour automatiser (en Python) :
Usage : python3 convert.py input.webm 0 00:01:30
convert.py
import subprocess
import sys
import os
if len(sys.argv) < 4:
print("Usage: python3 convert.py <input.webm> <start> <end>")
print("Ex: python3 convert.py input.webm 0 00:01:30")
sys.exit(1)
input_file = sys.argv[1]
start = sys.argv[2]
end = sys.argv[3]
output_name = "output"
# Filtre de crop/scale commun (la découpe se fait via -ss/-to en input)
# Remplacer "neighbor" par "lanczos" si la vidéo est réelle (non pixel art)
vf_base = "crop=640:400:320:200"
vf_hd = "crop=640:400:320:200,scale=1280:800:flags=neighbor"
print("=== Export MP4 640x400 (H.264) ===")
subprocess.run([
"ffmpeg",
"-ss", start, "-to", end,
"-i", input_file,
"-vf", vf_base,
"-c:v", "libx264",
"-crf", "16",
"-preset", "slow",
"-pix_fmt", "yuv420p",
"-c:a", "aac",
"-b:a", "192k",
"-movflags", "+faststart",
f"{output_name}-640x400.mp4"
], check=True)
print("=== Export MP4 HD 1280x800 (H.264) ===")
subprocess.run([
"ffmpeg",
"-ss", start, "-to", end,
"-i", input_file,
"-vf", vf_hd,
"-c:v", "libx264",
"-crf", "10",
"-preset", "veryslow",
"-pix_fmt", "yuv420p",
"-c:a", "aac",
"-b:a", "192k",
"-movflags", "+faststart",
f"{output_name}-1280x800.mp4"
], check=True)
print("=== Export WEBM 640x400 (VP9) ===")
subprocess.run([
"ffmpeg",
"-ss", start, "-to", end,
"-i", input_file,
"-vf", vf_base,
"-c:v", "libvpx-vp9",
"-crf", "15",
"-b:v", "0",
"-c:a", "libopus",
"-b:a", "192k",
f"{output_name}-640x400.webm"
], check=True)
print("=== Export WEBM HD 1280x800 (VP9) ===")
subprocess.run([
"ffmpeg",
"-ss", start, "-to", end,
"-i", input_file,
"-vf", vf_hd,
"-c:v", "libvpx-vp9",
"-crf", "10",
"-b:v", "0",
"-deadline", "best",
"-cpu-used", "0",
"-c:a", "libopus",
"-b:a", "192k",
f"{output_name}-1280x800.webm"
], check=True)
print("=== Terminé ===")
Pour YouTube, il faut passer à 5120x3200 pour que la vidéo ne soit pas dégradée fortement.
convert5120.py
import subprocess
import sys
import os
if len(sys.argv) < 4:
print("Usage: python3 script.py ")
print("Ex: python3 script.py input.webm 0 00:01:30")
sys.exit(1)
input = sys.argv[1]
start = sys.argv[2]
end = sys.argv[3]
output_name = "output"
temp_file = "temp_file.webm"
print("=== Coupe de la vidéo ===")
subprocess.run([
"ffmpeg",
"-i", input,
"-ss", start,
"-to", end,
"-c", "copy",
temp_file
], check=True)
print("=== Export MP4 HD 5120x3200 (H.264) ===")
subprocess.run([
"ffmpeg",
"-i", temp_file,
"-vf", "crop=640:400:320:200,scale=5120:3200:flags=neighbor",
"-c:v", "libx264",
"-crf", "10",
"-preset", "veryslow",
"-pix_fmt", "yuv420p",
"-c:a", "aac",
"-b:a", "192k",
"-movflags", "+faststart",
f"{output_name}-5120x3200.mp4"
], check=True)
print("=== Suppression du fichier temporaire ===")
if os.path.exists(temp_file):
os.remove(temp_file)
print("=== Terminé ===")