History

iso: support nal lengths other than 4

Sigrid Solveig Haflínudóttir committed 5 years ago

Commit 58c64801 parent d3149941 file · +59 −27Browse files

Unified · Split

iso.c+59−27
@@ -567,16 +567,21 @@ static int · 566 unmodified lines
567567 dumpstc(Biobuf *f, Biobuf *out, Track *t, u8int *frame)
568568 {
569569 SampleToChunk *stc;
570− u32int si, ch, nextch, n, len;
570+ u32int si, ch, nextch, n, k, len, sz;
571571 u32int samplelast, sample, rawsz, samplesz;
572572 u64int ts;
573− u8int *raw;
573+ u8int *raw, h[4];
574574
575575 raw = nil;
576576 rawsz = 0;
577577 sample = samplelast = 0;
578578 stc = t->stc;
579579 ch = 0;
580+ k = t->video.avc.nallen;
581+ h[0] = 0;
582+ h[1] = 0;
583+ h[2] = 0;
584+ h[3] = 1;
580585 for(si = 0; si < t->numstc; si++, stc++){
581586 nextch = t->numchunks;
582587 if(si+1 < t->numstc)
@@ -613,11 +618,21 @@ dumpstc(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 30 unmodified lines
613618 break;
614619 }
615620 }else if(t->video.format != 0){ /* all video goes out as IVF */
621+ if(t->video.format == FmtAvc1){
622+ for(sz = 0, n = 0; n < samplesz; n += k+len){
623+ len = raw[n+0];
624+ if(k > 1) len = len<<8 | raw[n+1];
625+ if(k > 2) len = len<<8 | raw[n+2];
626+ if(k > 3) len = len<<8 | raw[n+3];
627+ sz += 4+len;
628+ }
629+ }else
630+ sz = samplesz;
616631 ts = tts(t, sample);
617− frame[0] = samplesz;
618− frame[1] = samplesz >> 8;
619− frame[2] = samplesz >> 16;
620− frame[3] = samplesz >> 24;
632+ frame[0] = sz;
633+ frame[1] = sz >> 8;
634+ frame[2] = sz >> 16;
635+ frame[3] = sz >> 24;
621636 frame[4] = ts;
622637 frame[5] = ts >> 8;
623638 frame[6] = ts >> 16;
@@ -632,15 +647,15 @@ dumpstc(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 8 unmodified lines
632647 }
633648 }
634649 if(t->video.format == FmtAvc1){
635− for(n = 0; n < samplesz; n += len+4){
636− len = raw[n+0]<<24 | raw[n+1]<<16 | raw[n+2]<<8 | raw[n+3];
637− raw[n+0] = 0;
638− raw[n+1] = 0;
639− raw[n+2] = 0;
640− raw[n+3] = 1;
650+ for(n = 0; n < samplesz; n += k+len){
651+ len = raw[n+0];
652+ if(k > 1) len = len<<8 | raw[n+1];
653+ if(k > 2) len = len<<8 | raw[n+2];
654+ if(k > 3) len = len<<8 | raw[n+3];
655+ Bwrite(out, h, 4);
656+ Bwrite(out, raw+n+k, len);
641657 }
642− }
643− if(Bwrite(out, raw, samplesz) != samplesz){ /* EOF? */
658+ }else if(Bwrite(out, raw, samplesz) != samplesz){ /* EOF? */
644659 werrstr("eof");
645660 break;
646661 }
@@ -656,9 +671,9 @@ dumpstc(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 9 unmodified lines
656671 static int
657672 dumptrun(Biobuf *f, Biobuf *out, Track *t, u8int *frame)
658673 {
659− int i, j, len, n;
674+ int i, j, len, n, k;
660675 u64int ts;
661− u8int *raw;
676+ u8int *raw, h[4];
662677 int maxsz, sz;
663678 RunSample *s;
664679 Moof *m;
@@ -668,6 +683,11 @@ dumptrun(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 3 unmodified lines
668683 ts = 0;
669684 maxsz = 0;
670685 raw = nil;
686+ k = t->video.avc.nallen;
687+ h[0] = 0;
688+ h[1] = 0;
689+ h[2] = 0;
690+ h[3] = 1;
671691 for(i = 0, m = t->moof; i < t->nmoof; i++, m++){
672692 for(j = 0; j < m->trun.trun.samplecount; j++){
673693 s = &m->trun.trun.samples[j];
@@ -717,15 +737,27 @@ dumptrun(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 43 unmodified lines
717737 return -1;
718738 }
719739 if(t->video.format == FmtAvc1){
720− for(n = 12; n < 12+s->size; n += len+4){
721− len = raw[n+0]<<24 | raw[n+1]<<16 | raw[n+2]<<8 | raw[n+3];
722− raw[n+0] = 0;
723− raw[n+1] = 0;
724− raw[n+2] = 0;
725− raw[n+3] = 1;
740+ for(sz = 0, n = 12; n < 12+s->size; n += len+k){
741+ len = raw[n+0];
742+ if(k > 1) len = len<<8 | raw[n+1];
743+ if(k > 2) len = len<<8 | raw[n+2];
744+ if(k > 3) len = len<<8 | raw[n+3];
745+ sz += 4+len;
726746 }
727− }
728− if(Bwrite(out, raw, 12 + s->size) != 12 + s->size) /* eof? */
747+ raw[0] = sz;
748+ raw[1] = sz >> 8;
749+ raw[2] = sz >> 16;
750+ raw[3] = sz >> 24;
751+ Bwrite(out, raw, 12);
752+ for(n = 12; n < 12+s->size; n += len+k){
753+ len = raw[n+0];
754+ if(k > 1) len = len<<8 | raw[n+1];
755+ if(k > 2) len = len<<8 | raw[n+2];
756+ if(k > 3) len = len<<8 | raw[n+3];
757+ Bwrite(out, h, 4);
758+ Bwrite(out, raw+n+k, len);
759+ }
760+ }else if(Bwrite(out, raw, 12 + s->size) != 12 + s->size) /* eof? */
729761 break;
730762 ts += s->duration; /* sample's "time offset" is ignored here */
731763 }else{
@@ -740,7 +772,7 @@ dumptrun(Biobuf *f, Biobuf *out, Track *t, u8int *frame) · 8 unmodified lines
740772 static int
741773 dumptrack(Biobuf *f, int id)
742774 {
743− int i, j, x, res;
775+ int i, j, x, k, res;
744776 Biobuf out;
745777 u64int dur;
746778 Track *t;
@@ -832,8 +864,8 @@ dumptrack(Biobuf *f, int id) · 85 unmodified lines
832864 Bwrite(&out, frame, 0x20);
833865
834866 if(t->video.format == FmtAvc1){
835− if(t->video.avc.nallen != 4){
836− werrstr("avc1 nallen != 4 isn't supported yet");
867+ if(t->video.avc.nallen < 1 || t->video.avc.nallen > 4){
868+ werrstr("avc1: invalid nallen %d", t->video.avc.nallen);
837869 return -1;
838870 }
839871 memset(frame, 0, 4+8+4);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t