Bug 214247

Summary: multimedia/py-ffmpeg: fails to build with ffmpeg 3.x
Product: Ports & Packages Reporter: Jan Beich <jbeich>
Component: Individual Port(s)Assignee: Jan Beich <jbeich>
Status: Closed FIXED    
Severity: Affects Only Me CC: dbn
Priority: --- Keywords: patch, patch-ready
Version: LatestFlags: dbn: maintainer-feedback+
Hardware: Any   
OS: Any   
See Also: https://github.com/tito/ffmpeg-android/pull/4
Bug Depends on:    
Bug Blocks: 207547    
Attachments:
Description Flags
fix, v1
dbn: maintainer-approval+
followup fix dbn: maintainer-approval+

Description Jan Beich freebsd_committer 2016-11-05 17:21:09 UTC
ffmpeg/_ffmpeg.c:8559:23: error: no member named 'get_buffer' in 'struct AVCodecContext'; did you mean 'get_buffer2'?
    __pyx_v_codecCtx->get_buffer = __pyx_f_6ffmpeg_7_ffmpeg_our_get_buffer;
                      ^~~~~~~~~~
                      get_buffer2
/usr/local/include/libavcodec/avcodec.h:2565:11: note: 'get_buffer2' declared here
    int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
          ^
ffmpeg/_ffmpeg.c:8568:23: error: no member named 'release_buffer' in 'struct AVCodecContext'
    __pyx_v_codecCtx->release_buffer = __pyx_f_6ffmpeg_7_ffmpeg_our_release_buffer;
    ~~~~~~~~~~~~~~~~  ^

http://package23.nyi.freebsd.org/data/103i386-default-PR207547/2016-10-04_18h24m30s/logs/errors/py27-ffmpeg-1.2.4_2.log
Comment 1 Jan Beich freebsd_committer 2016-11-05 18:27:03 UTC
Created attachment 176663 [details]
fix, v1

FreeBSD 10.1 i386 + ffmpeg 2.8 build log: http://sprunge.us/USMX

from libavcodec/avcodec.h:
  /**
   * The default callback for AVCodecContext.get_buffer2(). It is made public so
   * it can be called by custom get_buffer2() implementations for decoders without
   * AV_CODEC_CAP_DR1 set.
   */
  int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
Comment 2 David Naylor freebsd_committer 2016-11-06 08:03:28 UTC
I'm currently AFK, please commit this change. Otherwise I can attend to it after 21 November. 

Also, if you avoid renaming avcodec_alloc_frame to av_alloc_frame, the diff will be smaller.
Comment 3 Jan Beich freebsd_committer 2016-11-06 08:10:13 UTC
Rename cannot be avoided, the old API is gone.

  >>> import ffmpeg
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python2.7/site-packages/ffmpeg/__init__.py", line 12, in <module>
      from _ffmpeg import FFVideo, FFVideoException
  ImportError: /usr/local/lib/python2.7/site-packages/ffmpeg/_ffmpeg.so: Undefined symbol "avcodec_alloc_frame"

doc/APIchanges says:

  2013-12-11 - 29c83d2 / b9fb59d,409a143 / 9431356,44967ab / d7b3ee9 - lavc 55.45.101 / 55.28.1 - avco\
  dec.h
    av_frame_alloc(), av_frame_unref() and av_frame_free() now can and should be
    used instead of avcodec_alloc_frame(), avcodec_get_frame_defaults() and
    avcodec_free_frame() respectively. The latter three functions are deprecated.

https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=8f12ef9860d0
Comment 4 commit-hook freebsd_committer 2016-11-06 08:14:21 UTC
A commit references this bug:

Author: jbeich
Date: Sun Nov  6 08:14:04 UTC 2016
New revision: 425471
URL: https://svnweb.freebsd.org/changeset/ports/425471

Log:
  multimedia/py-ffmpeg: unbreak build with ffmpeg 3.x

  ffmpeg/_ffmpeg.c:8559:23: error: no member named 'get_buffer' in 'struct AVCodecContext'; did you mean 'get_buffer2'?
      __pyx_v_codecCtx->get_buffer = __pyx_f_6ffmpeg_7_ffmpeg_our_get_buffer;
                        ^~~~~~~~~~
                        get_buffer2
  /usr/local/include/libavcodec/avcodec.h:2565:11: note: 'get_buffer2' declared here
      int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
            ^
  ffmpeg/_ffmpeg.c:8568:23: error: no member named 'release_buffer' in 'struct AVCodecContext'
      __pyx_v_codecCtx->release_buffer = __pyx_f_6ffmpeg_7_ffmpeg_our_release_buffer;
      ~~~~~~~~~~~~~~~~  ^

  PR:		214247
  Approved by:	dbn (maintainer)

Changes:
  head/multimedia/py-ffmpeg/Makefile
  head/multimedia/py-ffmpeg/files/patch-ffmpeg___ffmpeg.pxi
  head/multimedia/py-ffmpeg/files/patch-ffmpeg___ffmpeg.pyx
Comment 5 Jan Beich freebsd_committer 2016-11-06 09:19:34 UTC
Created attachment 176677 [details]
followup fix

One more change maybe required. However, ffmpeg/__init__.py (uses py-kivy) works "fine" without. It's hard to measure A/V sync when video rendering is too slow to catch up to audio. This occured even before the fixes here.
Comment 6 commit-hook freebsd_committer 2016-11-07 10:48:48 UTC
A commit references this bug:

Author: jbeich
Date: Mon Nov  7 10:48:18 UTC 2016
New revision: 425603
URL: https://svnweb.freebsd.org/changeset/ports/425603

Log:
  multimedia/py-ffmpeg: adjust pts after r425471

  AVFrame.pkt_pts didn't exist in ffmpeg-4f7d2fe-2010-12-16 snapshot when
  global_video_pkt_pts was added to py-ffmpeg. The code worked it around by
  saving PTS in AVFrame.opaque just before avcodec_decode_video2() call. This
  broke when r425471 removed our_get_buffer(). So, just use AVFrame.pkt_pts
  directly now.

  PR:		214247
  Approved by:	dbn (maintainer)

Changes:
  head/multimedia/py-ffmpeg/Makefile
  head/multimedia/py-ffmpeg/files/patch-ffmpeg___ffmpeg.pxi
  head/multimedia/py-ffmpeg/files/patch-ffmpeg___ffmpeg.pyx
Comment 7 Jan Beich freebsd_committer 2016-11-07 10:50:02 UTC
Note, FFmpeg 3.2 / libav v12 have https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=32c8359093d1