Skip to content

Commit a9abfa5

Browse files
committed
Support for AV1 MP4 input and output
1 parent 8b8a28c commit a9abfa5

12 files changed

Lines changed: 154 additions & 22 deletions

File tree

embed/min/player.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

embed/min/wrappers/html5.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

embed/min/wrappers/mews.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

embed/wrappers/html5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mistplayers.html5 = {
3535
shortmime = shortmime.join("/");
3636
//works for mp4 but not for webm
3737
function translateCodec(track) {
38+
if (track.codecstring){return track.codecstring;}
3839
function bin2hex(index) {
3940
return ("0"+track.init.charCodeAt(index).toString(16)).slice(-2);
4041
}

embed/wrappers/mews.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mistplayers.mews = {
2222

2323
//check (and save) codec compatibility
2424
function translateCodec(track) {
25+
if (track.codecstring){return track.codecstring;}
2526
function bin2hex(index) {
2627
return ("0"+track.init.charCodeAt(index).toString(16)).slice(-2);
2728
}

lib/dtsc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include "defines.h"
66
#include "dtsc.h"
77
#include "encode.h"
8-
#include "lib/shared_memory.h"
9-
#include "lib/util.h"
8+
#include "shared_memory.h"
9+
#include "util.h"
10+
#include "stream.h"
1011
#include <arpa/inet.h> //for htonl/ntohl
1112
#include <cstdlib>
1213
#include <cstring>
@@ -2710,6 +2711,7 @@ namespace DTSC{
27102711
std::string type = getType(*it);
27112712

27122713
trackJSON["codec"] = getCodec(*it);
2714+
trackJSON["codecstring"] = Util::codecString(getCodec(*it), getInit(*it));
27132715
trackJSON["type"] = type;
27142716
trackJSON["idx"] = (uint64_t)*it;
27152717
trackJSON["trackid"] = (uint64_t)getID(*it);

lib/mp4.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ namespace MP4{
270270
case 0x61616320: return ((AAC *)this)->toPrettyString(indent); break;
271271
case 0x68766331:
272272
case 0x68657631: return ((HEV1 *)this)->toPrettyString(indent); break;
273+
case 0x61763031: return ((AV01 *)this)->toPrettyString(indent); break;
274+
case 0x61763143: return ((AV1C *)this)->toPrettyString(indent); break;
273275
case 0x61766331:
274276
case 0x656E6376: // encv
275277
return ((AVC1 *)this)->toPrettyString(indent);

lib/mp4_generic.cpp

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,70 @@ namespace MP4{
799799
return r.str();
800800
}
801801

802+
803+
AV1C::AV1C(){
804+
memcpy(data + 4, "av1C", 4);
805+
setInt8(0b10000001, 0); // Marker 1, version 1: 0b10000001
806+
}
807+
808+
std::string AV1C::toPrettyString(uint32_t indent){
809+
std::stringstream r;
810+
r << std::string(indent, ' ') << "[av1C] AV1 Init Data (" << boxedSize() << ")" << std::endl;
811+
r << std::string(indent + 1, ' ') << "Marker: " << (int)((getInt8(0) & 0b10000000) >> 7) << std::endl;
812+
r << std::string(indent + 1, ' ') << "Version: " << (int)(getInt8(0) & 0b01111111) << std::endl;
813+
r << std::string(indent + 1, ' ') << "Profile: " << (int)((getInt8(1) & 0b11100000) >> 5) << std::endl;
814+
r << std::string(indent + 1, ' ') << "Level: " << (int)(getInt8(1) & 0b00011111) << std::endl;
815+
816+
r << std::string(indent + 1, ' ') << "Tier: " << (int)((getInt8(2) & 0b10000000) >> 7) << std::endl;
817+
818+
819+
r << std::string(indent + 1, ' ') << "Bit depth: ";
820+
switch ((getInt8(2) & 0b01100000)){
821+
case 0b00000000: r << "8"; break;
822+
case 0b01000000: r << "10"; break;
823+
case 0b01100000: r << "12"; break;
824+
case 0b00100000: r << "Unknown"; break;
825+
}
826+
r << std::endl;
827+
828+
r << std::string(indent + 1, ' ') << "Subsampling format: ";
829+
switch ((getInt8(2) & 0b00011100)){
830+
case 0b00000000: r << "YUV 4:4:4"; break;
831+
case 0b00001000: r << "YUV 4:2:2"; break;
832+
case 0b00001100: r << "YUV 4:2:0"; break;
833+
case 0b00011100: r << "Monochrome 4:0:0"; break;
834+
default: r << "Unknown";
835+
}
836+
r << std::endl;
837+
838+
r << std::string(indent + 1, ' ') << "Subsampling position: ";
839+
switch ((getInt8(2) & 0b00000011)){
840+
case 0: r << "Unknown"; break;
841+
case 1: r << "Vertical"; break;
842+
case 2: r << "Co-located"; break;
843+
case 3: r << "Reserved"; break;
844+
}
845+
r << std::endl;
846+
847+
if (getInt8(3) & 0b00010000){
848+
r << std::string(indent + 1, ' ') << "Initial presentation delay: " << (int)(getInt8(3) & 0b00001111) + 1 << std::endl;
849+
}else{
850+
r << std::string(indent + 1, ' ') << "Initial presentation delay: 0" << std::endl;
851+
}
852+
853+
r << std::string(indent + 1, ' ') << (payloadSize() - 4) << "b of OBU initialization data" << std::endl;
854+
855+
return r.str();
856+
}
857+
858+
void AV1C::setPayload(std::string newPayload){
859+
if (!reserve(0, payloadSize(), newPayload.size())){
860+
ERROR_MSG("Cannot allocate enough memory for payload");
861+
return;
862+
}
863+
memcpy((char *)payload(), (char *)newPayload.c_str(), newPayload.size());
864+
}
865+
802866
Descriptor::Descriptor(){
803867
data = (char *)malloc(2);
804868
data[0] = 0;
@@ -2692,22 +2756,26 @@ namespace MP4{
26922756
avccBox.setPayload(M.getInit(idx));
26932757
setCLAP(avccBox);
26942758
}
2695-
/*LTS-START*/
26962759
if (tCodec == "HEVC"){
26972760
setCodec("hev1");
26982761
MP4::HVCC hvccBox;
26992762
hvccBox.setPayload(M.getInit(idx));
27002763
setCLAP(hvccBox);
27012764
}
2702-
/*LTS-END*/
2765+
if (tCodec == "AV1"){
2766+
setCodec("av01");
2767+
MP4::AV1C av1cBox;
2768+
av1cBox.setPayload(M.getInit(idx));
2769+
setCLAP(av1cBox);
2770+
}
27032771
MP4::PASP paspBox;
27042772
setPASP(paspBox);
27052773
}
27062774

27072775
void VisualSampleEntry::initialize(){
27082776
memcpy(data + 4, "erro", 4);
2709-
setHorizResolution(0x00480000);
2710-
setVertResolution(0x00480000);
2777+
setHorizResolution(72);
2778+
setVertResolution(72);
27112779
setFrameCount(1);
27122780
setCompressorName("");
27132781
setDepth(0x0018);
@@ -2726,17 +2794,17 @@ namespace MP4{
27262794

27272795
uint16_t VisualSampleEntry::getHeight(){return getInt16(26);}
27282796

2729-
void VisualSampleEntry::setHorizResolution(uint32_t newHorizResolution){
2730-
setInt32(newHorizResolution, 28);
2797+
void VisualSampleEntry::setHorizResolution(double newHorizResolution){
2798+
setInt32(newHorizResolution * 65536.0, 28);
27312799
}
27322800

2733-
uint32_t VisualSampleEntry::getHorizResolution(){return getInt32(28);}
2801+
double VisualSampleEntry::getHorizResolution(){return getInt32(28) / 65536.0;}
27342802

2735-
void VisualSampleEntry::setVertResolution(uint32_t newVertResolution){
2736-
setInt32(newVertResolution, 32);
2803+
void VisualSampleEntry::setVertResolution(double newVertResolution){
2804+
setInt32(newVertResolution * 65536.0, 32);
27372805
}
27382806

2739-
uint32_t VisualSampleEntry::getVertResolution(){return getInt32(32);}
2807+
double VisualSampleEntry::getVertResolution(){return getInt32(32) / 65536.0;}
27402808

27412809
void VisualSampleEntry::setFrameCount(uint16_t newFrameCount){setInt16(newFrameCount, 40);}
27422810

@@ -2839,8 +2907,8 @@ namespace MP4{
28392907
r << toPrettySampleString(indent);
28402908
r << std::string(indent + 1, ' ') << "Width: " << getWidth() << std::endl;
28412909
r << std::string(indent + 1, ' ') << "Height: " << getHeight() << std::endl;
2842-
r << std::string(indent + 1, ' ') << "HorizResolution: " << getHorizResolution() << std::endl;
2843-
r << std::string(indent + 1, ' ') << "VertResolution: " << getVertResolution() << std::endl;
2910+
r << std::string(indent + 1, ' ') << "HorizResolution: " << getHorizResolution() << " DPI" << std::endl;
2911+
r << std::string(indent + 1, ' ') << "VertResolution: " << getVertResolution() << " DPI" << std::endl;
28442912
r << std::string(indent + 1, ' ') << "FrameCount: " << getFrameCount() << std::endl;
28452913
r << std::string(indent + 1, ' ') << "CompressorName: " << getCompressorName() << std::endl;
28462914
r << std::string(indent + 1, ' ') << "Depth: " << getDepth() << std::endl;
@@ -3249,6 +3317,12 @@ namespace MP4{
32493317
return toPrettyVisualString(indent, "[h264] H.264/MPEG-4 AVC");
32503318
}
32513319

3320+
AV01::AV01(){memcpy(data + 4, "av01", 4);}
3321+
3322+
std::string AV01::toPrettyString(uint32_t indent){
3323+
return toPrettyVisualString(indent, "[av01] AV1 Video");
3324+
}
3325+
32523326
FIEL::FIEL(){memcpy(data + 4, "fiel", 4);}
32533327

32543328
void FIEL::setTotal(char newTotal){setInt8(newTotal, 0);}

lib/mp4_generic.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ namespace MP4{
200200
h265::metaInfo getMetaInfo();
201201
};
202202

203+
class AV1C : public Box{
204+
public:
205+
AV1C();
206+
void setPayload(std::string newPayload);
207+
std::string toPrettyString(uint32_t indent = 0);
208+
};
209+
203210
class Descriptor{
204211
public:
205212
Descriptor();
@@ -694,10 +701,10 @@ namespace MP4{
694701
uint16_t getWidth();
695702
void setHeight(uint16_t newHeight);
696703
uint16_t getHeight();
697-
void setHorizResolution(uint32_t newHorizResolution);
698-
uint32_t getHorizResolution();
699-
void setVertResolution(uint32_t newVertResolution);
700-
uint32_t getVertResolution();
704+
void setHorizResolution(double newHorizResolution);
705+
double getHorizResolution();
706+
void setVertResolution(double newVertResolution);
707+
double getVertResolution();
701708
void setFrameCount(uint16_t newFrameCount);
702709
uint16_t getFrameCount();
703710
void setCompressorName(std::string newCompressorName);
@@ -851,6 +858,12 @@ namespace MP4{
851858
std::string toPrettyString(uint32_t indent = 0);
852859
};
853860

861+
class AV01 : public VisualSampleEntry{
862+
public:
863+
AV01();
864+
std::string toPrettyString(uint32_t indent = 0);
865+
};
866+
854867
class FIEL : public Box{
855868
public:
856869
FIEL();

0 commit comments

Comments
 (0)