Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra zero bytes in audio frame while resampling #1022

Closed
3 tasks done
nshmyrev opened this issue Aug 24, 2022 · 1 comment
Closed
3 tasks done

Extra zero bytes in audio frame while resampling #1022

nshmyrev opened this issue Aug 24, 2022 · 1 comment

Comments

@nshmyrev
Copy link

Overview

When one resamples audio frames like this, the frame bytes contain extra zeroes which causes noisy audio as in #773

                print (fr)
                for rfr in self.__resampler.resample(fr):
                    print (rfr)
                    bfr = bytearray(bytes(rfr.planes[0]))
                    print (type(bfr), len(bfr))
<av.AudioFrame 0, pts=227520, 960 samples at 48000Hz, stereo, s16 at 0x7f011f10fa50>
<av.AudioFrame 0, pts=227520, 960 samples at 48000Hz, mono, s16 at 0x7f011f10fed0> 1984
<class 'bytearray'> 1984

Expected behavior

Expected to receive 1920 bytes

Actual behavior

Receives 1984 bytes with zeroes in the end

Versions

  • OS: Ubuntu 18
  • PyAV runtime:
PyAV v9.2.0
library configuration: --disable-static --enable-shared --libdir=/tmp/vendor/lib --prefix=/tmp/vendor --disable-alsa --disable-doc --disable-mediafoundation --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-lzma --enable-version3 --enable-zlib
library license: GPL version 3 or later
libavcodec     58.134.100
libavdevice    58. 13.100
libavfilter     7.110.100
libavformat    58. 76.100
libavutil      56. 70.100
libswresample   3.  9.100
libswscale      5.  9.100
  • FFmpeg:
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100

Research

I have done the following:

@jlaine
Copy link
Member

jlaine commented Sep 2, 2022

Yes, FFmpeg likes to use frames whose memory is "aligned". You will need to look at the number of samples in the frame, and only use the "useful" part of the frame.

@jlaine jlaine closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants