I'm trying to use pyav for encoding audio from wav to mp3.
I have wrote a simple code (this code is similar to your "encode" example):
import av
def main():
inp = av.open('LRMonoPhase4.wav', 'r')
out = av.open('LRMonoPhase4.mp3', 'w')
ostream = out.add_stream("mp3")
for frame in inp.decode(audio=0):
frame.pts = None
out_packets = [ostream.encode(frame)]
while out_packets[-1]:
out_packets.append(ostream.encode(None))
for p in out_packets:
if p:
out.mux(p)
while True:
out_packet = ostream.encode(None)
if out_packet:
out.mux(out_packet)
else:
break
out.close()
if __name__ == '__main__':
main()
I have taken the following test files :
http://www.kozco.com/tech/LRMonoPhase4.wav
http://www.kozco.com/tech/piano2.wav
But it seems created mp3 files are broken. My result mp3 files:
LRMonoPhase4.zip
piano2.zip
Errors/Warning in console:
Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Trying to remove 1152 samples, but the queue is empty
last message repeated 1 times
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1652 >= 708
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1652 >= 750
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1652 >= 792
Trying to remove 1152 samples, but the queue is empty
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1944 >= 1000
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1944 >= 1042
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1944 >= 1083
Trying to remove 1152 samples, but the queue is empty
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2235 >= 1292
...
1 frames left in the queue on closing
I'm using Windows 10. I have built pyav from PyPI with prebuilt FFmpeg from here:
http://ffmpeg.zeranoe.com/builds/
Version 20170503-a75ef15-win64
ffmpeg -version
ffmpeg version N-85750-ga75ef15 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (GCC)
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil 55. 61.100 / 55. 61.100
libavcodec 57. 93.100 / 57. 93.100
libavformat 57. 72.101 / 57. 72.101
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 88.100 / 6. 88.100
libswscale 4. 7.101 / 4. 7.101
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
Thank you!
I'm trying to use pyav for encoding audio from wav to mp3.
I have wrote a simple code (this code is similar to your "encode" example):
I have taken the following test files :
http://www.kozco.com/tech/LRMonoPhase4.wav
http://www.kozco.com/tech/piano2.wav
But it seems created mp3 files are broken. My result mp3 files:
LRMonoPhase4.zip
piano2.zip
Errors/Warning in console:
I'm using Windows 10. I have built pyav from PyPI with prebuilt FFmpeg from here:
http://ffmpeg.zeranoe.com/builds/
Version 20170503-a75ef15-win64
Thank you!