android - 使用 pydub+ffmpeg 编码的 M4a (mp4) 音频文件无法在 Android 上播放
问题描述
我有一个 python 脚本来拆分一些wav
文件并导出到m4a
使用pydub。我可以让这些文件在多台设备上播放,但不能在 Android 设备上播放(使用 Google Pixel 3)。当我尝试直接ffmpeg
在终端中进行编码时,这在 Android 设备上运行良好。
这两个文件有什么区别,既然pydub
是 using ffmpeg
,我需要更改什么以使其与命令完全相同ffmpeg
?
不工作
from pydub import AudioSegment
>>> audio = AudioSegment.from_wav("input.wav")
>>> slice = audio[1000:3000]
>>> slice.export("pydub_export.m4a", format="mp4", parameters=["-ac", "1", "-c:a", "libfdk_aac", "-profile:a", "aac_he", "-vbr", "2"])
mediainfo
输出:
General
Complete name : pydub_export.m4a
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/mp41)
File size : 11.7 KiB
Duration : 2 s 115 ms
Overall bit rate mode : Constant
Overall bit rate : 45.1 kb/s
Writing application : Lavf58.29.100
Audio
ID : 1
Format : AAC LC SBR
Format/Info : Advanced Audio Codec Low Complexity with Spectral Band Replication
Commercial name : HE-AAC
Format settings : NBC
Codec ID : mp4a-40-5
Duration : 2 s 115 ms
Duration_LastFrame : -22 ms
Bit rate mode : Constant
Bit rate : 41.4 kb/s
Channel(s) : 1 channel
Channel layout : C
Sampling rate : 44.1 kHz
Frame rate : 21.533 FPS (2048 SPF)
Compression mode : Lossy
Stream size : 10.7 KiB (92%)
Default : Yes
Alternate group : 1
在职的
$ffmpeg -i input.wav -acodec copy -ss 1 -to 3 input_slice.wav
$ffmpeg -i input_slice.wav -ac 1 -c:a libfdk_aac -profile:a aac_he -vbr 2 ffmpeg_export.m4a
mediainfo
输出:
General
Complete name : ffmpeg_export.m4a
Format : MPEG-4
Format profile : Apple audio with iTunes info
Codec ID : M4A (isom/iso2)
File size : 11.2 KiB
Duration : 2 s 112 ms
Overall bit rate mode : Constant
Overall bit rate : 43.6 kb/s
Writing application : Lavf58.29.100
Audio
ID : 1
Format : AAC LC SBR
Format/Info : Advanced Audio Codec Low Complexity with Spectral Band Replication
Commercial name : HE-AAC
Format settings : NBC
Codec ID : mp4a-40-5
Duration : 2 s 112 ms
Duration_LastFrame : -25 ms
Bit rate mode : Constant
Bit rate : 39.9 kb/s
Channel(s) : 1 channel
Channel layout : C
Sampling rate : 44.1 kHz
Frame rate : 21.533 FPS (2048 SPF)
Compression mode : Lossy
Stream size : 10.3 KiB (91%)
Default : Yes
Alternate group : 1
我已经尝试使用损坏的文件将元数据移到前面-movflags faststart
,但没有任何区别。
解决方案
使用pydub 的 logging,我能够准确地看到ffmpeg
它产生的命令。
事实证明,中的format=...
参数为提供pydub
了标志。这只是找到要使用的正确参数的问题,并且给了我错误的文件。-f ...
ffmpeg
-f
mp4
@Gyan 的回答在这里建议-f ipod
。所以使用format="ipod"
inpydub
给出了正确的输出。
推荐阅读
- ghostscript - GhostscriptError:-100 使用 camelot-py 时
- javascript - 如何使用 Express JS 在另一个文件夹中加载 .js 文件并进行渲染?
- amazon-web-services - AWS 控制台连续两次转换角色
- android - 无法在android中使用facebook登录
- node.js - NPM 不工作 我的 NPM 没有问题。(这可能不是 npm 的问题。上面可能有额外的日志输出。)
- sql - 如何在 Oracle SQL Developer 中拆分数据
- attributeerror - cuDF 用于文本/字符串
- algorithm - 要在另一组中搜索的一组字符串
- matlab - 如何在 MatLab 和/或 OriginLab 中对方程进行编码以拟合超泊松分布
- javascript - 如何将对象附加到数组中的每个项目