summaryrefslogtreecommitdiff
path: root/m4/ffmpeg.m4
blob: d228de8a0026e72a8efae127dd9ce4b69f8a3ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
dnl
dnl autoconf script for searching and checking ffmpeg
dnl
dnl written by Frantisek Dvorak <valtri@users.sourceforge.net>
dnl
dnl
dnl AM_PATH_FFMPEG([ACTION IF FOUND [, ACTION IF NOT FOUND]]))
dnl
dnl It looks for ffmpeg, defines FFMPEG_CPPFLAGS and FFMPEG_LIBS.
dnl
AC_DEFUN([AM_PATH_FFMPEG], [

AC_ARG_WITH(external-ffmpeg, AC_HELP_STRING([--with-external-ffmpeg@<:@=DIR@:>@], [use external ffmpeg library]),
  [external_ffmpeg="$withval"],
  [external_ffmpeg="no"]
)

if test x"$external_ffmpeg" != "xno"; then
  
  dnl get the prefix, if specified
  if test x"$external_ffmpeg" != "xyes"; then
    ffmpeg_prefix="$withval"
  fi
  
  dnl disable test if requested
  AC_ARG_ENABLE(ffmpegtest,
    AC_HELP_STRING([--disable-ffmpegtest],
      [Do not try compile and run a test ffmpeg program. It will need specify custom FFMPEG_CPPFLAGS and FFMPEG_LIBS environment variables.]
    ),
    enable_ffmpegtest="$enableval",
    enable_ffmpegtest=yes
  )
  
  if test x"$enable_ffmpegtest" = "xyes"; then
    ac_save_LDFLAGS="${LDFLAGS}"
    ac_save_CPPFLAGS="${CPPFLAGS}"
    external_ffmpeg_found=no
  
    dnl look for the ffmpeg or just check specified flags
    if test x"$FFMPEG_CPPFLAGS" = "x" -a x"$FFMPEG_LIBS" = "x"; then
      dnl look for ffmpeg
      if test x"$ffmpeg_prefix" = "x"; then
        prefixes="/usr /usr/local /opt"
      else
        prefixes="$ffmpeg_prefix"
      fi
      for dir in $prefixes; do
        FFMPEG_CPPFLAGS="-I${dir}/include/ffmpeg -I${dir}/include/postproc"
        FFMPEG_LIBS="-L${dir}/lib"
        CPPFLAGS="${FFMPEG_CPPFLAGS} ${ac_save_CPPFLAGS}"
        LDFLAGS="${FFMPEG_LIBS} ${ac_save_LDFLAGS}"
  
        dnl drop the cache
        for i in "ac_cv_header_avcodec_h" "ac_cv_header_postprocess_h" \
                 "ac_cv_lib_avcodec_pp_get_context" \
                 "ac_cv_lib_postproc_pp_get_context" \
                 "ac_cv_lib_avcodec_register_avcodec"; do
          $as_unset $i || test "${$i+set}" != set || { $i=; export $i; }
        done

        dnl look for headers
        AC_CHECK_HEADER(avcodec.h, , continue)
        AC_CHECK_HEADER(postprocess.h, , continue)

        dnl look for libpostproc inside libavcodec
        AC_CHECK_LIB(avcodec, pp_get_context,
          [external_ffmpeg_found=yes
          FFMPEG_LIBS="${FFMPEG_LIBS} -lavcodec"
          break],
          ,
          []
        )

        dnl look for shared libpostproc and avcodec
        AC_CHECK_LIB(postproc, pp_get_context, 
          AC_CHECK_LIB(avcodec, register_avcodec,
            [external_ffmpeg_found=yes
            FFMPEG_LIBS="${FFMPEG_LIBS} -lavcodec -lpostproc"
            break]
          ),,
          [-lavcodec]
        )
      done
  
      dnl result of autodetection
      if test x"$external_ffmpeg_found" = "xyes"; then
        AC_MSG_RESULT([External ffmpeg library was found in ${dir}.])
      else
        AC_MSG_ERROR([External ffmpeg library not found.
*********************************************************************
You can try to specify prefix of ffmpeg library by the option
--with-external-ffmpeg=prefix, or to specify custom FFMPEG_CPPFLAGS
and FFMPEG_LIBS.

If you would like to use the internal ffmpeg, please remove the
configure option --with-external-ffmpeg.
*********************************************************************])
      fi
    else
      dnl check specified flags
      CPPFLAGS="${FFMPEG_CPPFLAGS} ${ac_save_CPPFLAGS}"
      LDFLAGS="${FFMPEG_LIBS} ${ac_save_LDFLAGS}"
      AC_LINK_IFELSE([#include <avcodec.h>
#include <postprocess.h>
 
int main() {
  register_avcodec((void *)0);
  pp_get_context(0, 0, 0);
}
],
        [external_ffmpeg_found=yes],
        [external_ffmpeg_found=no],
      )

      dnl result
      if test x"$external_ffmpeg_found" = "xyes"; then
        AC_MSG_RESULT([Using custom FFMPEG_CPPFLAGS and FFMPEG_LIBS for external ffmpeg.])
      else
        AC_MSG_ERROR([External ffmpeg library not found with specified options.
*********************************************************************
You can try to specify prefix of ffmpeg library by the option
--with-external-ffmpeg=prefix, or to specify different
FFMPEG_CPPFLAGS and FFMPEG_LIBS.

If you would like to use the internal ffmpeg, please remove the
configure option --with-external-ffmpeg.
*********************************************************************])
      fi
    fi
    CPPFLAGS="${ac_save_CPPFLAGS}"
    LDFLAGS="${ac_save_LDFLAGS}"
  else
    if test x"${FFMPEG_CPPFLAGS}" = "x" -a x"${FFMPEG_LIBS}" = "x"; then
      external_ffmpeg_found=no
      AC_MSG_ERROR([You should specify FFMPEG_CPPFLAGS and FFMPEG_LIBS.])
    else
      external_ffmpeg_found=yes
      AC_MSG_RESULT([Forced using custom FFMPEG_CPPFLAGS and FFMPEG_LIBS.])
    fi
  fi


  dnl result
  if test x"$external_ffmpeg_found" = "xyes"; then
    dnl common warning
    AC_MSG_NOTICE([
*********************************************************************
xine is configured with external ffmpeg.

This requires the same version of ffmpeg what is included in xine and
you should know what you do. If some problems occur, please try to
use internal ffmpeg.
*********************************************************************])
    ifelse([$1], , :, [$1])
  else
    ifelse([$2], , :, [$2])
  fi
  
  AC_SUBST(FFMPEG_CPPFLAGS)
  AC_SUBST(FFMPEG_LIBS)
  
else
  AC_MSG_RESULT([using included ffmpeg])
fi

])