本文介绍了将 MP3 裁剪为前 30 秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

原始问题

我希望能够从现有 MP3 文件生成一个新的(完全有效的)MP3 文件,用作预览——先试后买的风格.新文件应该只包含曲目的前 n 秒.

I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first n seconds of the track.

现在,我知道我可以在传送文件时在 n 秒(根据比特率和标头大小计算)截断流",但这有点脏,而且是真正的 PITAVBR 轨道.我希望能够生成合适的 MP3 文件.

Now, I know I could just "chop the stream" at n seconds (calculating from the bitrate and header size) when delivering the file, but this is a bit dirty and a real PITA on a VBR track. I'd like to be able to generate a proper MP3 file.

有人有什么想法吗?

答案

mp3splitffmpeg 都是很好的解决方案.我选择了 ffmpeg,因为它通常安装在 linux 服务器上,而且 也很容易用于窗户.这里有一些更好的命令行参数,用于使用 ffmpeg 生成预览

Both mp3split and ffmpeg are both good solutions. I chose ffmpeg as it is commonly installed on linux servers and is also easily available for windows. Here's some more good command line parameters for generating previews with ffmpeg

  • -t 在指定的秒数后斩断
  • -y 强制覆盖文件
  • -ab 设置比特率,例如-ab 96k
  • -ar 设置采样率,例如-ar 22050 用于 22.05kHz
  • -map_meta_data : 将轨道元数据从 infile 复制到 outfile
  • -t <seconds> chop after specified number of seconds
  • -y force file overwrite
  • -ab <bitrate> set bitrate e.g. -ab 96k
  • -ar <rate Hz> set sampling rate e.g. -ar 22050 for 22.05kHz
  • -map_meta_data <outfile>:<infile> copy track metadata from infile to outfile

您可以复制原始轨道设置,而不是设置 -ab 和 -ar,正如 Tim Farley 建议的那样:

instead of setting -ab and -ar, you can copy the original track settings, as Tim Farley suggests, with:

  • -acodec copy

推荐答案

我也推荐 ffmpeg,但是 John Boker 建议的命令行有一个意想不到的副作用:它将文件重新编码为默认比特率(即 64kb/s 至少在我这里的版本中).这可能会让您的客户对您的声音文件的质量产生错误的印象,而且需要更长的时间.

I also recommend ffmpeg, but the command line suggested by John Boker has an unintended side effect: it re-encodes the file to the default bitrate (which is 64 kb/s in the version I have here at least). This might give your customers a false impression of the quality of your sound files, and it also takes longer to do.

这是一个无需转码即可切片为 30 秒的命令行:

Here's a command line that will slice to 30 seconds without transcoding:

ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3

-acodec 开关告诉 ffmpeg 使用不转码的特殊复制"编解码器.快如闪电.

The -acodec switch tells ffmpeg to use the special "copy" codec which does not transcode. It is lightning fast.

注意:该命令是根据 Oben Sonne 的评论更新的

NOTE: the command was updated based on comment from Oben Sonne

这篇关于将 MP3 裁剪为前 30 秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:55