如何使用FFmpeg从.mp3文件中提取元数据并将其作为文本放置到视频中? [英] How to take metadata from .mp3 file and put it to a video as a text using FFmpeg?

查看:110
本文介绍了如何使用FFmpeg从.mp3文件中提取元数据并将其作为文本放置到视频中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我先前打开的主题中:

我从@llogan那里获得了详细的解释,介绍了如何在youtube上播放循环的短静音视频,从而自动在其中插入音轨而不中断翻译.

I've got detailed explanation from @llogan how to broadcast looped short muted video on youtube automatically injecting audio tracks in it without interrupting a translation.

我计划增强流程,我面临的下一个问题是如何在广播中动态添加其他文本.

I plan to enhance the flow and the next question I faced with is how to dynamically put an additional text to the broadcast.

先决条件:

  1. 由ffmpeg启动和运行YouTube广播
  2. 短短3分钟的视频正在无限循环中付费
  3. 来自播放列表的
  4. 音轨由"ffmpeg concat"自动获取.并逐一插入视频

这是开始翻译的基本命令:

this is a basic command to start translation:

ffmpeg -re -fflags + genpts -stream_loop -1 -i video.mp4 -re -f concat-i input.txt -map 0:v -map 1:a -c:v libx264 -tune stillimage -vf format = yuv420p -c:a复制-g 20 -b:v 2000k-最大2000k -bufsize8000k -f flv rtmp://a.rtmp.youtube.com/live2/my-key

ffmpeg -re -fflags +genpts -stream_loop -1 -i video.mp4 -re -f concat -i input.txt -map 0:v -map 1:a -c:v libx264 -tune stillimage -vf format=yuv420p -c:a copy -g 20 -b:v 2000k -maxrate 2000k -bufsize 8000k -f flv rtmp://a.rtmp.youtube.com/live2/my-key

我想带来的进步

  1. 我计划在音频文件中存储一些元数据(基本上是艺术家姓名和歌曲名称)
  2. 目前,一首特定歌曲开始播放时,应该从元数据中提取歌手/歌手的名字,并在整首歌曲播放过程中将其作为文本显示在视频上.
  3. 当当前歌曲结束并且新的歌曲开始播放时,以前的艺术家/歌曲文本应替换为新的歌曲/等

我的问题是如何使用ffmpeg正确获取元数据并将其添加到现有的广播配置中?

推荐答案

这是一个相当广泛的问题,我没有一个完整的解决方案.但是我可以提供部分答案,其中包含一些可用于帮助实现解决方案的命令.

This is a fairly broad question and I don't have a complete solution. But I can provide a partial answer containing several commands that you can use to help implement a solution.

请参见您可以通过ffmpeg流媒体实时插入文件中的文本吗?

使用 ffprobe :

ffprobe -v error -show_entries format_tags=title -of default=nw=1:nk=1 input.mp3
ffprobe -v error -show_entries format_tags=artist -of default=nw=1:nk=1 input.mp3

或组合: format_tags = title,artist (请注意,无论命令中的顺序如何, title 将首先显示,然后显示 artist .)

Or combined: format_tags=title,artist (note that title will display first, then artist, regardless of order in the command).

请参见如何以秒为单位获取视频时长?

最困难的部分是知道何时更新drawtext过滤器中 textfile 中引用的文件,如上面的按需更新视频中的文本所示.

The hard part is knowing when to update the file referenced in textfile in drawtext filter as shown in Update text on video on demand above.

为每首歌曲预先制作视频,包括标题和艺术家信息.简单的Bash示例:

Pre-make a video per song including the title and artist info. Simple Bash example:

audio=input.mp3; ffmpeg -stream_loop -1 -i video.mp4 -i "$audio" -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1,fps=25,drawtext=text='$(ffprobe -v error -show_entries format_tags=title,artist -of default=nw=1:nk=1 $audio)':fontsize=18:fontcolor=white:x=10:y=h-th-10,format=yuv420p[v]" -map "[v]" -map 1:a -c:v libx264 -c:a aac -ac 2 -ar 44100 -g 50 -b:v 2000k -maxrate 2000k -bufsize 6000k -shortest "${audio%.*}.mp4"

现在您已经进行了编码,并且所有内容都符合相同的属性以进行正确的串联,您可能只需

Now that you already did the encoding, and everything is conformed to the same attributes for proper concatenation, you can probably just stream copy your playlist to YouTube (but I didn't test):

ffmpeg -re -f concat -i input.txt -c copy -f flv rtmp://a.rtmp.youtube.com/live2/my-key

请参考您之前的问题,有关如何动态更新播放列表.

Refer to your previous question on how to dynamically update the playlist.

参考文献:

这篇关于如何使用FFmpeg从.mp3文件中提取元数据并将其作为文本放置到视频中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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