mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
fix some issues with video textures
This commit is contained in:
parent
5a44148f12
commit
bcb66a94d7
@ -23,6 +23,7 @@
|
|||||||
#include "clockObject.h"
|
#include "clockObject.h"
|
||||||
#include "config_gobj.h"
|
#include "config_gobj.h"
|
||||||
#include "config_grutil.h"
|
#include "config_grutil.h"
|
||||||
|
#include "bamCacheRecord.h"
|
||||||
|
|
||||||
TypeHandle FFMpegTexture::_type_handle;
|
TypeHandle FFMpegTexture::_type_handle;
|
||||||
|
|
||||||
@ -127,7 +128,7 @@ reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
|
|||||||
//Number of frames is a little questionable if we've got variable
|
//Number of frames is a little questionable if we've got variable
|
||||||
//frame rate. Duration comes in as a generic timestamp,
|
//frame rate. Duration comes in as a generic timestamp,
|
||||||
//and is therefore multiplied by AV_TIME_BASE.
|
//and is therefore multiplied by AV_TIME_BASE.
|
||||||
num_frames = (int(stream.pFormatCtx->duration*frame_rate))/AV_TIME_BASE;
|
num_frames = (int)((stream.pFormatCtx->duration*frame_rate)/AV_TIME_BASE);
|
||||||
if (grutil_cat.is_debug()) {
|
if (grutil_cat.is_debug()) {
|
||||||
grutil_cat.debug()
|
grutil_cat.debug()
|
||||||
<< "Loaded " << stream._filename << ", " << num_frames << " frames at "
|
<< "Loaded " << stream._filename << ", " << num_frames << " frames at "
|
||||||
@ -196,7 +197,8 @@ make_texture() {
|
|||||||
// Description: Called once per frame, as needed, to load the new
|
// Description: Called once per frame, as needed, to load the new
|
||||||
// image contents.
|
// image contents.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void FFMpegTexture::update_frame(int frame) {
|
void FFMpegTexture::
|
||||||
|
update_frame(int frame) {
|
||||||
int max_z = max(_z_size, (int)_pages.size());
|
int max_z = max(_z_size, (int)_pages.size());
|
||||||
for (int z = 0; z < max_z; ++z) {
|
for (int z = 0; z < max_z; ++z) {
|
||||||
VideoPage &page = _pages[z];
|
VideoPage &page = _pages[z];
|
||||||
@ -310,7 +312,12 @@ void FFMpegTexture::update_frame(int frame) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool FFMpegTexture::
|
bool FFMpegTexture::
|
||||||
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
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,
|
||||||
|
BamCacheRecord *record) {
|
||||||
|
if (record != (BamCacheRecord *)NULL) {
|
||||||
|
record->add_dependent_file(fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
nassertr(n == 0, false);
|
nassertr(n == 0, false);
|
||||||
nassertr(z >= 0 && z < get_z_size(), false);
|
nassertr(z >= 0 && z < get_z_size(), false);
|
||||||
|
|
||||||
@ -493,9 +500,6 @@ get_frame_data(int frame) {
|
|||||||
|
|
||||||
int gotFrame;
|
int gotFrame;
|
||||||
|
|
||||||
long long timeStamp=(AV_TIME_BASE/vstream->r_frame_rate.num)*(frame *vstream->r_frame_rate.den);
|
|
||||||
long long currTimeStamp;
|
|
||||||
|
|
||||||
//first find out where to go
|
//first find out where to go
|
||||||
if(frame==comingFrom)
|
if(frame==comingFrom)
|
||||||
{
|
{
|
||||||
@ -507,8 +511,11 @@ get_frame_data(int frame) {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
double timeStamp=((double)AV_TIME_BASE*frame *vstream->r_frame_rate.den)/vstream->r_frame_rate.num;
|
||||||
|
double currTimeStamp;
|
||||||
|
|
||||||
//find point in time
|
//find point in time
|
||||||
int res=av_seek_frame( pFormatCtx,-1, timeStamp,AVSEEK_FLAG_BACKWARD );
|
int res=av_seek_frame( pFormatCtx,-1, (long long)timeStamp,AVSEEK_FLAG_BACKWARD );
|
||||||
|
|
||||||
//Okay, now we're at the nearest keyframe behind our timestamp.
|
//Okay, now we're at the nearest keyframe behind our timestamp.
|
||||||
//Hurry up and move through frames until we find a frame just after it.
|
//Hurry up and move through frames until we find a frame just after it.
|
||||||
@ -517,9 +524,8 @@ get_frame_data(int frame) {
|
|||||||
av_read_frame( pFormatCtx, &packet );
|
av_read_frame( pFormatCtx, &packet );
|
||||||
|
|
||||||
// should really be checking that this is a video packet
|
// should really be checking that this is a video packet
|
||||||
currTimeStamp = (long long)(packet.pts / packet.duration *
|
currTimeStamp = (((double)AV_TIME_BASE * packet.pts) /
|
||||||
AV_TIME_BASE / av_q2d( vstream->r_frame_rate));
|
((double)packet.duration * av_q2d( vstream->r_frame_rate)));
|
||||||
|
|
||||||
if( currTimeStamp > timeStamp )
|
if( currTimeStamp > timeStamp )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
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,
|
||||||
|
BamCacheRecord *record);
|
||||||
virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
|
virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
|
||||||
int z, int n);
|
int z, int n);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "config_gobj.h"
|
#include "config_gobj.h"
|
||||||
#include "config_grutil.h"
|
#include "config_grutil.h"
|
||||||
#include "bamReader.h"
|
#include "bamReader.h"
|
||||||
|
#include "bamCacheRecord.h"
|
||||||
|
|
||||||
TypeHandle OpenCVTexture::_type_handle;
|
TypeHandle OpenCVTexture::_type_handle;
|
||||||
|
|
||||||
@ -295,7 +296,12 @@ update_frame(int frame) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool OpenCVTexture::
|
bool OpenCVTexture::
|
||||||
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
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,
|
||||||
|
BamCacheRecord *record) {
|
||||||
|
if (record != (BamCacheRecord *)NULL) {
|
||||||
|
record->add_dependent_file(fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
nassertr(n == 0, false);
|
nassertr(n == 0, false);
|
||||||
nassertr(z >= 0 && z < get_z_size(), false);
|
nassertr(z >= 0 && z < get_z_size(), false);
|
||||||
|
|
||||||
@ -367,14 +373,14 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
|||||||
// texture) to the indicated static image.
|
// texture) to the indicated static image.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool OpenCVTexture::
|
bool OpenCVTexture::
|
||||||
do_load_one(const PNMImage &pnmimage, int z, int n) {
|
do_load_one(const PNMImage &pnmimage, const string &name, int z, int n) {
|
||||||
if (z <= (int)_pages.size()) {
|
if (z <= (int)_pages.size()) {
|
||||||
VideoPage &page = modify_page(z);
|
VideoPage &page = modify_page(z);
|
||||||
page._color.clear();
|
page._color.clear();
|
||||||
page._alpha.clear();
|
page._alpha.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Texture::do_load_one(pnmimage, z, n);
|
return Texture::do_load_one(pnmimage, name, z, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -56,7 +56,8 @@ protected:
|
|||||||
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);
|
||||||
|
|
||||||
virtual bool do_load_one(const PNMImage &pnmimage, int z, int n);
|
virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
|
||||||
|
int z, int n);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class VideoPage;
|
class VideoPage;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user