FFmpeg:将文件夹中的所有音频(mp3)批量转换为带有专辑封面的视频(mp4) [英] FFmpeg: Batch convert all audio (mp3) in folder to video (mp4) with album artwork

查看:277
本文介绍了FFmpeg:将文件夹中的所有音频(mp3)批量转换为带有专辑封面的视频(mp4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将文件夹中的所有音频(mp3)批量转换为带有专辑封面的视频(mp4).用于将音频上传到youtube.我有一个几乎可以运行的代码,但我想使整个过程自动化.

I'm looking to batch convert all audio (mp3) in folder to video (mp4) with album artwork. This for uploading audios to youtube. I have pretty much a working code but I want to automate the whole thing.

这是我正在使用的.bat文件中的代码.

Here's the code from .bat file I'm using.

(来源: FFMpeg批处理图像+多音频到视频)

echo off
for %%a in ("*.mp3") do "C:\ffmpeg\bin\ffmpeg" -loop 1 -i  "C:\ffmpeg\bin\input.jpg.jpg" -i "%%a" -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "C:\mp4\%%~na.mp4"
pause

  • "C:\ ffmpeg \ bin \ ffmpeg"编解码器文件夹
  • "C:\ ffmpeg \ bin \ input.jpg"图像路径
  • "C:\ mp4 \ %%〜na.mp4"输出文件夹
  • -vf scale = 854:480,您可以为youtube视频指定视频16:9的分辨率
  • -c:aac-最短使用aac编解码器,通过指定-shortest,视频长度将与音频长度匹配
  • 这很好用,只是每次我都必须手动放置专辑封面.我希望ffmpeg自动从每个音频文件中提取专辑封面,然后将其批量转换为视频.

    This works great except I have to manually put the album art each time. I want ffmpeg to automatically extract the album art from each audio file and then convert it to video in batch.

    这是用于从.mp3文件中提取专辑封面的代码

    This is the code for extracting album art from .mp3 files

    ffmpeg -i input.mp3 -an -vcodec copy cover.jpg
    

    谢谢.

    推荐答案

    我知道了.感谢@ L.斯科特·约翰逊(Scott Johnson)寻求帮助.

    I've figured it out. Thanks to @L. Scott Johnson for the help.

    这是代码

    echo off
    for %%a in ("*.mp3") do (
      "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "E:\songgs\%%~na.jpg"
      "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i  "E:\songs\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "E:\songs\%%~na.mp4" )
    pause
    

    这是代码的基本版本.

    您可以从代码中编辑很多东西.

    You can edit many things from the code.

    例如,您可以使用此代码为同步歌词添加字幕

    For example you can add subtitles for synchronized lyrics with this code

    -vf"subtitles = %%〜na.srt"

    使用此代码调整封面大小

    Resize the cover with this code

    -vf"scale = 1500:1500"

    如果您想将它们都放在一起,只需用逗号(,)将它们添加如下:

    And if you want to both of them together just add them with comma (,) Like this:

    -vf"pad = ceil(iw/2)* 2:ceil(ih/2)* 2,subtitles = %%〜na.srt""

    您还可以将编码器更改为Nvidia NVENC,以实现更快的编码...

    you can also change the encoder to Nvidia NVENC for faster encoding...

    还有更多..你明白了.

    And many more.. you get the idea.

    再次感谢@ L.Scott Johnson 帮我编写了这段代码.随时提出任何问题,我会尽力提供帮助.正如我的用户名所说,我只是在学习这一点,我是一个菜鸟:)

    Again, thanks to @L. Scott Johnson for helping me with this code. Feel free to ask any question and I'll try to help. I'm just learning this, as my user name says, I'm a noob :)

    这篇关于FFmpeg:将文件夹中的所有音频(mp3)批量转换为带有专辑封面的视频(mp4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆