Skip to content

Commit 4166201

Browse files
committed
MP4ライターをMediaProcessorインターフェースを使用するように変更し、ループベースの処理に移行
1 parent 34e4267 commit 4166201

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/composer.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use crate::{
99
decoder::VideoDecoderOptions,
1010
encoder::{AudioEncoder, AudioEncoderThread, VideoEncoder, VideoEncoderThread},
1111
layout::Layout,
12-
media::{MediaStreamId, MediaStreamIdGenerator},
12+
media::{MediaSample, MediaStreamId, MediaStreamIdGenerator},
1313
mixer_audio::AudioMixerThread,
1414
mixer_video::VideoMixerThread,
15+
processor::{MediaProcessor, MediaProcessorInput, MediaProcessorOutput},
1516
source::{AudioSourceThread, VideoSourceThread},
1617
stats::{ProcessorStats, Seconds, SharedStats},
1718
types::CodecName,
@@ -70,12 +71,12 @@ impl Composer {
7071
);
7172

7273
// 映像ミキサーとエンコーダーを準備
73-
let encoded_video_rx = self
74+
let mut encoded_video_rx = self
7475
.create_video_mixer_and_encoder(error_flag.clone(), stats.clone(), video_source_rxs)
7576
.or_fail()?;
7677

7778
// 音声ミキサーとエンコーダーを準備
78-
let encoded_audio_rx = self
79+
let mut encoded_audio_rx = self
7980
.create_audio_mixer_and_encoder(error_flag.clone(), stats.clone(), audio_source_rxs)
8081
.or_fail()?;
8182

@@ -95,7 +96,29 @@ impl Composer {
9596
)
9697
.or_fail()?;
9798

98-
while let Some(timestamp) = mp4_writer.poll().or_fail()? {
99+
loop {
100+
match mp4_writer.process_output().or_fail()? {
101+
MediaProcessorOutput::Finished => break,
102+
MediaProcessorOutput::Pending { awaiting_stream_id }
103+
if awaiting_stream_id == writer_input_audio_stream_id =>
104+
{
105+
let input = MediaProcessorInput {
106+
stream_id: awaiting_stream_id,
107+
sample: encoded_audio_rx.recv().map(MediaSample::audio_data),
108+
};
109+
mp4_writer.process_input(input).or_fail()?;
110+
}
111+
MediaProcessorOutput::Pending { awaiting_stream_id } => {
112+
let input = MediaProcessorInput {
113+
stream_id: awaiting_stream_id,
114+
sample: encoded_video_rx.recv().map(MediaSample::video_frame),
115+
};
116+
mp4_writer.process_input(input).or_fail()?;
117+
}
118+
MediaProcessorOutput::Processed { .. } => unreachable!(),
119+
}
120+
121+
let timestamp = mp4_writer.current_duration();
99122
progress_bar.set_position(timestamp.as_secs());
100123
if error_flag.get() {
101124
// ファイル読み込み、デコード、合成、エンコード、のいずれかで失敗したものがあるとここに来る

0 commit comments

Comments
 (0)