mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
bring ffmpeg, opencv into new interface
This commit is contained in:
parent
3bd0d132b3
commit
efad95a5ea
@ -46,6 +46,7 @@ FFMpegTexture(const FFMpegTexture ©) :
|
|||||||
VideoTexture(copy),
|
VideoTexture(copy),
|
||||||
_pages(copy._pages)
|
_pages(copy._pages)
|
||||||
{
|
{
|
||||||
|
nassertv(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -59,8 +60,8 @@ FFMpegTexture::
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: FFMpegTexture::make_copy
|
// Function: FFMpegTexture::do_make_copy
|
||||||
// Access: Published, Virtual
|
// Access: Protected, Virtual
|
||||||
// Description: Returns a new copy of the same Texture. This copy,
|
// Description: Returns a new copy of the same Texture. This copy,
|
||||||
// if applied to geometry, will be copied into texture
|
// if applied to geometry, will be copied into texture
|
||||||
// as a separate texture from the original, so it will
|
// as a separate texture from the original, so it will
|
||||||
@ -72,10 +73,23 @@ FFMpegTexture::
|
|||||||
// original.
|
// original.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PT(Texture) FFMpegTexture::
|
PT(Texture) FFMpegTexture::
|
||||||
make_copy() {
|
do_make_copy() {
|
||||||
return new FFMpegTexture(*this);
|
PT(FFMpegTexture) tex = new FFMpegTexture(get_name());
|
||||||
|
tex->do_assign(*this);
|
||||||
|
|
||||||
|
return tex.p();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: FFMpegTexture::do_assign
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Implements make_copy().
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void FFMpegTexture::
|
||||||
|
do_assign(const FFMpegTexture ©) {
|
||||||
|
VideoTexture::do_assign(copy);
|
||||||
|
_pages = copy._pages;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: FFMPegTexture::modify_page
|
// Function: FFMPegTexture::modify_page
|
||||||
@ -95,14 +109,14 @@ modify_page(int z) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: FFmpegTexture::reconsider_video_properties
|
// Function: FFmpegTexture::do_reconsider_video_properties
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Resets the internal Texture properties when a new
|
// Description: Resets the internal Texture properties when a new
|
||||||
// video file is loaded. Returns true if the new image
|
// video file is loaded. Returns true if the new image
|
||||||
// is valid, false otherwise.
|
// is valid, false otherwise.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool FFMpegTexture::
|
bool FFMpegTexture::
|
||||||
reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
|
do_reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
|
||||||
int num_components, int z) {
|
int num_components, int z) {
|
||||||
double frame_rate = 0.0f;
|
double frame_rate = 0.0f;
|
||||||
int num_frames = 0;
|
int num_frames = 0;
|
||||||
@ -146,7 +160,7 @@ reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
|
|||||||
<< y_size << " texels.\n";
|
<< y_size << " texels.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reconsider_image_properties(x_size, y_size, num_components,
|
if (!do_reconsider_image_properties(x_size, y_size, num_components,
|
||||||
T_unsigned_byte, z)) {
|
T_unsigned_byte, z)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -334,12 +348,12 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
set_name(fullpath.get_basename_wo_extension());
|
set_name(fullpath.get_basename_wo_extension());
|
||||||
}
|
}
|
||||||
if (!has_filename()) {
|
if (!has_filename()) {
|
||||||
set_filename(fullpath);
|
_filename = fullpath;
|
||||||
set_alpha_filename(alpha_fullpath);
|
_alpha_filename = alpha_fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_fullpath(fullpath);
|
_fullpath = fullpath;
|
||||||
set_alpha_fullpath(alpha_fullpath);
|
_alpha_fullpath = alpha_fullpath;
|
||||||
}
|
}
|
||||||
if (page._color._codec_context->pix_fmt==PIX_FMT_RGBA32) {
|
if (page._color._codec_context->pix_fmt==PIX_FMT_RGBA32) {
|
||||||
// There had better not be an alpha interleave here.
|
// There had better not be an alpha interleave here.
|
||||||
@ -347,7 +361,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
|
|
||||||
_primary_file_num_channels = 4;
|
_primary_file_num_channels = 4;
|
||||||
_alpha_file_channel = 0;
|
_alpha_file_channel = 0;
|
||||||
if (!reconsider_video_properties(page._color, 4, z)) {
|
if (!do_reconsider_video_properties(page._color, 4, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -357,18 +371,18 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
_alpha_file_channel = alpha_file_channel;
|
_alpha_file_channel = alpha_file_channel;
|
||||||
|
|
||||||
if (page._alpha.is_valid()) {
|
if (page._alpha.is_valid()) {
|
||||||
if (!reconsider_video_properties(page._color, 4, z)) {
|
if (!do_reconsider_video_properties(page._color, 4, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!reconsider_video_properties(page._alpha, 4, z)) {
|
if (!do_reconsider_video_properties(page._alpha, 4, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!reconsider_video_properties(page._color, 3, z)) {
|
if (!do_reconsider_video_properties(page._color, 3, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,12 +38,13 @@ protected:
|
|||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
virtual ~FFMpegTexture();
|
virtual ~FFMpegTexture();
|
||||||
|
|
||||||
virtual PT(Texture) make_copy();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static PT(Texture) make_texture();
|
static PT(Texture) make_texture();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual PT(Texture) do_make_copy();
|
||||||
|
void do_assign(const FFMpegTexture ©);
|
||||||
|
|
||||||
virtual void update_frame(int frame);
|
virtual void update_frame(int frame);
|
||||||
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||||
int z, int n, int primary_file_num_channels, int alpha_file_channel,
|
int z, int n, int primary_file_num_channels, int alpha_file_channel,
|
||||||
@ -56,7 +57,7 @@ private:
|
|||||||
class VideoStream;
|
class VideoStream;
|
||||||
|
|
||||||
VideoPage &modify_page(int z);
|
VideoPage &modify_page(int z);
|
||||||
bool reconsider_video_properties(const VideoStream &stream,
|
bool do_reconsider_video_properties(const VideoStream &stream,
|
||||||
int num_components, int z);
|
int num_components, int z);
|
||||||
void do_update();
|
void do_update();
|
||||||
|
|
||||||
|
@ -421,6 +421,8 @@ do_make_copy() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void MovieTexture::
|
void MovieTexture::
|
||||||
do_assign(const MovieTexture ©) {
|
do_assign(const MovieTexture ©) {
|
||||||
|
Texture::do_assign(copy);
|
||||||
|
|
||||||
// Since 'make_copy' can be a slow operation,
|
// Since 'make_copy' can be a slow operation,
|
||||||
// I release the read lock before calling make_copy.
|
// I release the read lock before calling make_copy.
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ OpenCVTexture(const OpenCVTexture ©) :
|
|||||||
VideoTexture(copy),
|
VideoTexture(copy),
|
||||||
_pages(copy._pages)
|
_pages(copy._pages)
|
||||||
{
|
{
|
||||||
|
nassertv(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -58,8 +59,8 @@ OpenCVTexture::
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: OpenCVTexture::make_copy
|
// Function: OpenCVTexture::do_make_copy
|
||||||
// Access: Published, Virtual
|
// Access: Protected, Virtual
|
||||||
// Description: Returns a new copy of the same Texture. This copy,
|
// Description: Returns a new copy of the same Texture. This copy,
|
||||||
// if applied to geometry, will be copied into texture
|
// if applied to geometry, will be copied into texture
|
||||||
// as a separate texture from the original, so it will
|
// as a separate texture from the original, so it will
|
||||||
@ -71,8 +72,22 @@ OpenCVTexture::
|
|||||||
// original.
|
// original.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PT(Texture) OpenCVTexture::
|
PT(Texture) OpenCVTexture::
|
||||||
make_copy() {
|
do_make_copy() {
|
||||||
return new OpenCVTexture(*this);
|
PT(OpenCVTexture) tex = new OpenCVTexture(get_name());
|
||||||
|
tex->do_assign(*this);
|
||||||
|
|
||||||
|
return tex.p();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: OpenCVTexture::do_assign
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Implements make_copy().
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void OpenCVTexture::
|
||||||
|
do_assign(const OpenCVTexture ©) {
|
||||||
|
VideoTexture::do_assign(copy);
|
||||||
|
_pages = copy._pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -85,7 +100,7 @@ make_copy() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool OpenCVTexture::
|
bool OpenCVTexture::
|
||||||
from_camera(int camera_index, int z) {
|
from_camera(int camera_index, int z) {
|
||||||
if (!reconsider_z_size(z)) {
|
if (!do_reconsider_z_size(z)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nassertr(z >= 0 && z < get_z_size(), false);
|
nassertr(z >= 0 && z < get_z_size(), false);
|
||||||
@ -96,7 +111,7 @@ from_camera(int camera_index, int z) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reconsider_video_properties(page._color, 3, z)) {
|
if (!do_reconsider_video_properties(page._color, 3, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -125,14 +140,14 @@ modify_page(int z) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: OpenCVTexture::reconsider_video_properties
|
// Function: OpenCVTexture::do_reconsider_video_properties
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Resets the internal Texture properties when a new
|
// Description: Resets the internal Texture properties when a new
|
||||||
// video file is loaded. Returns true if the new image
|
// video file is loaded. Returns true if the new image
|
||||||
// is valid, false otherwise.
|
// is valid, false otherwise.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool OpenCVTexture::
|
bool OpenCVTexture::
|
||||||
reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
|
do_reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
|
||||||
int num_components, int z) {
|
int num_components, int z) {
|
||||||
double frame_rate = 0.0f;
|
double frame_rate = 0.0f;
|
||||||
int num_frames = 0;
|
int num_frames = 0;
|
||||||
@ -164,7 +179,7 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
|
|||||||
<< y_size << " texels.\n";
|
<< y_size << " texels.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reconsider_image_properties(x_size, y_size, num_components,
|
if (!do_reconsider_image_properties(x_size, y_size, num_components,
|
||||||
T_unsigned_byte, z)) {
|
T_unsigned_byte, z)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -334,7 +349,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
|
|
||||||
if (alpha_fullpath.empty()) {
|
if (alpha_fullpath.empty()) {
|
||||||
// Only one RGB movie.
|
// Only one RGB movie.
|
||||||
if (!reconsider_video_properties(page._color, 3, z)) {
|
if (!do_reconsider_video_properties(page._color, 3, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -343,13 +358,13 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
// An RGB movie combined with an alpha movie.
|
// An RGB movie combined with an alpha movie.
|
||||||
_alpha_file_channel = alpha_file_channel;
|
_alpha_file_channel = alpha_file_channel;
|
||||||
|
|
||||||
if (!reconsider_video_properties(page._color, 4, z)) {
|
if (!do_reconsider_video_properties(page._color, 4, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reconsider_video_properties(page._alpha, 4, z)) {
|
if (!do_reconsider_video_properties(page._alpha, 4, z)) {
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
return false;
|
return false;
|
||||||
|
@ -39,14 +39,15 @@ protected:
|
|||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
virtual ~OpenCVTexture();
|
virtual ~OpenCVTexture();
|
||||||
|
|
||||||
virtual PT(Texture) make_copy();
|
|
||||||
|
|
||||||
bool from_camera(int camera_index = -1, int z = 0);
|
bool from_camera(int camera_index = -1, int z = 0);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static PT(Texture) make_texture();
|
static PT(Texture) make_texture();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual PT(Texture) do_make_copy();
|
||||||
|
void do_assign(const FFMpegTexture ©);
|
||||||
|
|
||||||
virtual void update_frame(int frame);
|
virtual void update_frame(int frame);
|
||||||
|
|
||||||
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||||
@ -60,7 +61,7 @@ private:
|
|||||||
class VideoStream;
|
class VideoStream;
|
||||||
|
|
||||||
VideoPage &modify_page(int z);
|
VideoPage &modify_page(int z);
|
||||||
bool reconsider_video_properties(const VideoStream &stream,
|
bool do_reconsider_video_properties(const VideoStream &stream,
|
||||||
int num_components, int z);
|
int num_components, int z);
|
||||||
void do_update();
|
void do_update();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user