Sound quality for MovieStim is very bad

I am using the following MovieStim call:

	mov = visual.MovieStim(
		win=win, name='mov',
		ori=0, opacity=1,

and the audio playback is very loud and very noisy. I need to set the volume to 0.00001 for it to be bearable at all, but then only the noise is noticeable.
This is all happening with a .mkv video I compressed. I tried loading the .MOV file (before re-encoding) and the sound is less loud and less noisy, but still unacceptable. This is all of course baffling, since I re encoded the files with the following parameters passed to ffmpeg:

-crf 16 -c:a copy

Which should copy the audio stream without re-encoding. Here is the ffmpeg -i output for my files:

Input #0, matroska,webm, from 'nd750_a0037.mkv':
    MAJOR_BRAND     : qt  
    MINOR_VERSION   : 537331968
    ENCODER         : Lavf56.40.101
  Duration: 00:08:00.28, start: 0.000000, bitrate: 8003 kb/s
    Stream #0:0(eng): Video: h264 (High), yuvj420p(pc), 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
      CREATION_TIME   : 2016-05-27 16:52:02
      LANGUAGE        : eng
      ENCODER         : Lavc56.60.100 libx264
      DURATION        : 00:08:00.279000000
    Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s (default)
      CREATION_TIME   : 2016-05-27 16:52:02
      LANGUAGE        : eng
      DURATION        : 00:08:00.280000000


Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.MOV/nd750_a0037.MOV':
    major_brand     : qt  
    minor_version   : 537331968
    compatible_brands: qt  niko
    creation_time   : 2016-05-27 16:52:02
  Duration: 00:08:00.28, start: 0.000000, bitrate: 11619 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt470m), 1920x1080, 10079 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
      creation_time   : 2016-05-27 16:52:02
    Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
      creation_time   : 2016-05-27 16:52:02

If I try to play the video with mpv they both sound ok and afaict the same.

Any idea what’s wrong?

You’re using avbin so you could try the newer MovieStim3 (or MovieSTim2) to see if it’s any better. I’m not putting in any more effort to debugging avbin problems.

It may also be that the compression of the audio is the problem and you need Linear audio instead.

yo you think the problem is the avbin backend? Can MovieStim3 use any other backend except moviepy? That software is not yet packaged for Gentoo - I could don that, ofc, but it would take a while to get it in the main tree.

The problem was indeed the avbin backend, or more precisely the fact that the newest avbin version in Gentoo was very old. I have since bumped it. Now the sound is acceptable.

Having said that, even the newest avbin version from upstream is still quite ancient, as is the libav they bundle. Not least of all, their package seems a bit confused. As far as I have seen it’s just a .c and an .h file with lots of spaghetti code around them, and a build system that is reliant on git. long story short, I would advise against using it.

MovieStim2() works well with respect to playback, though it has its own issues.

I have commenced packaging the dependencies required for MovieStim3() for Gentoo, and in my testing environment it seems the playback is great. Smooth, good sound, and not having any of the aspect ratio issues I have seen with MovieStim2().

OK, glad you got that sorted. I’m not spending any more time (ever) to get avbin working. The moviepy backend is the one I’m intending to support long-term.