Added support for using libswscale
This commit is contained in:
parent
97e987a9d9
commit
fb54fd0a69
@ -20,6 +20,7 @@ IF(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(FFMPEG_LIBAVDEVICE libavdevice)
|
||||
pkg_check_modules(FFMPEG_LIBAVCODEC libavcodec)
|
||||
pkg_check_modules(FFMPEG_LIBAVUTIL libavutil)
|
||||
pkg_check_modules(FFMPEG_LIBSWSCALE libswscale)
|
||||
|
||||
ENDIF(PKG_CONFIG_FOUND)
|
||||
|
||||
|
@ -1,11 +1,35 @@
|
||||
# INCLUDE_DIRECTORIES( ${FFMPEG_INCLUDE_DIRS} )
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/libavdevice ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/ffmpeg
|
||||
)
|
||||
IF (FFMPEG_LIBSWSCALE_FOUND)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/libavdevice ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBSWSCALE_INCLUDE_DIRS} ${FFMPEG_LIBSWSCALE_INCLUDE_DIRS}/libswscale ${FFMPEG_LIBSWSCALE_INCLUDE_DIRS}/ffmpeg
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DUSE_SWSCALE)
|
||||
|
||||
LINK_DIRECTORIES(${FFMPEG_LIBRARY_DIRS})
|
||||
|
||||
SET(TARGET_EXTERNAL_LIBRARIES ${FFMPEG_LIBRARIES} ${FFMPEG_LIBSWSCALE_LIBRARIES})
|
||||
|
||||
ELSE(FFMPEG_LIBSWSCALE_FOUND)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/libavdevice ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/ffmpeg
|
||||
${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/libavcodec ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/ffmpeg
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(${FFMPEG_LIBRARY_DIRS})
|
||||
|
||||
SET(TARGET_EXTERNAL_LIBRARIES ${FFMPEG_LIBRARIES} )
|
||||
|
||||
ENDIF()
|
||||
|
||||
# MESSAGE("FFMPEG_LIBAVFORMAT_INCLUDE_DIRS = " ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} )
|
||||
# MESSAGE("FFMPEG_LIBAVDEVICE_INCLUDE_DIRS = " ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} )
|
||||
@ -36,9 +60,6 @@ SET(TARGET_H
|
||||
MessageQueue.hpp
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(${FFMPEG_LIBRARY_DIRS})
|
||||
|
||||
SET(TARGET_EXTERNAL_LIBRARIES ${FFMPEG_LIBRARIES} )
|
||||
|
||||
|
||||
#### end var setup ###
|
||||
|
@ -5,12 +5,14 @@
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
|
||||
#if 0
|
||||
extern "C"
|
||||
{
|
||||
int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src,
|
||||
int src_pix_fmt, int src_width, int src_height);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace osgFFmpeg {
|
||||
|
||||
@ -27,7 +29,8 @@ FFmpegDecoderVideo::FFmpegDecoderVideo(PacketQueue & packets, FFmpegClocks & clo
|
||||
m_packet_pts(AV_NOPTS_VALUE),
|
||||
m_user_data(0),
|
||||
m_publish_func(0),
|
||||
m_exit(false)
|
||||
m_exit(false),
|
||||
m_swscale_ctx(0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -41,6 +44,12 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
|
||||
m_exit = true;
|
||||
join();
|
||||
}
|
||||
|
||||
if (m_swscale_ctx)
|
||||
{
|
||||
sws_freeContext(m_swscale_ctx);
|
||||
m_swscale_ctx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -210,6 +219,25 @@ void FFmpegDecoderVideo::findAspectRatio()
|
||||
m_aspect_ratio = ratio;
|
||||
}
|
||||
|
||||
int FFmpegDecoderVideo::convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src,
|
||||
int src_pix_fmt, int src_width, int src_height)
|
||||
{
|
||||
#ifdef USE_SWSCALE
|
||||
if (m_swscale_ctx==0)
|
||||
{
|
||||
m_swscale_ctx = sws_getContext(src_width, src_height, src_pix_fmt,
|
||||
src_width, src_height, dst_pix_fmt,
|
||||
SWS_BILINEAR, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
return sws_scale(m_swscale_ctx,
|
||||
src->data, src->linesize, 0, src_height,
|
||||
dst->data, dst->linesize);
|
||||
#else
|
||||
return convert(dst, dst_pix_fmt, src,
|
||||
src_pix_fmt, src_width, src_height)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void FFmpegDecoderVideo::publishFrame(const double delay)
|
||||
@ -230,7 +258,7 @@ void FFmpegDecoderVideo::publishFrame(const double delay)
|
||||
if (m_context->pix_fmt == PIX_FMT_YUVA420P)
|
||||
yuva420pToRgba(dst, src, width(), height());
|
||||
else
|
||||
img_convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height());
|
||||
convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height());
|
||||
|
||||
// Flip and swap buffer
|
||||
swapBuffers();
|
||||
@ -266,7 +294,7 @@ void FFmpegDecoderVideo::swapBuffers()
|
||||
|
||||
void FFmpegDecoderVideo::yuva420pToRgba(AVPicture * const dst, const AVPicture * const src, int width, int height)
|
||||
{
|
||||
img_convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width, height);
|
||||
convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width, height);
|
||||
|
||||
const size_t bpp = 4;
|
||||
|
||||
|
@ -89,34 +89,42 @@ private:
|
||||
double synchronizeVideo(double pts);
|
||||
void yuva420pToRgba(AVPicture *dst, const AVPicture *src, int width, int height);
|
||||
|
||||
int convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src,
|
||||
int src_pix_fmt, int src_width, int src_height);
|
||||
|
||||
|
||||
static int getBuffer(AVCodecContext * context, AVFrame * picture);
|
||||
static void releaseBuffer(AVCodecContext * context, AVFrame * picture);
|
||||
|
||||
PacketQueue & m_packets;
|
||||
FFmpegClocks & m_clocks;
|
||||
AVStream * m_stream;
|
||||
AVCodecContext * m_context;
|
||||
AVCodec * m_codec;
|
||||
const uint8_t * m_packet_data;
|
||||
int m_bytes_remaining;
|
||||
int64_t m_packet_pts;
|
||||
PacketQueue & m_packets;
|
||||
FFmpegClocks & m_clocks;
|
||||
AVStream * m_stream;
|
||||
AVCodecContext * m_context;
|
||||
AVCodec * m_codec;
|
||||
const uint8_t * m_packet_data;
|
||||
int m_bytes_remaining;
|
||||
int64_t m_packet_pts;
|
||||
|
||||
FramePtr m_frame;
|
||||
FramePtr m_frame_rgba;
|
||||
Buffer m_buffer_rgba;
|
||||
Buffer m_buffer_rgba_public;
|
||||
FramePtr m_frame;
|
||||
FramePtr m_frame_rgba;
|
||||
Buffer m_buffer_rgba;
|
||||
Buffer m_buffer_rgba_public;
|
||||
|
||||
void * m_user_data;
|
||||
PublishFunc m_publish_func;
|
||||
void * m_user_data;
|
||||
PublishFunc m_publish_func;
|
||||
|
||||
double m_frame_rate;
|
||||
double m_aspect_ratio;
|
||||
int m_width;
|
||||
int m_height;
|
||||
size_t m_next_frame_index;
|
||||
bool m_alpha_channel;
|
||||
double m_frame_rate;
|
||||
double m_aspect_ratio;
|
||||
int m_width;
|
||||
int m_height;
|
||||
size_t m_next_frame_index;
|
||||
bool m_alpha_channel;
|
||||
|
||||
volatile bool m_exit;
|
||||
volatile bool m_exit;
|
||||
|
||||
#if USE_SWSCALE
|
||||
struct SwsContext * m_swscale_ctx;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@ -9,6 +9,11 @@ extern "C"
|
||||
#include <stdint.h>
|
||||
#include <avcodec.h>
|
||||
#include <avformat.h>
|
||||
|
||||
#ifdef USE_SWSCALE
|
||||
#include <swscale.h>
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,9 @@ public:
|
||||
if (! acceptsExtension(ext))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
const std::string path = osgDB::findDataFile(filename, options);
|
||||
const std::string path = osgDB::containsServerAddress(filename) ?
|
||||
filename :
|
||||
osgDB::findDataFile(filename, options);
|
||||
|
||||
if (path.empty())
|
||||
return ReadResult::FILE_NOT_FOUND;
|
||||
|
Loading…
Reference in New Issue
Block a user