arduino-audio-tools
Loading...
Searching...
No Matches
ContainerAVI.h
Go to the documentation of this file.
1#pragma once
2#include <string.h>
10
11#define LIST_HEADER_SIZE 12
12#define CHUNK_HEADER_SIZE 8
13
14namespace audio_tools {
15
24public:
25 size_t writeArray(uint8_t *data, size_t len) {
26 int to_write = min(availableToWrite(), (size_t)len);
27 memmove(vector.data() + available_byte_count, data, to_write);
28 available_byte_count += to_write;
29 return to_write;
30 }
31 void consume(int size) {
32 // use pointer arithmetic (not the bounds-checked operator[]): when size
33 // == available_byte_count (buffer fully drained, common for chunks at
34 // least as big as the buffer capacity, e.g. large raw video frames),
35 // vector.data() + size legally points one-past-the-end and the memmove
36 // length is 0, which operator[] would reject even though it's a no-op
39 }
40 bool resize(size_t size) {
41 vector.resize(size + 4);
42 return vector.data() != nullptr;
43 }
44
45 uint8_t *data() { return vector.data(); }
46
48
49 size_t available() { return available_byte_count; }
50
51 void clear() {
53 memset(vector.data(), 0, vector.size());
54 }
55
56 bool isEmpty() { return available_byte_count == 0; }
57
58 size_t size() { return vector.size(); }
59
60 long indexOf(const char *str) {
61 uint8_t *ptr = (uint8_t *)memmem(vector.data(), available_byte_count, str,
62 strlen(str));
63 return ptr == nullptr ? -1l : ptr - vector.data();
64 }
65
66protected:
69};
70
73using FOURCC = char[4];
74
90
95
112
113// field widths mirror the on-disk 40-byte BITMAPINFOHEADER exactly (all
114// DWORD/uint32_t, except the two WORD/uint16_t fields) - do not widen these,
115// the decoder reinterpret_casts raw file bytes directly onto this struct
129
139
140// struct WAVFormat {
141// uint16_t wFormatTag;
142// uint16_t nChannels;
143// uint32_t nSamplesPerSec;
144// uint32_t nAvgBytesPerSec;
145// uint16_t nBlockAlign;
146// };
147
149
163
171public:
172 void set(size_t currentPos, StrView id, size_t size, ParseObjectType type) {
173 set(currentPos, id.c_str(), size, type);
174 }
175
176 void set(size_t currentPos, const char *id, size_t size,
179 data_size = size;
181 start_pos = currentPos;
182 // allign on word
183 if (size % 2 != 0) {
184 data_size++;
185 }
186 end_pos = currentPos + data_size + 4;
187 // save FOURCC
188 if (id != nullptr) {
189 memcpy(chunk_id, id, 4);
190 chunk_id[4] = 0;
191 }
192 open = data_size;
193 }
194 const char *id() { return chunk_id; }
195 size_t size() { return data_size; }
199 size_t declaredSize() { return declared_size; }
200
202 bool isValid() {
203 switch (object_type) {
204 case AVIStreamData:
205 return isAudio() || isVideo();
206 case AVIChunk:
207 return open > 0;
208 case AVIList:
209 return true;
210 }
211 return false;
212 }
213
214 // for Chunk
215 AVIMainHeader *asAVIMainHeader(void *ptr) { return (AVIMainHeader *)ptr; }
217 return (AVIStreamHeader *)ptr;
218 }
219 WAVFormatX *asAVIAudioFormat(void *ptr) { return (WAVFormatX *)ptr; }
221 return (BitmapInfoHeader *)ptr;
222 }
223
224 // Zero-initialized so a default-constructed/not-yet-set() ParseObject is
225 // deterministically "empty" (open==0 => isValid()==false for the default
226 // AVIChunk object_type below) instead of reading whatever was previously
227 // on the stack at this memory - the same uninitialized-read hazard that
228 // caused a real, platform-dependent infinite loop in cleanupStack() (see
229 // its own comment) when it read an unset ParseObject's end_pos.
230 size_t open = 0;
231 size_t end_pos = 0;
232 size_t start_pos = 0;
233 size_t data_size = 0;
234 size_t declared_size = 0;
235
236 // for AVIStreamData
238 return object_type == AVIStreamData ? (chunk_id[1] << 8) | chunk_id[0] : 0;
239 }
240 bool isAudio() {
241 return object_type == AVIStreamData
242 ? chunk_id[2] == 'w' && chunk_id[3] == 'b'
243 : false;
244 }
246 return object_type == AVIStreamData
247 ? chunk_id[2] == 'd' && chunk_id[3] == 'b'
248 : false;
249 }
251 return object_type == AVIStreamData
252 ? chunk_id[2] == 'd' && chunk_id[3] == 'c'
253 : false;
254 }
256
257protected:
258 // ParseBuffer data_buffer;
259 char chunk_id[5] = {};
260 // Default is AVIChunk (not e.g. AVIList, whose isValid() is
261 // unconditionally true) so that a default-constructed/not-yet-set()
262 // ParseObject deterministically reports isValid()==false via the
263 // open==0 default above, instead of depending on whatever this member
264 // would otherwise be left as (see the class comment on the members
265 // above - this mirrors that fix).
267};
268
281class DemuxerAVI : public Demuxer {
282public:
291 DemuxerAVI(int bufferSize = 1024) {
292 parse_buffer.resize(bufferSize);
293 }
294
296 const char *mimeVideo() { return "video/avi"; }
297
299 const char *mime() override { return toMime(audio_info.wFormatTag); }
300
303 bool isValid(const uint8_t *data, size_t len) override {
304 return len >= 12 && memcmp(data, "RIFF", 4) == 0 &&
305 memcmp(data + 8, "AVI ", 4) == 0;
306 }
307
316 void setSendWavHeader(bool flag) override {
317 send_wav_header = flag;
319 }
320
321 bool begin() override {
323 header_is_avi = false;
324 is_parsing_active = true;
325 current_pos = 0;
327 is_metadata_ready = false;
328 is_wav_header_sent = false;
329 riff_file_size = 0;
330 // forget everything from a previous file: unparsed bytes, a partially
331 // accumulated video chunk and the open LIST/chunk state would otherwise
332 // desync the parser when a new file (or the same one again) is started
335 object_stack.clear();
339 movi_end_pos = 0;
340 return true;
341 }
342
346 void setOutputAudio(Print &out_stream) override {
347 p_output_audio = &out_stream;
348 }
349
354 virtual void setOutput(Print &out_stream) override {
355 setOutputAudio(out_stream);
356 }
357
359 void setMute(bool mute) { is_mute = mute; }
360
361 void setOutputVideo(Print &out_stream) override {
362 p_output_video = &out_stream;
363 }
364 void setOutputVideo(VideoOutput &out_stream) override {
365 p_output_video_video = &out_stream;
366 }
367
368 virtual size_t write(const uint8_t *data, size_t len) override {
369 LOGD("write: %d", (int)len);
370 int result = parse_buffer.writeArray((uint8_t *)data, len);
371 // Reading any chunk/stream-data header needs up to LIST_HEADER_SIZE (12)
372 // bytes (parseList()/tryParseList() read offsets 0-11; parseAVIStreamData
373 // /parseChunk only need 8) - none of those getInt()/getStr() calls guard
374 // against running past what's actually buffered. Calling parse() with
375 // fewer bytes available reads stale leftover bytes past
376 // available_byte_count (consume() shifts via memmove but never zeroes
377 // the vacated tail), producing a garbage FOURCC/size - exactly the
378 // "unknown subchunk"/huge-bogus-size corruption this avoids by simply
379 // waiting for more data to accumulate instead of parsing prematurely.
381 // we expect the first parse to succeed
382 if (parse()) {
383 // if so we process the parse_buffer
385 if (!parse())
386 break;
387 }
388 } else {
389 LOGD("Parse Error");
391 result = len;
392 is_parsing_active = false;
393 }
394 }
395 return result;
396 }
397
398 operator bool() override { return is_parsing_active; }
399
400 void end() override { is_parsing_active = false; };
401
404
407
410
411 const char *aviVideoFormat() { return video_format; }
412
415
423 VideoInfo result;
424 result.width = (uint16_t)video_info.biWidth;
425 result.height = (uint16_t)video_info.biHeight;
426 result.format =
428 result.frame_size =
429 (uint32_t)videoFrameSizeBytes(result.format, result.width, result.height);
432 ? 1000000.0f / main_header.dwMicroSecPerFrame
433 : 0;
434 return result;
435 }
436
437
448 AudioInfoFormat result(info);
450 return result;
451 }
452
457 void setValidationCallback(bool (*cb)(DemuxerAVI &avi)) {
458 validation_cb = cb;
459 }
460
462 int videoSeconds() { return video_seconds; }
463
464protected:
465 bool header_is_avi = false;
466 bool is_parsing_active = true;
490 long current_pos = 0;
491 long movi_end_pos = 0;
494 char video_format[5] = {0};
495 bool is_metadata_ready = false;
496 bool (*validation_cb)(DemuxerAVI &avi) = nullptr;
497 bool is_mute = false;
498 bool send_wav_header = false;
500 bool is_wav_header_sent = false;
506
508 return strncmp(stream_header[stream_header_idx].fccType, "auds", 4) == 0;
509 }
510
512 return strncmp(stream_header[stream_header_idx].fccType, "vids", 4) == 0;
513 }
514
515 // we return true if at least one parse step was successful
516 bool parse() {
517 bool result = true;
518 switch (parse_state) {
519 case ParseHeader: {
520 result = parseHeader();
521 if (result)
523 } break;
524
525 case ParseHdrl: {
526 ParseObject hdrl = parseList("hdrl");
527 result = hdrl.isValid();
528 if (result) {
530 }
531 } break;
532
533 case ParseAvih: {
534 ParseObject avih = parseChunk("avih");
535 result = avih.isValid();
536 if (result) {
539 consume(avih.size());
541 }
542 } break;
543
544 case ParseStrl: {
545 ParseObject strl = parseList("strl");
546 ParseObject strh = parseChunk("strh");
549 consume(strh.size());
551 } break;
552
553 case ParseStrf: {
554 ParseObject strf = parseChunk("strf");
555 if (isCurrentStreamAudio()) {
558 LOGI("audioFormat: %d (%x) - %s", (int)audio_info.wFormatTag,
561 consume(strf.size());
562 } else if (isCurrentStreamVideo()) {
565 LOGI("videoFormat: %s", aviVideoFormat());
567 video_format[4] = 0;
568 consume(strf.size());
569 } else {
570 result = false;
571 }
573 } break;
574
575 case AfterStrf: {
576 // ignore all data until we find a new List
577 int pos = parse_buffer.indexOf("LIST");
578 if (pos >= 0) {
579 consume(pos);
581 if (StrView(tmp.id()).equals("strl")) {
583 } else if (StrView(tmp.id()).equals("movi")) {
585 } else {
586 // e.g. ignore info
588 }
589 } else {
590 // no valid data, so throw it away, we keep the last 4 digits in case
591 // if it contains the beginning of a LIST
592 cleanupStack();
594 }
595 } break;
596
597 case ParseMovi: {
598 ParseObject movi = tryParseList();
599 if (StrView(movi.id()).equals("movi")) {
601 is_metadata_ready = true;
602 if (validation_cb)
604 processStack(movi);
605 movi_end_pos = movi.end_pos;
607 // trigger new write
608 result = false;
609 }
610 } break;
611
612 case SubChunk: {
613 // rec is optinal
614 ParseObject hdrl = tryParseList();
615 if (StrView(hdrl.id()).equals("rec")) {
617 processStack(hdrl);
618 }
619
624 LOGD("video:[%d]->[%d]", (int)current_stream_data.start_pos,
626 } else if (current_stream_data.isAudio()) {
627 LOGD("audio:[%d]->[%d]", (int)current_stream_data.start_pos,
629 } else {
630 // Not fatal - writeData() (SubChunkContinue) skips its payload below.
631 LOGW("unknown subchunk '%s' at %d, skipping %d bytes",
634 }
635
636 } break;
637
638 case SubChunkContinue: {
639 writeData();
640 if (open_subchunk_len == 0) {
642 (p_output_video != nullptr || p_output_video_video != nullptr)) {
643 if (p_output_video != nullptr) p_output_video->flush();
645 }
646 if (tryParseChunk("idx").isValid()) {
648 } else if (tryParseList("rec").isValid()) {
650 } else {
651 if (current_pos >= movi_end_pos) {
653 } else {
655 }
656 }
657 }
658 } break;
659
660 case ParseIgnore: {
661 LOGD("ParseIgnore");
663 } break;
664
665 default:
666 result = false;
667 break;
668 }
669 return result;
670 }
671
682
690 if (is_wav_header_sent || p_output_audio == nullptr) return;
691 WAVAudioInfo winfo(info);
693 winfo.is_streamed = true;
696 winfo.ext_adpcm_header = true;
697 WAVHeader wav_header;
698 wav_header.setAudioInfo(winfo);
699 wav_header.writeHeader(p_output_audio);
700 is_wav_header_sent = true;
701 }
702
704 memcpy(video_format, stream_header[stream_header_idx].fccHandler, 4);
706 if (vh->dwScale <= 0) {
707 vh->dwScale = 1;
708 }
709 int rate = vh->dwRate / vh->dwScale;
710 video_seconds = rate <= 0 ? 0 : vh->dwLength / rate;
711 LOGI("videoSeconds: %d seconds", video_seconds);
712 }
713
718 static VideoFormat toVideoFormat(uint32_t biCompression,
719 uint16_t biBitCount) {
720 if (biCompression == 0) return VideoFormat::RAW; // BI_RGB
721 if (biCompression == 3) // BI_BITFIELDS
722 return biBitCount == 16 ? VideoFormat::RGB565 : VideoFormat::RAW;
723
724 auto is = [biCompression](const char *fourcc) {
725 return memcmp(&biCompression, fourcc, 4) == 0;
726 };
727 if (is("H264") || is("h264") || is("X264") || is("x264") ||
728 is("avc1") || is("AVC1"))
729 return VideoFormat::H264;
730 if (is("MJPG") || is("mjpg"))
731 return VideoFormat::MJPEG;
732 if (is("FMP4") || is("XVID") || is("DIVX") || is("DX50") ||
733 is("mp4v"))
734 return VideoFormat::MPEG4;
735 if (is("YUY2") || is("YUYV") || is("yuy2") || is("yuyv"))
736 return VideoFormat::YUV422;
737 if (is("I420") || is("IYUV"))
738 return VideoFormat::I420;
739 if (is("RGBP"))
740 return VideoFormat::RGB565;
742 }
743
744 void writeData() {
745 long to_write = min((long)parse_buffer.available(), open_subchunk_len);
746 // open_subchunk_len spans the word-aligned chunk (current_stream_data
747 // .size()), which for an odd declared size includes a trailing RIFF pad
748 // byte that must be consumed from the buffer but not delivered as
749 // payload to the audio/video sink - clip to the real, unpadded length.
750 long already_written = (long)current_stream_data.size() - open_subchunk_len;
751 long payload_left = (long)current_stream_data.declaredSize() - already_written;
752 if (payload_left < 0) payload_left = 0;
753 long payload_to_write = min(to_write, payload_left);
754
756 LOGD("audio %d", (int)to_write);
757 if (!is_mute && payload_to_write > 0 && p_output_audio != nullptr){
758 p_output_audio->write(parse_buffer.data(), payload_to_write);
759 }
760 open_subchunk_len -= to_write;
761 cleanupStack();
762 consume(to_write);
763 } else if (current_stream_data.isVideo()) {
764 LOGD("video %d", (int)to_write);
765 // Accumulate rather than forward each piece immediately: a video
766 // chunk (one whole encoded frame) is routinely bigger than
767 // parse_buffer's capacity, so writeData() runs several times per
768 // chunk as more bytes stream in - forwarding each piece straight to
769 // p_output_video as it arrived used to split H.264 NAL units across
770 // separate write() calls at arbitrary byte offsets. TinyH264's
771 // NalReader resets fresh on every write() with no memory of an
772 // incomplete trailing NAL, so a mid-NAL split silently truncated
773 // that NAL and discarded its real continuation bytes - confirmed by
774 // byte-diffing exactly what H264Decoder received against a known-
775 // good ffmpeg extraction of the same stream (identical content,
776 // wrong call boundaries). Buffering the whole chunk here and
777 // delivering it in one write() call once open_subchunk_len reaches
778 // 0 below sidesteps that entirely - the same "one complete
779 // NAL-aligned buffer per frame" delivery DemuxerMP4 already does
780 // (trivially, since MP4's sample table gives it each frame's exact
781 // size up front).
782 if (payload_to_write > 0) {
783 size_t offset = video_accumulator.size();
784 video_accumulator.resize(offset + payload_to_write);
785 memcpy(video_accumulator.data() + offset, parse_buffer.data(),
786 payload_to_write);
787 }
788 open_subchunk_len -= to_write;
789 if (open_subchunk_len == 0 && video_accumulator.size() > 0) {
790 if (p_output_video != nullptr)
793 if (p_output_video_video != nullptr)
797 }
798 cleanupStack();
799 consume(to_write);
800 } else {
801 // Unknown subchunk (not audio/video, e.g. an index or padding chunk) -
802 // skip its payload without delivering it anywhere, using the same
803 // word-aligned length already parsed, so the demuxer keeps making
804 // progress instead of getting stuck reprocessing it.
805 LOGD("skipping unknown subchunk %d", (int)to_write);
806 open_subchunk_len -= to_write;
807 cleanupStack();
808 consume(to_write);
809 }
810 }
811
812 // 'RIFF' fileSize fileType (data)
813 bool parseHeader() {
814 bool header_is_avi = false;
815 int headerSize = 12;
816 if (getStr(0, 4).equals("RIFF")) {
817 ParseObject result;
818 uint32_t header_file_size = getInt(4);
819 // chunk_size = file_size - 8; treat a near-max value (unbounded/
820 // streamed placeholder, mirroring WAVHeader's own convention) as
821 // "unknown" rather than wrapping around when normalizing to file_size
823 header_file_size >= 0xFFFFFFF0 ? 0 : header_file_size + 8;
824 header_is_avi = getStr(8, 4).equals("AVI ");
825 result.set(current_pos, "AVI ", header_file_size, AVIChunk);
826 processStack(result);
827 consume(headerSize);
828
829 } else {
830 LOGE("parseHeader");
831 }
832 return header_is_avi;
833 }
834
838 ParseObject result;
839 result.set(current_pos, getStr(0, 4), 0, AVIChunk);
840 return result;
841 }
842
845 ParseObject tryParseChunk(const char *id) {
846 ParseObject result;
847 if (getStr(0, 4).equals(id)) {
848 result.set(current_pos, id, 0, AVIChunk);
849 }
850 return result;
851 }
852
853 ParseObject tryParseList(const char *id) {
854 ParseObject result;
855 StrView &list_id = getStr(8, 4);
856 if (list_id.equals(id) && getStr(0, 3).equals("LIST")) {
857 result.set(current_pos, getStr(8, 4), getInt(4), AVIList);
858 }
859 return result;
860 }
861
864 ParseObject result;
865 if (getStr(0, 4).equals("LIST")) {
866 result.set(current_pos, getStr(8, 4), getInt(4), AVIList);
867 }
868 return result;
869 }
870
872 ParseObject parseChunk(const char *id) {
873 ParseObject result;
874 int chunk_size = getInt(4);
875 if (getStr(0, 4).equals(id) && parse_buffer.size() >= chunk_size) {
876 result.set(current_pos, id, chunk_size, AVIChunk);
877 processStack(result);
879 }
880 return result;
881 }
882
884 ParseObject parseList(const char *id) {
885 ParseObject result;
886 if (getStr(0, 4).equals("LIST") && getStr(8, 4).equals(id)) {
887 int size = getInt(4);
888 result.set(current_pos, id, size, AVIList);
889 processStack(result);
891 }
892 return result;
893 }
894
896 ParseObject result;
897 int size = getInt(4);
898 result.set(current_pos, getStr(0, 4), size, AVIStreamData);
899 // Always consume the 8-byte chunk header, even for a FOURCC we don't
900 // recognize as audio/video (e.g. an OpenDML 'ix00'/'ix01' index chunk or
901 // 'JUNK' padding embedded inside 'movi') - otherwise current_pos never
902 // advances past it and every subsequent parse() call re-reads the same
903 // unknown header forever (writeData() has nothing to consume for it),
904 // stalling the whole demuxer.
905 processStack(result);
906 consume(8);
907 return result;
908 }
909
910 void processStack(ParseObject &result) {
911 cleanupStack();
912 object_stack.push(result);
913 spaces.setChars(' ', object_stack.size());
914 LOGD("%s - %s (%d-%d) size:%d", spaces.c_str(), result.id(),
915 (int)result.start_pos, (int)result.end_pos, (int)result.data_size);
916 }
917
919 ParseObject current;
920 // make sure that we remove the object from the stack if we past the end.
921 // peek() returns false (leaving 'current' untouched) once the stack is
922 // empty - checking that return value, not just current.end_pos, avoids
923 // reading current's garbage initial value on an empty stack (e.g. the
924 // very first call, before anything has ever been pushed): that garbage
925 // is platform/compiler-dependent, and this loop previously kept
926 // spinning forever on some builds (observed hanging on ESP32-S3 while
927 // an x86-64 desktop build of the exact same source/input happened not
928 // to) whenever it looked <= current_pos.
929 while (object_stack.peek(current) && current.end_pos <= current_pos) {
930 object_stack.pop(current);
931 }
932 }
933
935 StrView &getStr(int offset, int len) {
936 str.setCapacity(len + 1);
937 const char *data = (const char *)parse_buffer.data();
938 str.copyFrom((data + offset), len, 5);
939
940 return str;
941 }
942
944 uint32_t getInt(int offset) {
945 uint32_t *result = (uint32_t *)(parse_buffer.data() + offset);
946 return *result;
947 }
948
950 void consume(int len) {
951 current_pos += len;
953 }
954};
955
958
998class MuxerAVI : public Muxer {
999 public:
1001 MuxerAVI(Print &out) : MuxerAVI() { setOutput(out); }
1002
1003 const char *mimeVideo() override { return "video/avi"; }
1004
1006 void setOutput(Print &out) override { p_out = &out; }
1007
1009 void setVideoInfo(MuxerVideoConfig config) override { video_cfg = config; }
1010
1014
1020 void setAudioInfo(AudioInfoFormat info) override {
1021 audio_info = info;
1022 has_audio = true;
1023 }
1025 AudioInfoFormat &audioInfo() override { return audio_info; }
1026
1029 bool begin() override {
1030 if (p_out == nullptr) {
1031 LOGE("output not defined");
1032 return false;
1033 }
1034 if (video_cfg.width == 0 || video_cfg.height == 0) {
1035 LOGE("invalid video size: %d x %d", (int)video_cfg.width,
1036 (int)video_cfg.height);
1037 return false;
1038 }
1039 writeHeader();
1042 frame_open = false;
1043 is_open = true;
1044 return true;
1045 }
1046
1050 void setStreamType(StreamContentType type) override { write_stream_type = type; }
1053
1055 void end() override { is_open = false; }
1056
1057 operator bool() override { return is_open; }
1058
1063 void beginFrame(size_t size) {
1064 if (!is_open) return;
1065 writeChunkHeader("00dc", (uint32_t)size);
1066 frame_open = true;
1067 frame_remaining = size;
1068 frame_pad = (size % 2) != 0;
1069 }
1070
1076 size_t writeFrame(const uint8_t *data, size_t len) {
1077 if (!is_open || !frame_open) return 0;
1078 size_t to_write = len < frame_remaining ? len : frame_remaining;
1079 size_t written = p_out->write(data, to_write);
1080 frame_remaining -= written;
1081 return written;
1082 }
1083
1086 if (frame_open && frame_pad) p_out->write((uint8_t)0);
1087 frame_open = false;
1089 return 0;
1090 }
1091
1099 size_t write(const uint8_t *data, size_t len) override {
1101 return addAudioFrame(data, len);
1102 }
1103 switch (video_cfg.format) {
1104 case VideoFormat::MJPEG:
1105 return addJpegFrame(data, len);
1107 return addYUV422Frame(data, len);
1109 return addRGB565Frame(data, len);
1110 case VideoFormat::I420:
1111 return addI420Frame(data, len);
1112 default:
1113 return addVideoFrame(data, len);
1114 }
1115 }
1116
1125 size_t addVideoFrame(const uint8_t *data, size_t len,
1126 bool isKeyFrame = true) override {
1127 beginFrame(len);
1128 size_t written = writeFrame(data, len);
1129 endFrame();
1130 return written;
1131 }
1132
1137 size_t addJpegFrame(const uint8_t *data, size_t len) override {
1139 return addVideoFrame(data, len);
1140 }
1141
1144 size_t addYUV422Frame(const uint8_t *data, size_t len) override {
1146 return addVideoFrame(data, len);
1147 }
1148
1151 size_t addRGB565Frame(const uint8_t *data, size_t len) override {
1153 return addVideoFrame(data, len);
1154 }
1155
1159 size_t addI420Frame(const uint8_t *data, size_t len) override {
1161 return addVideoFrame(data, len);
1162 }
1163
1166 size_t addAudioFrame(const uint8_t *data, size_t len) override {
1167 if (!is_open || !has_audio) return 0;
1168 writeChunkHeader("01wb", (uint32_t)len);
1169 size_t written = p_out->write(data, len);
1170 if (len % 2 != 0) p_out->write((uint8_t)0);
1172 return written;
1173 }
1174
1179
1180 protected:
1181 static const uint32_t AVIF_ISINTERLEAVED = 0x00000100;
1182
1183 Print *p_out = nullptr;
1187 bool has_audio = false;
1188 bool is_open = false;
1189 bool frame_open = false;
1190 bool frame_pad = false;
1194
1195 const char *fourCC() {
1196 if (video_cfg.fourcc != nullptr) return video_cfg.fourcc;
1197 switch (video_cfg.format) {
1198 case VideoFormat::H264:
1199 return "H264";
1200 case VideoFormat::MJPEG:
1201 return "MJPG";
1202 case VideoFormat::MPEG4:
1203 return "FMP4";
1204 case VideoFormat::RAW:
1205 return "DIB ";
1207 return "YUY2";
1209 return "RGBP";
1210 case VideoFormat::I420:
1211 return "I420";
1213 return "H264";
1214 }
1215 return "H264";
1216 }
1217
1221
1224 uint16_t biBitCount() {
1225 switch (video_cfg.format) {
1226 case VideoFormat::RAW:
1227 return 24;
1230 return 16;
1231 case VideoFormat::I420:
1232 return 12;
1233 default:
1234 return 24;
1235 }
1236 }
1237
1242 size_t px = (size_t)video_cfg.width * (size_t)video_cfg.height;
1243 switch (format) {
1244 case VideoFormat::RAW:
1245 return px * 3;
1248 return px * 2;
1249 case VideoFormat::I420:
1250 return px + px / 2;
1251 default:
1252 return 0;
1253 }
1254 }
1255
1259
1264 writeU32(0); // BI_RGB
1265 } else if (video_cfg.format == VideoFormat::RGB565) {
1266 writeU32(3); // BI_BITFIELDS
1267 } else {
1268 writeFourCC(fourCC()); // e.g. H264, MJPG, FMP4, YUY2, I420
1269 }
1270 }
1271
1275 if (video_cfg.format != expected) {
1276 LOGW("getVideoInfo().format does not match the addXxxFrame() called");
1277 }
1278 }
1279
1282 void checkRawFrame(VideoFormat expected, size_t len) {
1283 checkVideoFormat(expected);
1284 size_t expected_size = expectedRawFrameSize(expected);
1285 if (expected_size > 0 && len != expected_size) {
1286 LOGW("frame size %d does not match the expected %d bytes for %d x %d",
1287 (int)len, (int)expected_size, (int)video_cfg.width,
1288 (int)video_cfg.height);
1289 }
1290 }
1291
1292 void writeU8(uint8_t v) { p_out->write(v); }
1293 void writeU16(uint16_t v) {
1294 uint8_t b[2] = {(uint8_t)(v & 0xFF), (uint8_t)((v >> 8) & 0xFF)};
1295 p_out->write(b, 2);
1296 }
1297 void writeI16(int16_t v) { writeU16((uint16_t)v); }
1299 uint8_t b[4] = {(uint8_t)(v & 0xFF), (uint8_t)((v >> 8) & 0xFF),
1300 (uint8_t)((v >> 16) & 0xFF), (uint8_t)((v >> 24) & 0xFF)};
1301 p_out->write(b, 4);
1302 }
1303 void writeFourCC(const char *cc) { p_out->write((const uint8_t *)cc, 4); }
1304 void writeZeros(int n) {
1305 for (int j = 0; j < n; j++) writeU8(0);
1306 }
1307 void writeChunkHeader(const char *id, uint32_t size) {
1308 writeFourCC(id);
1309 writeU32(size);
1310 }
1311
1314 uint32_t videoStrfSize() { return 40 + (isBitfields() ? 12 : 0); }
1315
1318 uint32_t videoStrlSize() { return 4 + (8 + 56) + (8 + videoStrfSize()); }
1321 uint32_t audioStrlSize() { return 4 + (8 + 56) + (8 + 18); }
1322
1324 uint32_t micros_per_frame =
1325 video_cfg.fps > 0 ? (uint32_t)(1000000.0f / video_cfg.fps) : 0;
1326 writeChunkHeader("avih", 56);
1327 writeU32(micros_per_frame); // dwMicroSecPerFrame
1328 writeU32(0); // dwMaxBytesPerSec
1329 writeU32(0); // dwPaddingGranularity
1330 writeU32(has_audio ? AVIF_ISINTERLEAVED : 0); // dwFlags
1331 writeU32(0); // dwTotalFrames (unknown)
1332 writeU32(0); // dwInitialFrames
1333 writeU32(has_audio ? 2 : 1); // dwStreams
1334 writeU32(0); // dwSuggestedBufferSize
1335 writeU32(video_cfg.width); // dwWidth
1336 writeU32(video_cfg.height); // dwHeight
1337 writeZeros(16); // dwReserved[4]
1338 }
1339
1341 writeFourCC("LIST");
1343 writeFourCC("strl");
1344
1345 // strh (AVIStreamHeader)
1346 writeChunkHeader("strh", 56);
1347 writeFourCC("vids");
1349 writeU32(0); // dwFlags
1350 writeU16(0); // wPriority
1351 writeU16(0); // wLanguage
1352 writeU32(0); // dwInitialFrames
1353 writeU32(1000); // dwScale
1354 writeU32((uint32_t)(video_cfg.fps * 1000)); // dwRate
1355 writeU32(0); // dwStart
1356 writeU32(0); // dwLength (unknown)
1357 writeU32(0); // dwSuggestedBufferSize
1358 writeU32(0xFFFFFFFF); // dwQuality (use default)
1359 writeU32(0); // dwSampleSize (variable per frame)
1360 writeI16(0); // rcFrame.left
1361 writeI16(0); // rcFrame.top
1362 writeI16((int16_t)video_cfg.width); // rcFrame.right
1363 writeI16((int16_t)video_cfg.height); // rcFrame.bottom
1364
1365 // strf (BITMAPINFOHEADER [+ 3 DWORD color masks for RGB565])
1367 writeU32(40); // biSize (base header; masks, if any, follow)
1368 writeU32(video_cfg.width); // biWidth
1369 writeU32(video_cfg.height); // biHeight
1370 writeU16(1); // biPlanes
1371 writeU16(biBitCount()); // biBitCount
1372 writeBiCompression(); // biCompression
1373 writeU32(biSizeImage()); // biSizeImage
1374 writeU32(0); // biXPelsPerMeter
1375 writeU32(0); // biYPelsPerMeter
1376 writeU32(0); // biClrUsed
1377 writeU32(0); // biClrImportant
1378 if (isBitfields()) {
1379 writeU32(0x0000F800); // red mask
1380 writeU32(0x000007E0); // green mask
1381 writeU32(0x0000001F); // blue mask
1382 }
1383 }
1384
1386 writeFourCC("LIST");
1388 writeFourCC("strl");
1389
1390 uint16_t block_align =
1391 (uint16_t)(audio_info.channels * (audio_info.bits_per_sample / 8));
1392 uint32_t byte_rate = (uint32_t)audio_info.sample_rate * block_align;
1393
1394 // strh (AVIStreamHeader)
1395 writeChunkHeader("strh", 56);
1396 writeFourCC("auds");
1397 writeZeros(4); // fccHandler (unspecified)
1398 writeU32(0); // dwFlags
1399 writeU16(0); // wPriority
1400 writeU16(0); // wLanguage
1401 writeU32(0); // dwInitialFrames
1402 writeU32(1); // dwScale
1404 writeU32(0); // dwStart
1405 writeU32(0); // dwLength (unknown)
1406 writeU32(0); // dwSuggestedBufferSize
1407 writeU32(0xFFFFFFFF); // dwQuality
1408 writeU32(block_align); // dwSampleSize
1409 writeZeros(8); // rcFrame (unused for audio)
1410
1411 // strf (WAVEFORMATEX)
1412 writeChunkHeader("strf", 18);
1413 writeU16((uint16_t)audio_info.format); // wFormatTag
1414 writeU16(audio_info.channels); // nChannels
1415 writeU32((uint32_t)audio_info.sample_rate); // nSamplesPerSec
1416 writeU32(byte_rate); // nAvgBytesPerSec
1417 writeU16(block_align); // nBlockAlign
1418 writeU16(audio_info.bits_per_sample); // wBitsPerSample
1419 writeU16(0); // cbSize
1420 }
1421
1423 // hdrl LIST payload: "hdrl" FOURCC + avih chunk + strl LIST(s), each incl
1424 // their own headers
1425 uint32_t hdrl_size = 4 + (8 + 56) + (8 + videoStrlSize());
1426 if (has_audio) hdrl_size += (8 + audioStrlSize());
1427
1428 writeFourCC("RIFF");
1429 writeU32(0xFFFFFFFF); // total file size: unknown while streaming
1430 writeFourCC("AVI ");
1431
1432 writeFourCC("LIST");
1433 writeU32(hdrl_size);
1434 writeFourCC("hdrl");
1438
1439 writeFourCC("LIST");
1440 writeU32(0xFFFFFFFF); // movi size: unknown while streaming
1441 writeFourCC("movi");
1442 }
1443};
1444
1445} // namespace audio_tools
WAV Audio Formats used by Microsoft e.g. in AVI video files.
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define LIST_HEADER_SIZE
Definition ContainerAVI.h:11
#define CHUNK_HEADER_SIZE
Definition ContainerAVI.h:12
Definition Arduino.h:56
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120
virtual void flush()
Definition Arduino.h:130
AudioInfo info
Definition AudioCodecsBase.h:80
void notifyAudioChange(AudioInfo info)
Definition AudioTypes.h:180
AVI Container Decoder which can be fed with small chunks of data. The minimum length must be bigger t...
Definition ContainerAVI.h:281
virtual size_t write(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:368
BitmapInfoHeader video_info
Definition ContainerAVI.h:472
bool isValid(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:303
void setupVideoInfo()
Definition ContainerAVI.h:703
bool parse()
Definition ContainerAVI.h:516
StrView & getStr(int offset, int len)
Provides the string at the indicated byte offset with the indicated length.
Definition ContainerAVI.h:935
void setMute(bool mute)
Definition ContainerAVI.h:359
ParseObject parseList(const char *id)
We load the indicated list from the current data.
Definition ContainerAVI.h:884
Str str
Definition ContainerAVI.h:493
AVIMainHeader main_header
Definition ContainerAVI.h:469
long current_pos
Definition ContainerAVI.h:490
ParseObject current_stream_data
Definition ContainerAVI.h:476
void setupAudioInfo()
Definition ContainerAVI.h:672
ParseObject parseChunk(const char *id)
We load the indicated chunk from the current data.
Definition ContainerAVI.h:872
Print * p_output_audio
Definition ContainerAVI.h:477
WAVFormatX audio_info
Definition ContainerAVI.h:473
bool(* validation_cb)(DemuxerAVI &avi)
Definition ContainerAVI.h:496
VideoOutput * p_output_video_video
Definition ContainerAVI.h:479
VideoInfo getVideoInfo() override
Definition ContainerAVI.h:422
const char * mimeVideo()
Provides the video mime.
Definition ContainerAVI.h:296
bool send_wav_header
Definition ContainerAVI.h:498
AudioInfoFormat getAudioInfo() override
Definition ContainerAVI.h:447
Print * p_output_video
Definition ContainerAVI.h:478
void end() override
Definition ContainerAVI.h:400
long open_subchunk_len
Definition ContainerAVI.h:489
int videoSeconds()
Provide the length of the video in seconds.
Definition ContainerAVI.h:462
ParseObject tryParseList(const char *id)
Definition ContainerAVI.h:853
bool is_parsing_active
Definition ContainerAVI.h:466
void sendWavHeader()
Definition ContainerAVI.h:689
bool is_mute
Definition ContainerAVI.h:497
bool is_metadata_ready
Definition ContainerAVI.h:495
AVIMainHeader aviMainHeader()
Provides the information from the main header chunk.
Definition ContainerAVI.h:403
uint32_t getInt(int offset)
Provides the int32 at the indicated byte offset.
Definition ContainerAVI.h:944
bool is_wav_header_sent
Definition ContainerAVI.h:500
char video_format[5]
Definition ContainerAVI.h:494
int stream_header_idx
Definition ContainerAVI.h:470
ParseObject tryParseList()
We try to parse the actual state for any list.
Definition ContainerAVI.h:863
Stack< ParseObject > object_stack
Definition ContainerAVI.h:475
long movi_end_pos
Definition ContainerAVI.h:491
void cleanupStack()
Definition ContainerAVI.h:918
Vector< AVIStreamHeader > stream_header
Definition ContainerAVI.h:471
bool isMetadataReady()
Returns true if all metadata has been parsed and is available.
Definition ContainerAVI.h:454
ParseObject parseAVIStreamData()
Definition ContainerAVI.h:895
Vector< uint8_t > video_accumulator
Definition ContainerAVI.h:488
Str spaces
Definition ContainerAVI.h:492
bool isCurrentStreamAudio()
Definition ContainerAVI.h:507
BitmapInfoHeader aviVideoInfo()
Provides the video information.
Definition ContainerAVI.h:409
const char * mime() override
provides the audio mime
Definition ContainerAVI.h:299
void setOutputVideo(Print &out_stream) override
Definition ContainerAVI.h:361
void consume(int len)
We remove the processed bytes from the beginning of the buffer.
Definition ContainerAVI.h:950
void setOutputVideo(VideoOutput &out_stream) override
Definition ContainerAVI.h:364
int video_seconds
Definition ContainerAVI.h:505
void setSendWavHeader(bool flag) override
Definition ContainerAVI.h:316
bool begin() override
Definition ContainerAVI.h:321
bool isCurrentStreamVideo()
Definition ContainerAVI.h:511
virtual void setOutput(Print &out_stream) override
Definition ContainerAVI.h:354
void writeData()
Definition ContainerAVI.h:744
Vector< StreamContentType > content_types
Definition ContainerAVI.h:474
bool header_is_avi
Definition ContainerAVI.h:465
uint32_t riff_file_size
Definition ContainerAVI.h:504
bool parseHeader()
Definition ContainerAVI.h:813
ParseObject tryParseChunk()
Definition ContainerAVI.h:837
ParseBuffer parse_buffer
Definition ContainerAVI.h:468
bool send_wav_header_explicit
Definition ContainerAVI.h:499
WAVFormatX aviAudioInfo()
Provides the audio information.
Definition ContainerAVI.h:414
void setOutputAudio(Print &out_stream) override
Definition ContainerAVI.h:346
const char * aviVideoFormat()
Definition ContainerAVI.h:411
AVIStreamHeader aviStreamHeader(int idx)
Provides the information from the stream header chunks.
Definition ContainerAVI.h:406
static VideoFormat toVideoFormat(uint32_t biCompression, uint16_t biBitCount)
Definition ContainerAVI.h:718
ParseObject tryParseChunk(const char *id)
Definition ContainerAVI.h:845
ParseState parse_state
Definition ContainerAVI.h:467
void setValidationCallback(bool(*cb)(DemuxerAVI &avi))
Definition ContainerAVI.h:457
void processStack(ParseObject &result)
Definition ContainerAVI.h:910
DemuxerAVI(int bufferSize=1024)
Definition ContainerAVI.h:291
Common interface for demuxers (DemuxerAVI, DemuxerMP4) that split a container's video and (optional) ...
Definition ContainerCommon.h:184
Configuration for the (single) video track written by MuxerAVI.
Definition ContainerAVI.h:998
StreamContentType write_stream_type
Definition ContainerAVI.h:1185
bool is_open
Definition ContainerAVI.h:1188
void setOutput(Print &out) override
Defines the output: e.g. a local File or a network Client.
Definition ContainerAVI.h:1006
bool isBitfields()
Definition ContainerAVI.h:1220
void writeI16(int16_t v)
Definition ContainerAVI.h:1297
uint32_t videoStrfSize()
Definition ContainerAVI.h:1314
bool frame_pad
Definition ContainerAVI.h:1190
void writeBiCompression()
Definition ContainerAVI.h:1262
uint32_t biSizeImage()
Definition ContainerAVI.h:1258
size_t addVideoFrame(const uint8_t *data, size_t len, bool isKeyFrame=true) override
Definition ContainerAVI.h:1125
AudioInfoFormat audio_info
Definition ContainerAVI.h:1186
void writeU8(uint8_t v)
Definition ContainerAVI.h:1292
StreamContentType streamType() override
The track write() currently targets (see setStreamType())
Definition ContainerAVI.h:1052
size_t addJpegFrame(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1137
void writeHeader()
Definition ContainerAVI.h:1422
void checkVideoFormat(VideoFormat expected)
Definition ContainerAVI.h:1274
MuxerAVI(Print &out)
Definition ContainerAVI.h:1001
void writeFourCC(const char *cc)
Definition ContainerAVI.h:1303
void checkRawFrame(VideoFormat expected, size_t len)
Definition ContainerAVI.h:1282
bool has_audio
Definition ContainerAVI.h:1187
bool frame_open
Definition ContainerAVI.h:1189
void beginFrame(size_t size)
Definition ContainerAVI.h:1063
AudioInfoFormat & audioInfo() override
Provides read/write access to the audio track's AudioInfoFormat.
Definition ContainerAVI.h:1025
uint32_t audioStrlSize()
Definition ContainerAVI.h:1321
void end() override
Closes the encoder: no trailer is written (streaming AVI has no idx1)
Definition ContainerAVI.h:1055
size_t writeFrame(const uint8_t *data, size_t len)
Definition ContainerAVI.h:1076
void writeU32(uint32_t v)
Definition ContainerAVI.h:1298
void setVideoInfo(MuxerVideoConfig config) override
Defines the video track configuration - call before begin()
Definition ContainerAVI.h:1009
void setStreamType(StreamContentType type) override
Definition ContainerAVI.h:1050
uint32_t endFrame()
Closes the current video frame (word-aligns the chunk)
Definition ContainerAVI.h:1085
size_t addAudioFrame(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1166
size_t write(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1099
size_t frame_remaining
Definition ContainerAVI.h:1191
void writeAudioStrl()
Definition ContainerAVI.h:1385
void setAudioInfo(AudioInfoFormat info) override
Definition ContainerAVI.h:1020
uint32_t videoFrameCount()
Number of video frames written so far.
Definition ContainerAVI.h:1176
size_t expectedRawFrameSize(VideoFormat format)
Definition ContainerAVI.h:1241
uint32_t audioChunkCount()
Number of audio chunks written so far.
Definition ContainerAVI.h:1178
size_t addYUV422Frame(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1144
uint32_t audio_chunk_count
Definition ContainerAVI.h:1193
size_t addI420Frame(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1159
MuxerAVI()
Definition ContainerAVI.h:1000
Print * p_out
Definition ContainerAVI.h:1183
uint32_t videoStrlSize()
Definition ContainerAVI.h:1318
size_t addRGB565Frame(const uint8_t *data, size_t len) override
Definition ContainerAVI.h:1151
void writeVideoStrl()
Definition ContainerAVI.h:1340
const char * fourCC()
Definition ContainerAVI.h:1195
bool begin() override
Definition ContainerAVI.h:1029
void writeU16(uint16_t v)
Definition ContainerAVI.h:1293
void writeChunkHeader(const char *id, uint32_t size)
Definition ContainerAVI.h:1307
uint16_t biBitCount()
Definition ContainerAVI.h:1224
uint32_t video_frame_count
Definition ContainerAVI.h:1192
void writeZeros(int n)
Definition ContainerAVI.h:1304
const char * mimeVideo() override
Definition ContainerAVI.h:1003
void writeMainHeader()
Definition ContainerAVI.h:1323
MuxerVideoConfig getVideoInfo() override
Definition ContainerAVI.h:1013
MuxerVideoConfig video_cfg
Definition ContainerAVI.h:1184
static const uint32_t AVIF_ISINTERLEAVED
Definition ContainerAVI.h:1181
Common interface for muxers (MuxerAVI, MuxerMP4) that combine an already-encoded video track (and opt...
Definition ContainerCommon.h:42
We try to keep the necessary buffer for parsing as small as possible, The data() method provides the ...
Definition ContainerAVI.h:23
Vector< uint8_t > vector
Definition ContainerAVI.h:67
size_t size()
Definition ContainerAVI.h:58
size_t writeArray(uint8_t *data, size_t len)
Definition ContainerAVI.h:25
size_t availableToWrite()
Definition ContainerAVI.h:47
size_t available_byte_count
Definition ContainerAVI.h:68
void consume(int size)
Definition ContainerAVI.h:31
size_t available()
Definition ContainerAVI.h:49
uint8_t * data()
Definition ContainerAVI.h:45
long indexOf(const char *str)
Definition ContainerAVI.h:60
void clear()
Definition ContainerAVI.h:51
bool resize(size_t size)
Definition ContainerAVI.h:40
bool isEmpty()
Definition ContainerAVI.h:56
Represents a LIST or a CHUNK: The ParseObject represents the current parsing result....
Definition ContainerAVI.h:170
size_t size()
Definition ContainerAVI.h:195
bool isVideo()
Definition ContainerAVI.h:255
size_t open
Definition ContainerAVI.h:230
size_t end_pos
Definition ContainerAVI.h:231
WAVFormatX * asAVIAudioFormat(void *ptr)
Definition ContainerAVI.h:219
size_t start_pos
Definition ContainerAVI.h:232
ParseObjectType type()
Definition ContainerAVI.h:201
bool isVideoCompressed()
Definition ContainerAVI.h:250
void set(size_t currentPos, const char *id, size_t size, ParseObjectType type)
Definition ContainerAVI.h:176
char chunk_id[5]
Definition ContainerAVI.h:259
size_t declared_size
Definition ContainerAVI.h:234
ParseObjectType object_type
Definition ContainerAVI.h:266
size_t declaredSize()
Definition ContainerAVI.h:199
BitmapInfoHeader * asVideoFormat(void *ptr)
Definition ContainerAVI.h:220
void set(size_t currentPos, StrView id, size_t size, ParseObjectType type)
Definition ContainerAVI.h:172
int streamNumber()
Definition ContainerAVI.h:237
AVIMainHeader * asAVIMainHeader(void *ptr)
Definition ContainerAVI.h:215
bool isVideoUncompressed()
Definition ContainerAVI.h:245
size_t data_size
Definition ContainerAVI.h:233
bool isAudio()
Definition ContainerAVI.h:240
AVIStreamHeader * asAVIStreamHeader(void *ptr)
Definition ContainerAVI.h:216
const char * id()
Definition ContainerAVI.h:194
bool isValid()
Definition ContainerAVI.h:202
LIFO Stack which is based on a List.
Definition Stack.h:14
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition Str.h:24
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition Str.h:96
void setCapacity(size_t newLen)
Definition Str.h:86
void setChars(char c, int len)
Fills the string with len chars.
Definition Str.h:109
A simple wrapper to provide string functions on existing allocated char*. If the underlying char* is ...
Definition StrView.h:29
virtual bool equals(const char *str)
checks if the string equals indicated parameter string
Definition StrView.h:197
virtual const char * c_str()
provides the string value as const char*
Definition StrView.h:456
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
void push_back(T &&value)
Definition Vector.h:182
void clear()
Definition Vector.h:176
bool resize(size_t newSize, T value)
Definition Vector.h:266
T * data()
Definition Vector.h:321
int size()
Definition Vector.h:178
Abstract class for video playback. This class is used to assemble a complete video frame in memory....
Definition VideoOutput.h:107
virtual size_t write(const uint8_t *data, size_t len)=0
virtual void flush()
Definition VideoOutput.h:113
virtual bool isKeyFrame(const uint8_t *data, size_t len)
Definition VideoOutput.h:135
Parser for Wav header data for details see https://de.wikipedia.org/wiki/RIFF_WAVE.
Definition CodecWAV.h:91
void setAudioInfo(WAVAudioInfo info)
Sets the info in the header.
Definition CodecWAV.h:176
bool writeHeader(Print *out)
Just write a wav header to the indicated outputbu.
Definition CodecWAV.h:179
char[4] FOURCC
Four-character code identifier for AVI format.
Definition ContainerAVI.h:73
VideoFormat
Video codec/pixel-format identifier, shared by two unrelated uses: the (single) video stream of a con...
Definition VideoOutput.h:29
StreamContentType
Which track write() feeds, for muxers (MuxerAVI, MuxerMP4) that double as a plain,...
Definition Video.h:21
size_t videoFrameSizeBytes(VideoFormat format, uint16_t width, uint16_t height)
Fixed per-frame size (bytes) for a raw/uncompressed VideoFormat at the given resolution - 0 for compr...
Definition Video.h:27
AudioFormat
Audio format codes used by Microsoft e.g. in avi or wav files.
Definition AudioFormat.h:21
const char * toMime(AudioFormat format)
Provides the mime type for a AudioFormat wav code, or nullptr if not known/mapped.
Definition AudioFormat.h:308
bool isWavFormat(AudioFormat format)
True if the wav code is handled via the WAV decoder (i.e. toMime() maps it to "audio/wav": PCM and al...
Definition AudioFormat.h:358
@ Audio
Definition Video.h:21
@ Video
Definition Video.h:21
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
ParseObjectType
Definition ContainerAVI.h:148
@ AVIChunk
Definition ContainerAVI.h:148
@ AVIList
Definition ContainerAVI.h:148
@ AVIStreamData
Definition ContainerAVI.h:148
ParseState
Definition ContainerAVI.h:150
@ ParseStrl
Definition ContainerAVI.h:154
@ ParseStrf
Definition ContainerAVI.h:158
@ AfterStrf
Definition ContainerAVI.h:159
@ SubChunkContinue
Definition ContainerAVI.h:155
@ ParseMovi
Definition ContainerAVI.h:160
@ SubChunk
Definition ContainerAVI.h:156
@ ParseRec
Definition ContainerAVI.h:157
@ ParseHdrl
Definition ContainerAVI.h:152
@ ParseHeader
Definition ContainerAVI.h:151
@ ParseIgnore
Definition ContainerAVI.h:161
@ ParseAvih
Definition ContainerAVI.h:153
Definition ContainerAVI.h:75
uint32_t dwStreams
Definition ContainerAVI.h:84
uint32_t dwInitialFrames
Definition ContainerAVI.h:83
uint32_t dwMaxBytesPerSec
Definition ContainerAVI.h:79
uint32_t dwHeight
Definition ContainerAVI.h:87
uint32_t dwReserved[4]
Definition ContainerAVI.h:88
uint32_t dwFlags
Definition ContainerAVI.h:81
uint32_t dwPaddingGranularity
Definition ContainerAVI.h:80
uint32_t dwMicroSecPerFrame
Definition ContainerAVI.h:78
uint32_t dwSuggestedBufferSize
Definition ContainerAVI.h:85
uint32_t dwWidth
Definition ContainerAVI.h:86
uint32_t dwTotalFrames
Definition ContainerAVI.h:82
Definition ContainerAVI.h:96
uint32_t dwSampleSize
Definition ContainerAVI.h:109
uint32_t dwLength
Definition ContainerAVI.h:106
uint32_t dwInitialFrames
Definition ContainerAVI.h:102
uint16_t wPriority
Definition ContainerAVI.h:100
uint16_t wLanguage
Definition ContainerAVI.h:101
FOURCC fccType
Definition ContainerAVI.h:97
uint32_t dwScale
Definition ContainerAVI.h:103
FOURCC fccHandler
Definition ContainerAVI.h:98
uint32_t dwFlags
Definition ContainerAVI.h:99
uint32_t dwStart
Definition ContainerAVI.h:105
uint32_t dwQuality
Definition ContainerAVI.h:108
RECT rcFrame
Definition ContainerAVI.h:110
uint32_t dwRate
Definition ContainerAVI.h:104
uint32_t dwSuggestedBufferSize
Definition ContainerAVI.h:107
AudioInfo extended with a WAVEFORMATEX-style codec tag (the "wav code"): identifies the codec (PCM,...
Definition AudioFormat.h:400
AudioFormat format
Definition AudioFormat.h:409
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:58
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:60
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:62
virtual void logInfo(const char *source="")
Definition AudioTypes.h:127
Definition ContainerAVI.h:116
uint32_t biSizeImage
Definition ContainerAVI.h:123
uint32_t biCompression
Definition ContainerAVI.h:122
uint32_t biWidth
Definition ContainerAVI.h:118
uint16_t biBitCount
Definition ContainerAVI.h:121
uint32_t biHeight
Definition ContainerAVI.h:119
uint32_t biYPelsPerMeter
Definition ContainerAVI.h:125
uint32_t biClrImportant
Definition ContainerAVI.h:127
uint32_t biSize
Definition ContainerAVI.h:117
uint16_t biPlanes
Definition ContainerAVI.h:120
uint32_t biClrUsed
Definition ContainerAVI.h:126
uint32_t biXPelsPerMeter
Definition ContainerAVI.h:124
Shared video track configuration for muxers (MuxerAVI, MuxerMP4) - call before begin().
Definition ContainerCommon.h:11
float fps
Definition ContainerCommon.h:14
const char * fourcc
Definition ContainerCommon.h:20
uint16_t height
Definition ContainerCommon.h:13
uint16_t width
Definition ContainerCommon.h:12
VideoFormat format
Definition ContainerCommon.h:15
Definition ContainerAVI.h:91
uint32_t dwHeight
Definition ContainerAVI.h:93
uint32_t dwWidth
Definition ContainerAVI.h:92
Basic video information (width/height/codec/frame size), analogous to AudioInfo - common to both Demu...
Definition VideoOutput.h:49
uint32_t frame_size
Definition VideoOutput.h:62
uint32_t total_file_size
Definition VideoOutput.h:68
float fps
Definition VideoOutput.h:56
uint16_t height
Frame height in pixels.
Definition VideoOutput.h:53
uint16_t width
Frame width in pixels.
Definition VideoOutput.h:51
VideoFormat format
Video codec - VideoFormat::UNKNOWN if not (yet) determined.
Definition VideoOutput.h:58
Sound information which is available in the WAV header.
Definition CodecWAV.h:32
AudioFormat format
Definition CodecWAV.h:40
bool is_streamed
Definition CodecWAV.h:43
int block_align
Definition CodecWAV.h:42
int byte_rate
Definition CodecWAV.h:41
bool ext_adpcm_header
write the extended 'fmt ' chunk + 'fact' chunk for ADPCM formats
Definition CodecWAV.h:49
Definition ContainerAVI.h:130
uint16_t wBitsPerSample
Definition ContainerAVI.h:136
uint16_t nChannels
Definition ContainerAVI.h:132
uint16_t nBlockAlign
Definition ContainerAVI.h:135
uint32_t nSamplesPerSec
Definition ContainerAVI.h:133
uint32_t nAvgBytesPerSec
Definition ContainerAVI.h:134
uint16_t cbSize
Definition ContainerAVI.h:137
AudioFormat wFormatTag
Definition ContainerAVI.h:131