20 local_reader(reader), path(path), chunk_size(24*3), chunk_count(1), frame_count(1), is_writing(false),
21 default_extension(
".webm"), default_vcodec(
"libvpx"), default_acodec(
"libvorbis"), last_frame_needed(false), is_open(false)
24 info.vcodec = default_vcodec;
25 info.acodec = default_acodec;
34 write_json_meta_data();
68 throw WriterClosed(
"The ChunkWriter is closed. Call Open() before calling this method.", path);
74 frame->Save(get_chunk_path(chunk_count,
"",
".jpeg"), 1.0);
77 create_folder(get_chunk_path(chunk_count,
"final",
""));
78 writer_final =
new FFmpegWriter(get_chunk_path(chunk_count,
"final", default_extension));
79 writer_final->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
80 writer_final->SetVideoOptions(
true, default_vcodec,
info.fps,
info.width,
info.height,
info.pixel_ratio,
false,
false,
info.video_bit_rate);
83 create_folder(get_chunk_path(chunk_count,
"preview",
""));
84 writer_preview =
new FFmpegWriter(get_chunk_path(chunk_count,
"preview", default_extension));
85 writer_preview->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
86 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);
89 create_folder(get_chunk_path(chunk_count,
"thumb",
""));
90 writer_thumb =
new FFmpegWriter(get_chunk_path(chunk_count,
"thumb", default_extension));
91 writer_thumb->SetAudioOptions(
true, default_acodec,
info.sample_rate,
info.channels,
info.channel_layout, 128000);
92 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);
95 writer_final->PrepareStreams();
96 writer_preview->PrepareStreams();
97 writer_thumb->PrepareStreams();
100 writer_final->WriteHeader();
101 writer_preview->WriteHeader();
102 writer_thumb->WriteHeader();
106 last_frame_needed =
true;
111 if (last_frame_needed)
116 writer_final->WriteFrame(last_frame);
117 writer_preview->WriteFrame(last_frame);
118 writer_thumb->WriteFrame(last_frame);
121 auto blank_frame = std::make_shared<Frame>(
122 1,
info.width,
info.height,
"#000000",
124 blank_frame->AddColor(
info.width,
info.height,
"#000000");
125 writer_final->WriteFrame(blank_frame);
126 writer_preview->WriteFrame(blank_frame);
127 writer_thumb->WriteFrame(blank_frame);
131 last_frame_needed =
false;
137 writer_final->WriteFrame(frame);
138 writer_preview->WriteFrame(frame);
139 writer_thumb->WriteFrame(frame);
144 if (frame_count % chunk_size == 0 && frame_count >= chunk_size)
147 for (
int z = 0; z<12; z++)
150 writer_final->WriteFrame(frame);
151 writer_preview->WriteFrame(frame);
152 writer_thumb->WriteFrame(frame);
156 writer_final->WriteTrailer();
157 writer_preview->WriteTrailer();
158 writer_thumb->WriteTrailer();
161 writer_final->Close();
162 writer_preview->Close();
163 writer_thumb->Close();
215 for (
int z = 0; z<12; z++)
218 writer_final->WriteFrame(last_frame);
219 writer_preview->WriteFrame(last_frame);
220 writer_thumb->WriteFrame(last_frame);
224 writer_final->WriteTrailer();
225 writer_preview->WriteTrailer();
226 writer_thumb->WriteTrailer();
229 writer_final->Close();
230 writer_preview->Close();
231 writer_thumb->Close();
248 local_reader->Close();