如何使FFmpeg自动将mp3音频轨道插入单个循环的静音视频中

如何使FFmpeg自动将mp3音频轨道插入单个循环的静音视频中

本文介绍了如何使FFmpeg自动将mp3音频轨道插入单个循环的静音视频中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都在这里!所以基本上这就是我想要实现的:

everybody here! So basically this is what I want to achieve:

我有一个静音的视频,长约3分钟.我有一个mp3格式的音轨列表(一个文件夹中有40首歌曲,持续时间为2到6分钟)

I have a muted video about 3 minutes long.I have a list of audio tracks in mp3 format (40 songs in a folder with duration 2 to 6 mins each one)

我希望该视频自动循环播放,从播放列表中提取歌曲,并将它们逐一注入到视频中.每次歌曲播放完毕时,列表中的下一首歌曲都应立即开始播放.视频会继续播放,并且不在乎曲目的持续时间.

I want this video to play cycled automatically taking songs from playlist and injecting them to the video one by one. Every time a song finishes the next one from the list should start playing at the moment. Video continues playing and doesn't care duration of tracks.

我认为这是在24/7模式下在youtube上播放带有视频背景的广播的第一步,该功能可以在不停止翻译的情况下将其他曲目添加到播放列表中.

I consider it as the first step on the way to broadcast radio with a video background on youtube in 24/7 mode with ability to put additional tracks to playlist without need to stop translation.

我的问题是我是FFmpeg的新手,我很乐意为实现我的目标而开始调查哪个FFMpeg主题的任何建议

My problem is that I'm new in FFmpeg and I would appreciate any suggestions regarding which FFMpeg topic to start investigate with in order to achieve my goal

推荐答案

使用concat多路分配器

您可以实时更新 concat多路分配器但每个音频文件必须具有相同的属性,相同数量的流,并且都必须具有相同的格式.

  1. 创建包含以下内容的 input.txt :

ffconcat version 1.0
file 'audio1.mp3'
file 'audio2.mp3'
file 'audio3.mp3'
file 'audio40.mp3'

所有文件名都必须是安全"的,否则它将失败,并显示不安全的文件名.基本上,文件名中没有特殊字符,仅使用绝对路径.有关更多信息,请参见 concat多路分配器.

All file names must be "safe" or it will fail with Unsafe file name. Basically no special characters in file names and only use absolute paths. See concat demuxer for more info.

运行 ffmpeg 以流式传输到YouTube:

Run ffmpeg to stream to YouTube:

ffmpeg -re -framerate 10 -loop 1 -i image.jpg -re -f concat -i input.txt -map 0:v -map 1:a -c:v libx264 -tune stillimage -vf format=yuv420p -c:a aac -g 20 -b:v 2000k -maxrate 2000k -bufsize 8000k -f flv rtmp://youtube

  • 当您准备添加新歌曲时,使 temp.txt 包含:

    ffconcat version 1.0
    file 'audio41.mp3'
    file 'audio42.mp3'
    file 'audio43.mp3'
    

  • 原子地替换 input.txt :

    mv temp.txt input.txt
    

  • 有关更多信息,请参见 FFmpeg Wiki:连接.

    See FFmpeg Wiki: Concatenate for lots more info.

    input.txt 中列出的文件必须全部相同:

    The files listed in input.txt must all have the same:

    • 格式(AAC,MP3等,但不能混合使用)
    • 采样率(48000、44100等)
    • 频道数(单声道,立体声等).

    如果它们有所不同,则必须先对其进行预处理,然后才能将它们添加到播放列表中.Bash示例以44100采样率( -ar 44100 )使每个音频与立体声( -ac 2 )一致并保存为M4A容器中的AAC格式:

    If they vary then you will have to pre-process them before adding them to the playlist. Bash example conforming each audio to stereo (-ac 2) with 44100 sample rate (-ar 44100) and save as AAC format in M4A container:

    mkdir conformed
    for f in *.mp3; do ffmpeg -i "$f" -map 0:a -ac 2 -ar 44100 -c:a aac "conformed/${f%.*}.m4a"; done
    

    • 建议输出到AAC以流式传输到YouTube.

      • Outputting to AAC is recommended for streaming to YouTube.

        如果执行此操作,则可以避免将 ffmpeg 命令中的音频重新编码到YouTube.只需在步骤2中将 -c:aac 更改为 -c:acopy :运行 ffmpeg 以流式传输到YouTube .

        If you do this then you can avoid re-encoding the audio in the ffmpeg command to YouTube. Just change -c:a aac to -c:a copy in step #2: Run ffmpeg to stream to YouTube.

        这篇关于如何使FFmpeg自动将mp3音频轨道插入单个循环的静音视频中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-06 19:14