Info
🌱 來自: command line know how
ffmpeg
To create a video from your audio.mp3
file and img.png
image, and to add a running time code in the center of the image, you can use FFmpeg, a powerful multimedia framework. Here’s a step-by-step guide on how to do it:
-
Install FFmpeg: If you haven’t already, install FFmpeg on your computer. You can download it from the FFmpeg website and follow the installation instructions for your operating system.
-
Prepare the Command: Use the following FFmpeg command as a template. This command will take your
img.png
andaudio.mp3
, create a video, and add a timecode overlay:
Explanation of the command
-loop 1 -framerate 25 -i img.png
: Loops the image at a frame rate of 25 FPS.-i audio.mp3
: Specifies the audio file.-vf "drawtext=..."
: This is the filter to draw the timecode.text='%{pts\:hms}'
: The timecode format (hours:minutes:seconds).x=(w-tw)/2
: Centers the text horizontally.y=(h/2-th/2)
: Centers the text vertically.fontcolor=white
: Sets the font color to white.fontsize=30
: Sets the font size.box=1
: Adds a background box for readability.boxcolor=black@0.5
: The box color (semi-transparent black).boxborderw=5
: The border width of the box.
-c:v libx264
: Uses the H.264 codec for the video.-tune stillimage
: Optimizes for still image input.-c:a aac -b:a 192k
: Uses AAC codec for audio with a bitrate of 192k.-pix_fmt yuv420p
: Ensures compatibility with most players.-shortest
: Ends the video when the shortest input (audio or video) ends.output.mp4
: The name of the output file.
- Run the Command: Open a terminal or command prompt, navigate to the directory where your
img.png
andaudio.mp3
files are located, and run the command.
This command will produce a video file named output.mp4
with your image, the audio playing in the background, and a running time code centered on the image. Adjust the font size and box properties as needed to fit your preferences.