matham / ffpyplayer

A cython implementation of an ffmpeg based player.
GNU Lesser General Public License v3.0
134 stars 38 forks source link

Audio thread error for version >= 4.4: Channel layout change is not supported #147

Open blsqr opened 1 year ago

blsqr commented 1 year ago

Hi there,

and first of all thanks for ffpyplayer! It's very powerful to have these bindings :)

I noticed an issue with the latest version (4.5) of ffpyplayer relating to playing the audio streams from certain video files: When starting to play the video, no audio can be heard and the following error is logged:

[ffpyplayer_abuffersink @ 0x600003f30210] Channel layout change is not supported
Audio thread error: Not yet implemented in FFmpeg, patches welcome

As hinted upon in this reddit thread, downgrading to 4.3.5 indeed helped: The audio plays as expected, emitting only the following log message in place of the one above:

[ffpyplayer_abuffersink @ 0x600002fe8790] Removing channel layout 0x3, redundant with 2 channels

The video plays fine via ffplay, including audio, so I would have expected ffpyplayer to also play it without issues.
Is there something between v4.3.5 and 4.5 that might have caused this error? Was this a deliberate change?

I don't know the codebase really, but I'm happy to dive into this, if it helps.


Python 3.10.12, macOS 13.4.1

ffpyplayer.player.MediaPlayer(
    video_url,
    lib_opts={},
    ff_opts=dict(sync="audio", ss=0, infbuf=True),
)
$ ffprobe video.mp4
ffprobe version 6.0 Copyright (c) 2007-2023 the FFmpeg developers
  built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x13c804ae0] st: 0 edit list: 1 Missing key frame while searching for timestamp: 1000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x13c804ae0] st: 0 edit list 1 Cannot find an index entry before timestamp: 1000.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : XAVC
    minor_version   : 16785407
    compatible_brands: XAVCmp42iso2
    creation_time   : 2023-05-16T22:35:07.000000Z
  Duration: 00:02:23.04, start: 0.000000, bitrate: 98555 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/iec61966-2-4, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 96812 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2023-05-16T22:35:07.000000Z
      handler_name    : Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](und): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2023-05-16T22:35:07.000000Z
      handler_name    : Sound Media Handler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](und): Data: none (rtmd / 0x646D7472), 204 kb/s (default)
    Metadata:
      creation_time   : 2023-05-16T22:35:07.000000Z
      handler_name    : Timed Metadata Media Handler
      timecode        : 14:54:11:01
Unsupported codec with id 0 for input stream 2
IVAN-QX commented 10 months ago

Have the same issue when i used ffpyplayer 4.3.5 it printed:

[ffpyplayer_abuffersink @ 0x600002fe8790] Removing channel layout 0x4, redundant with 1 channels

downgrading to 4.3.5 not very good. it fixes the issue but video frames on the left shows some short lines like confusion in frames I'm using kivy for video showing

IVAN-QX commented 8 months ago

@blsqr the audio codec i think of this video isn't mp3 or ogg i tried to play wav on 4.5 and gave the same error but works fine when convert it to mp3 the change between 4.3.5 and 4.5 is ability to play wav and other codecs change the audio codec of your video to be mp3

blsqr commented 8 months ago

Thanks for sharing this, @IVAN-QX! Unfortunately, I don't have the option of changing audio codecs, I need to work with the existing videos and cannot re-encode them.

Also, the fact that ffplay has no issues with playing the audio and it previously working suggests that something else might be going on 🤔