Hi,
please find attached a patch I started a while ago when Alexander Winizki
wrote his "New Features Request" and which I forgot until now ...
It adds some picture infos about current resolution, fps and aspect ratio
below every displayed picture (inbetween the 2 go-buttons/timestamps).
All this infos actually are already read from MPEG headers and stored into our
index structure expect the resolution which we forgot ... I found two
solutions for this:
1. Simply get it from an Qimage via imageprovider() which I expected to be
somewhat slow when scrolling through the video (but actually I couldn't
notice a big difference).
2. Store read resolutions at end of index file and use the 3 (up to now)
unused leading bits of the index structure to point at this dynamic lookup
table.
A static table isn't feasible since there are more than 7 possible resolutions
out there in DVB-land and that way we even can have up to 7 different
resolutions per video which should be enough (a zero automatically means no
resolutions stored = old index file format).
Actually I'm not sure if the resolution can ever change during a recording
resp. transmission... if not, one should better stick to option 1 and
determine it only once from the very first picture read!
Also if someone minds changing the format of the index file...
At the moment with this patch Option 1 is only used when an old index file has
been read. All newly created index files get automatically the lookup table
(=7 faked pictures) attached to the end which increases them by 7x16bytes.
If one ever tries to read a new indexfile with and old dvbcut an error about
invalid indexfile is raised... at least when I tried that with my example
video. ;-)
ciao
Ralph
diff -Naur svn/ChangeLog r131-picinfo/ChangeLog
--- svn/ChangeLog 2008-06-14 19:09:30.000000000 +0200
+++ r131-picinfo/ChangeLog 2008-10-05 17:42:52.000000000 +0200
@@ -1,3 +1,12 @@
+2008-10-05 Michael Riepe <[EMAIL PROTECTED]>
+
+ * dvbcutbase.ui
+ * dvbcut.cpp
+ * index.cpp
+ * index.h
+ * mpgfile.h
+ Show picture related infos (slightly changed index format!)
+
2008-06-14 Michael Riepe <[EMAIL PROTECTED]>
* configure.in:
diff -Naur svn/src/dvbcutbase.ui r131-picinfo/src/dvbcutbase.ui
--- svn/src/dvbcutbase.ui 2008-01-16 22:34:05.000000000 +0100
+++ r131-picinfo/src/dvbcutbase.ui 2008-08-24 23:27:31.000000000 +0200
@@ -166,6 +166,49 @@
</size>
</property>
</spacer>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>picinfolabel</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>10</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="font">
+ <font>
+ <family>Monospace</family>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ <property name="alignment">
+ <set>AlignVCenter|AlignRight</set>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>2</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
<widget class="QLineEdit">
<property name="name">
<cstring>goinput2</cstring>
@@ -251,6 +294,49 @@
</spacer>
<widget class="QLabel">
<property name="name">
+ <cstring>picinfolabel2</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>10</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="font">
+ <font>
+ <family>Monospace</family>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ <property name="alignment">
+ <set>AlignVCenter|AlignRight</set>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>2</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QLabel">
+ <property name="name">
<cstring>pictimelabel2</cstring>
</property>
<property name="enabled">
diff -Naur svn/src/dvbcut.cpp r131-picinfo/src/dvbcut.cpp
--- svn/src/dvbcut.cpp 2008-03-22 11:53:24.000000000 +0100
+++ r131-picinfo/src/dvbcut.cpp 2008-10-05 14:23:07.000000000 +0200
@@ -1663,6 +1663,8 @@
imagedisplay->setPixmap(QPixmap());
pictimelabel->clear();
pictimelabel2->clear();
+ picinfolabel->clear();
+ picinfolabel2->clear();
linslider->setValue(0);
jogslider->setValue(0);
@@ -1705,6 +1707,8 @@
imagedisplay->setEnabled(false);
pictimelabel->setEnabled(false);
pictimelabel2->setEnabled(false);
+ picinfolabel->setEnabled(false);
+ picinfolabel2->setEnabled(false);
goinput->setEnabled(false);
gobutton->setEnabled(false);
goinput2->setEnabled(false);
@@ -2051,6 +2055,8 @@
imagedisplay->setEnabled(true);
pictimelabel->setEnabled(true);
pictimelabel2->setEnabled(true);
+ picinfolabel->setEnabled(true);
+ picinfolabel2->setEnabled(true);
goinput->setEnabled(true);
gobutton->setEnabled(true);
goinput2->setEnabled(true);
@@ -2203,7 +2209,9 @@
{
const index::picture &idx=(*mpg)[curpic];
const pts_t pts=idx.getpts()-firstpts;
-
+ const char *AR[]={"forbidden","1:1","4:3","16:9","2.21:1","reserved"};
+ const char *FR[]={"forbidden","23.976","24","25","29.97","30","50","59.94","60","reserved"};
+
int outpic=0;
pts_t outpts=0;
QChar mark = ' ';
@@ -2240,6 +2248,21 @@
pictimelabel2->setText(outtime);
goinput->setText(QString::number(curpic));
goinput2->setText(QString::number(outpic));
+
+ int res=idx.getresolution(); // are found video resolutions stored in index?
+ if (res) {
+ // new index with resolution bits set and lookup table at the end
+ picinfolabel->setText(QString::number(mpg->getwidth(res)) + "x"
+ + QString::number(mpg->getheight(res)));
+ } else {
+ // in case of an old index file type (or if we don't want to change the index format/encoding?)
+ // ==> get info directly from each image (which could be somewhat slower?!?)
+ QImage p = imageprovider(*mpg, new dvbcutbusy(this), true).getimage(curpic,false);
+ picinfolabel->setText(QString::number(p.width()) + "x"
+ + QString::number(p.height()));
+ }
+ picinfolabel2->setText(QString(FR[idx.getframerate()]) + "fps, "
+ + QString(AR[idx.getaspectratio()]));
}
diff -Naur svn/src/index.cpp r131-picinfo/src/index.cpp
--- svn/src/index.cpp 2007-10-14 01:19:43.000000000 +0200
+++ r131-picinfo/src/index.cpp 2008-10-05 17:33:03.000000000 +0200
@@ -27,6 +27,9 @@
#include <cstring>
#include <list>
#include <utility>
+#include <set>
+#include <vector>
+#include <string>
#include "port.h"
#include "index.h"
@@ -58,8 +61,12 @@
index::~index()
{
- if (p)
- free(p);
+ if (p) {
+ free(p);
+ // delete read resolutions
+ WIDTH.clear();
+ HEIGHT.clear();
+ }
}
int index::generate(const char *savefilename, std::string *errorstring, logoutput *log)
@@ -68,7 +75,7 @@
bool usestdout=false;
int pictureswritten=0;
dvbcut_off_t filesize=0;
-
+
if (savefilename && savefilename[0]) {
if (savefilename[0]=='-' && savefilename[1]==0) // use stdout
{
@@ -106,11 +113,16 @@
bool foundseqheader=false;
bool waitforfirstsequenceheader=true;
int aspectratio=0,framerate=0;
- filepos_t seqheaderpos=0;
+ double maxbitrate=0., bitrate;
+ long int bits=0;
+ pts_t maxbitratepts=0, dt;
+ std::pair<int,int> res;
+ int nres = 0;
+ filepos_t seqheaderpos=0, lastseqheaderpos=0;
int seqheaderpic=0;
pts_t referencepts=0; // pts of picture #0 in current sequence
int maxseqnr=-1; // maximum sequence number in current sequence
- pts_t lastpts=1ll<<31;
+ pts_t lastpts=1ll<<31, lastseqheaderpts=0, firstseqheaderpts=0;
int last_non_b_pic = -1;
int last_non_b_seqnr = -1;
int last_seqnr = -1;
@@ -175,6 +187,21 @@
sd->discard(skip);
data=(const uint8_t*) sd->getdata();
+ // store found resolutions in lookup table
+ res.first=(data[4]<<4)|((data[5]>>4)&0xf); // width
+ res.second=((data[5]&0xf)<<8)|data[6]; // height
+ if (resolutions.find(res)==resolutions.end() && nres<7) {
+ nres++;
+ resolutions.insert(res); // a set helps checking already read resolutions
+ WIDTH.push_back(res.first);
+ HEIGHT.push_back(res.second);
+ //fprintf(stderr, "RESOLUTION[%d]: %d x %d\n", nres, res.first, res.second);
+ }
+
+ // that's always the same preset value and thus not very usefull (in 400 bps)!!!
+ //bitrate = ((data[8]<<10)|(data[9]<<2)|((data[10]>>6)&0x3))*400;
+ //if (bitrate>maxbitrate) maxbitrate=bitrate;
+
aspectratio=(data[7]>>4)&0xf;
framerate=data[7]&0xf;
referencepts+=((maxseqnr+1)*mpgfile::frameratescr[framerate])/300;
@@ -245,7 +272,27 @@
p=(picture*)realloc((void*)p,size*sizeof(picture));
}
- p[pictures]=picture(foundseqheader?seqheaderpos:picpos,pts,framerate,aspectratio,seqnr,frametype,foundseqheader);
+ p[pictures]=picture(foundseqheader?seqheaderpos:picpos,pts,framerate,aspectratio,seqnr,frametype,foundseqheader,nres);
+
+ // try to determine bitrate per GOP manually since the read one is not very usefull
+ if (foundseqheader) {
+ if (firstseqheaderpts && lastseqheaderpos<seqheaderpos && lastseqheaderpts<pts) {
+ dt = (pts-lastseqheaderpts)/90;
+ bits = (seqheaderpos-lastseqheaderpos)*8;
+ // avergage (input) bitrate per GOP
+ bitrate=1000*double(bits)/double(dt);
+ if (maxbitrate<bitrate) {
+ maxbitrate=bitrate;
+ maxbitratepts=lastseqheaderpts;
+ }
+ //fprintf(stderr, "%s: BITRATE = %d kbps over next %d ms\n",
+ // ptsstring(lastseqheaderpts-firstseqheaderpts).c_str(), int(bitrate/1024.), int(dt));
+ } else {
+ firstseqheaderpts=pts;
+ }
+ lastseqheaderpos=seqheaderpos;
+ lastseqheaderpts=pts;
+ }
if (frametype == IDX_PICTYPE_I) {
if (lastiframe >= 0) {
@@ -313,6 +360,16 @@
sd->discard(skip);
}
+ // create 7 fake pictures containing read resolutions (pos: width, pts: height)
+ for (int i=0; i<nres; i++) {
+ p[pictures]=picture(filepos_t(WIDTH[i]),pts_t(HEIGHT[i]),0,0,0,0,false,i+1);
+ ++pictures;
+ }
+ for (int i=nres; i<7; i++) {
+ p[pictures]=picture(filepos_t(0),pts_t(0),0,0,0,0,false,i+1);
+ ++pictures;
+ }
+
if (err1cnt > 0)
fprintf(stderr, "last video PTS error repeated %d times\n", err1cnt);
if (errcnt > 0)
@@ -345,6 +402,9 @@
if (!usestdout && fd>=0)
::close(fd);
+ pictures-=7; // subtract fake pictures
+ fprintf(stderr, "Max. input bitrate of %d kbps detected at %s!\n", int(maxbitrate/1024), ptsstring(maxbitratepts-firstseqheaderpts).c_str());
+
return check();
}
@@ -454,6 +514,23 @@
}
p=(picture*)realloc((void*)data,pictures*sizeof(picture));
+ // 7 fake pictures at end contain resolution lookup table
+ // (if new type of index file, after svn-revision 131)
+ if (p[0].getresolution()>0) {
+ pictures-=7;
+ int w, h, nres=0;
+ for (int i=pictures; nres<7; i++) {
+ w=int(p[i].getpos());
+ h=int(p[i].getpts());
+ if (w==0 || h==0)
+ break;
+ nres++;
+ WIDTH.push_back(w);
+ HEIGHT.push_back(h);
+ //fprintf(stderr, "RESOLUTION[%d]: %d x %d\n", nres, w, h);
+ }
+ }
+
int seqnr[1<<10]={0};
int seqpics=0;
for(int i=0;;++i) {
@@ -502,7 +579,7 @@
return -3;
}
}
-
+
return check();
}
diff -Naur svn/src/index.h r131-picinfo/src/index.h
--- svn/src/index.h 2007-10-22 12:05:55.000000000 +0200
+++ r131-picinfo/src/index.h 2008-08-24 23:41:25.000000000 +0200
@@ -23,6 +23,8 @@
#include <stdint.h>
#include <byteswap.h>
+#include <set>
+#include <vector>
#include "types.h"
#include "pts.h"
#include "defines.h"
@@ -45,7 +47,8 @@
{
filepos_t position;
uint64_t pts; // additional information in the 24 most significant bits:
- // ...QTTSSSSSSSSSSAAAAFFFF
+ // RRRQTTSSSSSSSSSSAAAAFFFF
+ // R: resolution number (according to lookup table with WIDTHxHEIGHT at end of index)
// Q: sequence header flag
// T: picture type
// S: picture sequence number
@@ -53,10 +56,11 @@
// F: frame rate (mpeg code)
picture(filepos_t pos, pts_t _pts, int framerate, int aspectratio,
- int sequencenumber, int picturetype, bool seqheader=false) :
+ int sequencenumber, int picturetype, bool seqheader=false, int resolution=0) :
position( pos ),
pts((_pts&0xffffffffffll) | ((uint64_t)( (framerate&0xf)|((aspectratio&0xf)<<4)|
- ((sequencenumber&0x3ff)<<8)|((picturetype&0x3)<<18)|(seqheader?0x100000:0) )<<40))
+ ((sequencenumber&0x3ff)<<8)|((picturetype&0x3)<<18)|
+ (seqheader?0x100000:0)|((resolution&0x7)<<21) )<<40))
{ }
picture() : position(0), pts(0)
{}
@@ -94,6 +98,10 @@
{
return pts&0x1000000000000000ll;
}
+ int getresolution() const
+ {
+ return int(pts>>61)&0x7;
+ }
bool isbframe() const
{
return getpicturetype()==IDX_PICTYPE_B;
@@ -123,6 +131,11 @@
int realpictures;
int check();
+
+ // lookup-tables with found resolutions (stored at end of index file and coded in 3
+ // most significant bits of picture structure, 0 for old type index files)
+ std::vector<int> WIDTH, HEIGHT;
+ std::set<std::pair<int,int> > resolutions;
public:
index(mpgfile &m) : mpg(m),p(0),pictures(0)
@@ -134,6 +147,15 @@
int save(int fd, std::string *errorstring = 0, bool closeme = false);
int save(const char *filename, std::string *errorstring=0);
int load(const char *filename, std::string *errorstring=0);
+
+ int getwidth(int res) const
+ {
+ return res>0 && res<=int(WIDTH.size()) ? WIDTH[res-1] : -1;
+ }
+ int getheight(int res) const
+ {
+ return res>0 && res<=int(HEIGHT.size()) ? HEIGHT[res-1] : -1;
+ }
int indexnr(int pic) const
{
diff -Naur svn/src/mpgfile.h r131-picinfo/src/mpgfile.h
--- svn/src/mpgfile.h 2007-11-28 16:12:51.000000000 +0100
+++ r131-picinfo/src/mpgfile.h 2008-08-24 22:39:35.000000000 +0200
@@ -203,6 +203,14 @@
{
return idx.save(filename,errorstring);
}
+ int getwidth(int res)
+ {
+ return idx.getwidth(res);
+ }
+ int getheight(int res)
+ {
+ return idx.getheight(res);
+ }
void decodegop(int start, int stop, std::list<avframe*> &framelist);
void initaudiocodeccontext(int aud);
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
DVBCUT-devel mailing list
DVBCUT-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dvbcut-devel