summaryrefslogtreecommitdiff
path: root/src/lib/ffmpeg_content.cc
blob: 6109b72126af904a4a8909e52bb4061ac221c545 (plain)
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
#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 boost::shared_ptr;

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)
{

}

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;
}