1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
#include <libcxml/cxml.h>
#include "ffmpeg_content.h"
#include "ffmpeg_decoder.h"
#include "compose.hpp"
#include "job.h"
#include "util.h"
#include "log.h"
#include "i18n.h"
using std::string;
using std::vector;
using std::list;
using boost::shared_ptr;
using boost::lexical_cast;
int const FFmpegContentProperty::SUBTITLE_STREAMS = 100;
int const FFmpegContentProperty::SUBTITLE_STREAM = 101;
int const FFmpegContentProperty::AUDIO_STREAMS = 102;
int const FFmpegContentProperty::AUDIO_STREAM = 103;
FFmpegContent::FFmpegContent (boost::filesystem::path f)
: Content (f)
, VideoContent (f)
, AudioContent (f)
{
}
FFmpegContent::FFmpegContent (shared_ptr<const cxml::Node> node)
: Content (node)
, VideoContent (node)
, AudioContent (node)
{
list<shared_ptr<cxml::Node> > c = node->node_children ("SubtitleStream");
for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
_subtitle_streams.push_back (FFmpegSubtitleStream (*i));
if ((*i)->optional_number_child<int> ("Selected")) {
_subtitle_stream = _subtitle_streams.back ();
}
}
c = node->node_children ("AudioStream");
for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
_audio_streams.push_back (FFmpegAudioStream (*i));
if ((*i)->optional_number_child<int> ("Selected")) {
_audio_stream = _audio_streams.back ();
}
}
}
void
FFmpegContent::as_xml (xmlpp::Node* node) const
{
node->add_child("Type")->add_child_text ("FFmpeg");
Content::as_xml (node);
VideoContent::as_xml (node);
boost::mutex::scoped_lock lm (_mutex);
for (vector<FFmpegSubtitleStream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
xmlpp::Node* t = node->add_child("SubtitleStream");
if (_subtitle_stream && *i == _subtitle_stream.get()) {
t->add_child("Selected")->add_child_text("1");
}
i->as_xml (t);
}
for (vector<FFmpegAudioStream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
xmlpp::Node* t = node->add_child("AudioStream");
if (_audio_stream && *i == _audio_stream.get()) {
t->add_child("Selected")->add_child_text("1");
}
i->as_xml (t);
}
}
void
FFmpegContent::examine (shared_ptr<Film> film, shared_ptr<Job> job, bool quick)
{
job->descend (0.5);
Content::examine (film, job, quick);
job->ascend ();
job->set_progress_unknown ();
shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (film, shared_from_this (), true, false, false, true));
ContentVideoFrame video_length = 0;
if (quick) {
video_length = decoder->video_length ();
film->log()->log (String::compose ("Video length obtained from header as %1 frames", decoder->video_length ()));
} else {
while (!decoder->pass ()) {
/* keep going */
}
video_length = decoder->video_frame ();
film->log()->log (String::compose ("Video length examined as %1 frames", decoder->video_frame ()));
}
{
boost::mutex::scoped_lock lm (_mutex);
_video_length = video_length;
_subtitle_streams = decoder->subtitle_streams ();
if (!_subtitle_streams.empty ()) {
_subtitle_stream = _subtitle_streams.front ();
}
_audio_streams = decoder->audio_streams ();
if (!_audio_streams.empty ()) {
_audio_stream = _audio_streams.front ();
}
}
take_from_video_decoder (decoder);
Changed (VideoContentProperty::VIDEO_LENGTH);
Changed (FFmpegContentProperty::SUBTITLE_STREAMS);
Changed (FFmpegContentProperty::SUBTITLE_STREAM);
Changed (FFmpegContentProperty::AUDIO_STREAMS);
Changed (FFmpegContentProperty::AUDIO_STREAM);
}
string
FFmpegContent::summary () const
{
return String::compose (_("Movie: %1"), file().filename ());
}
void
FFmpegContent::set_subtitle_stream (FFmpegSubtitleStream s)
{
{
boost::mutex::scoped_lock lm (_mutex);
_subtitle_stream = s;
}
Changed (FFmpegContentProperty::SUBTITLE_STREAM);
}
void
FFmpegContent::set_audio_stream (FFmpegAudioStream s)
{
{
boost::mutex::scoped_lock lm (_mutex);
_audio_stream = s;
}
Changed (FFmpegContentProperty::AUDIO_STREAM);
}
ContentAudioFrame
FFmpegContent::audio_length () const
{
if (!_audio_stream) {
return 0;
}
return video_frames_to_audio_frames (_video_length, audio_frame_rate(), video_frame_rate());
}
int
FFmpegContent::audio_channels () const
{
if (!_audio_stream) {
return 0;
}
return _audio_stream->channels ();
}
int
FFmpegContent::audio_frame_rate () const
{
if (!_audio_stream) {
return 0;
}
return _audio_stream->frame_rate;
}
int64_t
FFmpegContent::audio_channel_layout () const
{
if (!_audio_stream) {
return 0;
}
return _audio_stream->channel_layout;
}
bool
operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b)
{
return a.id == b.id;
}
bool
operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
{
return a.id == b.id;
}
FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node)
{
name = node->string_child ("Name");
id = node->number_child<int> ("Id");
frame_rate = node->number_child<int> ("FrameRate");
channel_layout = node->number_child<int64_t> ("ChannelLayout");
}
void
FFmpegAudioStream::as_xml (xmlpp::Node* root) const
{
root->add_child("Name")->add_child_text (name);
root->add_child("Id")->add_child_text (lexical_cast<string> (id));
root->add_child("FrameRate")->add_child_text (lexical_cast<string> (frame_rate));
root->add_child("ChannelLayout")->add_child_text (lexical_cast<string> (channel_layout));
}
/** Construct a SubtitleStream from a value returned from to_string().
* @param t String returned from to_string().
* @param v State file version.
*/
FFmpegSubtitleStream::FFmpegSubtitleStream (shared_ptr<const cxml::Node> node)
{
name = node->string_child ("Name");
id = node->number_child<int> ("Id");
}
void
FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
{
root->add_child("Name")->add_child_text (name);
root->add_child("Id")->add_child_text (lexical_cast<string> (id));
}
|