6
6
7
7
#include < stdexcept>
8
8
#include < sstream>
9
+ #include < fstream>
9
10
10
11
namespace avtranscoder
11
12
{
@@ -29,7 +30,7 @@ FileProperties::FileProperties(const FormatContext& formatContext)
29
30
30
31
void FileProperties::extractStreamProperties (IProgress& progress, const EAnalyseLevel level)
31
32
{
32
- // if the analysis level wiil decode some streams parts, seek at the beginning
33
+ // Returns at the beginning of the stream before any deep analysis
33
34
if (level > eAnalyseLevelHeader && ! isRawFormat ())
34
35
const_cast <FormatContext*>(_formatContext)->seek (0 , AVSEEK_FLAG_BACKWARD);
35
36
@@ -43,37 +44,37 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
43
44
{
44
45
case AVMEDIA_TYPE_VIDEO:
45
46
{
46
- VideoProperties properties (*_formatContext , streamIndex, progress, level);
47
+ VideoProperties properties (*this , streamIndex, progress, level);
47
48
_videoStreams.push_back (properties);
48
49
break ;
49
50
}
50
51
case AVMEDIA_TYPE_AUDIO:
51
52
{
52
- AudioProperties properties (*_formatContext , streamIndex);
53
+ AudioProperties properties (*this , streamIndex);
53
54
_audioStreams.push_back (properties);
54
55
break ;
55
56
}
56
57
case AVMEDIA_TYPE_DATA:
57
58
{
58
- DataProperties properties (*_formatContext , streamIndex);
59
+ DataProperties properties (*this , streamIndex);
59
60
_dataStreams.push_back (properties);
60
61
break ;
61
62
}
62
63
case AVMEDIA_TYPE_SUBTITLE:
63
64
{
64
- SubtitleProperties properties (*_formatContext , streamIndex);
65
+ SubtitleProperties properties (*this , streamIndex);
65
66
_subtitleStreams.push_back (properties);
66
67
break ;
67
68
}
68
69
case AVMEDIA_TYPE_ATTACHMENT:
69
70
{
70
- AttachementProperties properties (*_formatContext , streamIndex);
71
+ AttachementProperties properties (*this , streamIndex);
71
72
_attachementStreams.push_back (properties);
72
73
break ;
73
74
}
74
75
case AVMEDIA_TYPE_UNKNOWN:
75
76
{
76
- UnknownProperties properties (*_formatContext , streamIndex);
77
+ UnknownProperties properties (*this , streamIndex);
77
78
_unknownStreams.push_back (properties);
78
79
break ;
79
80
}
@@ -121,7 +122,7 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
121
122
_streams[unknownStreamIndex] = &_unknownStreams.at (streamIndex);
122
123
}
123
124
124
- // if the analysis level has decoded some streams parts, return at the beginning
125
+ // Returns at the beginning of the stream after any deep analysis
125
126
if (level > eAnalyseLevelHeader && ! isRawFormat ())
126
127
const_cast <FormatContext*>(_formatContext)->seek (0 , AVSEEK_FLAG_BACKWARD);
127
128
}
@@ -186,6 +187,9 @@ float FileProperties::getDuration() const
186
187
{
187
188
if (!_avFormatContext)
188
189
throw std::runtime_error (" unknown format context" );
190
+ const size_t duration = _avFormatContext->duration ;
191
+ if (duration == (size_t )AV_NOPTS_VALUE)
192
+ return 0 ;
189
193
return 1.0 * _avFormatContext->duration / AV_TIME_BASE;
190
194
}
191
195
@@ -196,6 +200,12 @@ size_t FileProperties::getBitRate() const
196
200
return _avFormatContext->bit_rate ;
197
201
}
198
202
203
+ size_t FileProperties::getFileSize () const
204
+ {
205
+ std::ifstream in (getFilename ().c_str (), std::ios::binary | std::ios::ate);
206
+ return in.tellg ();
207
+ }
208
+
199
209
size_t FileProperties::getPacketSize () const
200
210
{
201
211
if (!_avFormatContext)
@@ -243,10 +253,13 @@ PropertyVector& FileProperties::fillVector(PropertyVector& data) const
243
253
addProperty (data, " formatName" , &FileProperties::getFormatName);
244
254
addProperty (data, " formatLongName" , &FileProperties::getFormatLongName);
245
255
addProperty (data, " mimeType" , &FileProperties::getFormatMimeType);
256
+ addProperty (data, " rawFormat" , &FileProperties::isRawFormat);
246
257
247
258
addProperty (data, " startTime" , &FileProperties::getStartTime);
248
259
addProperty (data, " duration" , &FileProperties::getDuration);
249
260
addProperty (data, " bitrate" , &FileProperties::getBitRate);
261
+ addProperty (data, " fileSize" , &FileProperties::getFileSize);
262
+ addProperty (data, " packetSize" , &FileProperties::getPacketSize);
250
263
addProperty (data, " numberOfStreams" , &FileProperties::getNbStreams);
251
264
addProperty (data, " numberOfPrograms" , &FileProperties::getProgramsCount);
252
265
0 commit comments