Nasty hack for fixing H264 init data on FLV
This commit is contained in:
parent
b244618737
commit
939924439d
4 changed files with 22 additions and 2 deletions
|
@ -15,7 +15,7 @@ namespace Bit{
|
|||
//Host to binary/binary to host functions - similar to kernel ntoh/hton functions.
|
||||
|
||||
/// Retrieves a short in network order from the pointer p.
|
||||
inline unsigned short btohs(char * p) {
|
||||
inline unsigned short btohs(const char * p) {
|
||||
return ((unsigned short)p[0] << 8) | p[1];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <string.h> //memcpy
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#include "h264.h" //Needed for init data parsing in case of invalid values from FLV init
|
||||
|
||||
/// Holds the last FLV header parsed.
|
||||
/// Defaults to a audio+video header on FLV version 0x01 if no header received yet.
|
||||
char FLV::Header[13] = {'F', 'L', 'V', 0x01, 0x05, 0, 0, 0, 0x09, 0, 0, 0, 0};
|
||||
|
@ -1099,6 +1102,16 @@ JSON::Value FLV::Tag::toJSON(DTSC::Meta & metadata, AMF::Object & amf_storage, u
|
|||
}
|
||||
metadata.tracks[reTrack].init = std::string((char *)data + 12, (size_t)len - 16);
|
||||
}
|
||||
///this is a hacky way around invalid FLV data (since it gets ignored nearly everywhere, but we do need correct data...
|
||||
if (!metadata.tracks[reTrack].width || !metadata.tracks[reTrack].height || !metadata.tracks[reTrack].fpks){
|
||||
h264::sequenceParameterSet sps;
|
||||
sps.fromDTSCInit(metadata.tracks[reTrack].init);
|
||||
h264::SPSMeta spsChar = sps.getCharacteristics();
|
||||
metadata.tracks[reTrack].width = spsChar.width;
|
||||
metadata.tracks[reTrack].height = spsChar.height;
|
||||
metadata.tracks[reTrack].fpks = spsChar.fps * 1000;
|
||||
|
||||
}
|
||||
pack_out.null();
|
||||
return pack_out; //skip rest of parsing, get next tag.
|
||||
}
|
||||
|
|
|
@ -81,6 +81,12 @@ namespace h264 {
|
|||
|
||||
sequenceParameterSet::sequenceParameterSet(const char * _data, unsigned long _dataLen) : data(_data), dataLen(_dataLen) {}
|
||||
|
||||
//DTSC Initdata is the payload for an avcc box. init[8+] is data, init[6-7] is a network-encoded length
|
||||
void sequenceParameterSet::fromDTSCInit(const std::string & dtscInit){
|
||||
data = dtscInit.data() + 8;
|
||||
dataLen = Bit::btohs(dtscInit.data() + 6);
|
||||
}
|
||||
|
||||
SPSMeta sequenceParameterSet::getCharacteristics() const {
|
||||
SPSMeta result;
|
||||
|
||||
|
|
|
@ -50,7 +50,8 @@ namespace h264 {
|
|||
|
||||
class sequenceParameterSet {
|
||||
public:
|
||||
sequenceParameterSet(const char * _data, unsigned long _dataLen);
|
||||
sequenceParameterSet(const char * _data = NULL, unsigned long _dataLen = 0);
|
||||
void fromDTSCInit(const std::string & dtscInit);
|
||||
SPSMeta getCharacteristics() const;
|
||||
private:
|
||||
const char * data;
|
||||
|
|
Loading…
Add table
Reference in a new issue