FFmpeg视频转换脚本需求:生成MP4/WebM及首帧JPEG(640*360)
Hey there! Let's get this sorted out for you—since you're new to FFmpeg, I'll break this down step by step to meet all your requirements: converting to MP4/WebM, generating a first-frame JPEG, and locking everything to 640×360 resolution. Plus, I'll share easy-to-use drag-and-drop/folder-based tools so you don't have to type commands every time.
First: Fixing Your FFmpeg Command
Your original command fails because it doesn't specify critical encoding parameters or resolution scaling. FFmpeg needs clear instructions for codecs (especially for WebM/MP4) and resizing. Here's a single command that does everything in one go (saves time by avoiding re-decoding the input):
ffmpeg -i /tmp/video.off \ -vf scale=640:360 \ -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k /tmp/video.mp4 \ -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus -b:a 128k /tmp/video.webm \ -vf "scale=640:360,select=eq(n\,0)" -vframes 1 /tmp/video_thumb.jpg
Let me break down what each part does:
-vf scale=640:360: Forces the video to resize to your target resolutionlibx264+crf 23: Standard H.264 codec for MP4 (great compatibility; 18-28 is the recommended quality range—lower = better quality)libvpx-vp9+crf 30: Efficient VP9 codec for WebM (smaller file sizes than H.264;-b:v 0lets the codec focus entirely on quality)select=eq(n\,0)+-vframes 1: Grabs only the first frame of the video to save as a JPEG thumbnail
Easy Drag-and-Drop/Folder Tools
If you don't want to mess with commands every time, here are ready-to-use scripts for Windows, Linux, and macOS:
Windows Batch Script (Drag-and-Drop)
Save this as convert_videos.bat on your desktop:
@echo off setlocal enabledelayedexpansion if "%~1"=="" ( echo 请把视频文件拖到这个脚本上! pause exit /b ) :: Process each dropped file for %%f in (%*) do ( set "input=%%f" set "output_folder=%%~dpnf" mkdir "!output_folder!" 2>nul :: Run FFmpeg conversion ffmpeg -i "!input!" ^ -vf scale=640:360 ^ -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k "!output_folder!\%%~nf.mp4" ^ -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus -b:a 128k "!output_folder!\%%~nf.webm" ^ -vf "scale=640:360,select=eq(n\,0)" -vframes 1 "!output_folder!\%%~nf_thumb.jpg" echo 处理完成: %%~nf ) echo 所有文件都搞定啦! pause
How to use: Drag one or more video files onto the batch file. It'll create a folder for each video (in the same directory) with your converted MP4, WebM, and thumbnail.
Linux/macOS Bash Script
Save this as convert_videos.sh, then run chmod +x convert_videos.sh to make it executable:
#!/bin/bash if [ $# -eq 0 ]; then echo "请把视频文件拖到这个脚本上,或者运行 ./convert_videos.sh 视频文件1 视频文件2" exit 1 fi for input in "$@"; do output_folder="${input%.*}" mkdir -p "$output_folder" ffmpeg -i "$input" \ -vf scale=640:360 \ -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k "$output_folder/$(basename "${input%.*}").mp4" \ -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus -b:a 128k "$output_folder/$(basename "${input%.*}").webm" \ -vf "scale=640:360,select=eq(n\,0)" -vframes 1 "$output_folder/$(basename "${input%.*}")_thumb.jpg" echo 处理完成: $(basename "$input") done echo 所有文件处理完毕!
How to use: Drag video files onto the script, or run it with your video files as arguments.
内容的提问来源于stack exchange,提问作者William Eguienta

