Description: Improve detection of av_register_protocol() for ffmpeg. Author: Angel Carpintero Origin: Upstream, https://github.com/sackmotion/motion/commit/7aec4b#svn538 Last-Update: 2012-02-12 --- a/configure.in +++ b/configure.in @@ -316,7 +316,7 @@ # else if test "${FFMPEG_DIR}" = "yes"; then # AUTODETECT STATIC/SHARED LIB - AC_MSG_CHECKING(for ffmpeg autodetecting) + AC_MSG_CHECKING(for ffmpeg autodetecting libraries) if test -f /usr/lib64/libavcodec.a -o -f /usr/lib64/libavcodec.so && test -f /usr/lib64/libavformat.a -o -f /usr/lib64/libavformat.so ; then AC_MSG_RESULT(found in /usr/lib64) @@ -347,7 +347,7 @@ echo "" fi else - AC_MSG_CHECKING(for ffmpeg in -> [${FFMPEG_DIR}] <-) + AC_MSG_CHECKING(for ffmpeg libraries in -> [${FFMPEG_DIR}] <-) if test -f ${FFMPEG_DIR}/lib/libavcodec.a -o -f ${FFMPEG_DIR}/lib/libavcodec.so && test -f ${FFMPEG_DIR}/lib/libavformat.a -o -f ${FFMPEG_DIR}/lib/libavformat.so ; then AC_MSG_RESULT(found) FFMPEG_OK="found" @@ -392,9 +392,11 @@ elif test -f ${FFMPEG_DIR}/include/libavformat/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/libavformat/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include -DFFMPEG_NEW_INCLUDES" + AVFORMAT="-I${FFMPEG_DIR}/include/libavformat" elif test -f ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include/ffmpeg -DFFMPEG_NEW_INCLUDES" + AVFORMAT="-I${FFMPEG_DIR}/include/ffmpeg/libavformat" else AC_MSG_RESULT(not found) FFMPEG_OK="no_found" @@ -423,9 +425,11 @@ AC_MSG_CHECKING([file_protocol is defined in ffmpeg ?]) saved_CFLAGS=$CFLAGS saved_LIBS=$LIBS - CFLAGS="${FFMPEG_CFLAGS}" + + + CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" LIBS="$TEMP_LIBS" - + AC_COMPILE_IFELSE( [ #include @@ -442,7 +446,35 @@ ] ) CFLAGS=$saved_CFLAGS - LIBS=$saved_LIBS + LIBS=$saved_LIBS + + AC_MSG_CHECKING([av_register_protocol is defined in ffmpeg ?]) + saved_CFLAGS=$CFLAGS + saved_LIBS=$LIBS + CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" + LIBS="$TEMP_LIBS" + + AC_COMPILE_IFELSE( + [ + #include + URLProtocol test_file_protocol; + int main(void){ + av_register_protocol(&test_file_protocol); + return 0; + } + ], + [ + AC_MSG_RESULT(yes) + TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_AV_REGISTER_PROTOCOL" + ], + [ + AC_MSG_RESULT(no) + ] + ) + + CFLAGS=$saved_CFLAGS + LIBS=$saved_LIBS + fi fi fi --- a/ffmpeg.c +++ b/ffmpeg.c @@ -232,11 +232,11 @@ mpeg1_file_protocol.url_seek = file_protocol.url_seek; mpeg1_file_protocol.url_close = file_protocol.url_close; - /* Register the append file protocol. */ -#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8) +/* Register the append file protocol. */ +#ifdef HAVE_FFMPEG_AV_REGISTER_PROTOCOL av_register_protocol(&mpeg1_file_protocol); #else - register_protocol(&mpeg1_file_protocol); + av_register_protocol2(&mpeg1_file_protocol, sizeof(mpeg1_file_protocol)); #endif } @@ -410,7 +410,11 @@ ffmpeg->c = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st); c->codec_id = ffmpeg->oc->oformat->video_codec; +#if LIBAVCODEC_VERSION_MAJOR < 53 c->codec_type = CODEC_TYPE_VIDEO; +#else + c->codec_type = AVMEDIA_TYPE_VIDEO; +#endif is_mpeg1 = c->codec_id == CODEC_ID_MPEG1VIDEO; if (strcmp(ffmpeg_video_codec, "ffv1") == 0) @@ -679,7 +683,11 @@ if (ffmpeg->oc->oformat->flags & AVFMT_RAWPICTURE) { /* raw video case. The API will change slightly in the near future for that */ #ifdef FFMPEG_AVWRITEFRAME_NEWAPI +#if LIBAVCODEC_VERSION_MAJOR < 53 pkt.flags |= PKT_FLAG_KEY; +#else + pkt.flags |= AV_PKT_FLAG_KEY; +#endif pkt.data = (uint8_t *)pic; pkt.size = sizeof(AVPicture); ret = av_write_frame(ffmpeg->oc, &pkt); @@ -700,7 +708,11 @@ #ifdef FFMPEG_AVWRITEFRAME_NEWAPI pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts; if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame) { +#if LIBAVCODEC_VERSION_MAJOR < 53 pkt.flags |= PKT_FLAG_KEY; +#else + pkt.flags |= AV_PKT_FLAG_KEY; +#endif } pkt.data = ffmpeg->video_outbuf; pkt.size = out_size;