22 local_reader(reader), path(path), chunk_size(24*3), chunk_count(1), frame_count(1), is_writing(false),
23 default_extension(
".webm"), default_vcodec(
"libvpx"), default_acodec(
"libvorbis"), last_frame_needed(false), is_open(false)
26 info.vcodec = default_vcodec;
27 info.acodec = default_acodec;
36 write_json_meta_data();
70 throw WriterClosed(
"The ChunkWriter is closed. Call Open() before calling this method.", path);
76 frame->Save(get_chunk_path(chunk_count,
"",
".jpeg"), 1.0);
79 create_folder(get_chunk_path(chunk_count,
"final",
""));
80 writer_final =
new FFmpegWriter(get_chunk_path(chunk_count,
"final", default_extension));
81 writer_final->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
82 writer_final->SetVideoOptions(
true, default_vcodec,
info.fps,
info.width,
info.height,
info.pixel_ratio,
false,
false,
info.video_bit_rate);
85 create_folder(get_chunk_path(chunk_count,
"preview",
""));
86 writer_preview =
new FFmpegWriter(get_chunk_path(chunk_count,
"preview", default_extension));
87 writer_preview->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
88 writer_preview->SetVideoOptions(
true, default_vcodec,
info.fps,
info.width * 0.5,
info.height * 0.5,
info.pixel_ratio,
false,
false,
info.video_bit_rate * 0.5);
91 create_folder(get_chunk_path(chunk_count,
"thumb",
""));
92 writer_thumb =
new FFmpegWriter(get_chunk_path(chunk_count,
"thumb", default_extension));
93 writer_thumb->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
94 writer_thumb->SetVideoOptions(
true, default_vcodec,
info.fps,
info.width * 0.25,
info.height * 0.25,
info.pixel_ratio,
false,
false,
info.video_bit_rate * 0.25);
97 writer_final->PrepareStreams();
98 writer_preview->PrepareStreams();
99 writer_thumb->PrepareStreams();
102 writer_final->WriteHeader();
103 writer_preview->WriteHeader();
104 writer_thumb->WriteHeader();
108 last_frame_needed =
true;
113 if (last_frame_needed)
118 writer_final->WriteFrame(last_frame);
119 writer_preview->WriteFrame(last_frame);
120 writer_thumb->WriteFrame(last_frame);
123 auto blank_frame = std::make_shared<Frame>(
124 1,
info.width,
info.height,
"#000000",
126 blank_frame->AddColor(
info.width,
info.height,
"#000000");
127 writer_final->WriteFrame(blank_frame);
128 writer_preview->WriteFrame(blank_frame);
129 writer_thumb->WriteFrame(blank_frame);
133 last_frame_needed =
false;
139 writer_final->WriteFrame(frame);
140 writer_preview->WriteFrame(frame);
141 writer_thumb->WriteFrame(frame);
146 if (frame_count % chunk_size == 0 && frame_count >= chunk_size)
149 for (
int z = 0; z<12; z++)
152 writer_final->WriteFrame(frame);
153 writer_preview->WriteFrame(frame);
154 writer_thumb->WriteFrame(frame);
158 writer_final->WriteTrailer();
159 writer_preview->WriteTrailer();
160 writer_thumb->WriteTrailer();
163 writer_final->Close();
164 writer_preview->Close();
165 writer_thumb->Close();
217 for (
int z = 0; z<12; z++)
220 writer_final->WriteFrame(last_frame);
221 writer_preview->WriteFrame(last_frame);
222 writer_thumb->WriteFrame(last_frame);
226 writer_final->WriteTrailer();
227 writer_preview->WriteTrailer();
228 writer_thumb->WriteTrailer();
231 writer_final->Close();
232 writer_preview->Close();
233 writer_thumb->Close();
250 local_reader->Close();