summaryrefslogtreecommitdiff
path: root/m4/ffmpeg.m4
blob: f413a74f7dde33f6c840908869ba2d69cbff7fb7 (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
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_CFLAGS and FFMPEG_LIBS.
dnl
AC_DEFUN([AM_PATH_FFMPEG], [

dnl get the prefix, if specified
if test x"$external_ffmpeg" != "xyes" -a x"$external_ffmpeg" != "xno"; 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_CFLAGS 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_CFLAGS" = x -a x"$FFMPEG_LIBS" = x; then
    dnl look for ffmpeg
    if test x"$ffmpeg_prefix" = x; then
      prefixes="$ffmpeg_prefix /usr /usr/local /opt"
    else
      prefixes="$ffmpeg_prefix"
    fi
    for dir in $prefixes; do
      FFMPEG_CFLAGS="-I${dir}/include/ffmpeg -I${dir}/include/postproc"
      FFMPEG_LIBS="-L${dir}/lib"
      CPPFLAGS="${ac_save_CFLAGS} ${FFMPEG_CFLAGS}"
      LDFLAGS="${ac_save_LDFLAGS} ${FFMPEG_LIBS}"

      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 check the headers
      AC_CHECK_HEADERS(avcodec.h postprocess.h,
        [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],
                [continue],
                [-lavcodec]
              )],
              [continue]
            )],
          []
        )],
        [continue]
      )
    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_CFLAGS 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="${ac_save_CFLAGS} ${FFMPEG_CFLAGS}"
    LDFLAGS="${ac_save_LDFLAGS} ${FFMPEG_LIBS}"
    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_CFLAGS 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_CFLAGS 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_CFLAGS}" = "x" -a x"${FFMPEG_LIBS}" = "x"; then
    external_ffmpeg_found=no
    AC_MSG_ERROR([You should specify FFMPEG_CFLAGS and FFMPEG_LIBS])
  else
    external_ffmpeg_found=yes
    AC_MSG_RESULT([Forced using custom FFMPEG_CFLAGS and FFMPEG_LIBS.])
  fi
fi

dnl result
if test x"$external_ffmpeg_found" = "xyes"; then
  ifelse([$1], , :, [$1])
else
  ifelse([$2], , :, [$2])
fi

AC_SUBST(FFMPEG_CFLAGS)
AC_SUBST(FFMPEG_LIBS)

])