shithub: mcfs

Download patch

ref: 564664d7fc2e3822f6d5ce04cb873d5a079b62e8
parent: 792fec9929df590a990c94a0ac96f4b769234c90
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Sep 14 17:49:19 EDT 2020

dump trun audio samples

--- a/iso.c
+++ b/iso.c
@@ -616,15 +616,12 @@
 	int i, j;
 	u64int ts;
 	u8int *raw;
-	int maxsz;
+	int maxsz, sz;
 	RunSample *s;
 	Moof *m;
 
 	USED(frame);
 
-	if(t->video.format == 0)
-		sysfatal("trun dump only works with IVF atm"); /* FIXME */
-
 	ts = 0;
 	maxsz = 0;
 	raw = nil;
@@ -635,29 +632,53 @@
 				maxsz = 12 + s->size;
 				raw = realloc(raw, maxsz);
 			}
-			raw[0] = s->size;
-			raw[1] = s->size >> 8;
-			raw[2] = s->size >> 16;
-			raw[3] = s->size >> 24;
-			raw[4] = ts;
-			raw[5] = ts >> 8;
-			raw[6] = ts >> 16;
-			raw[7] = ts >> 24;
-			raw[8] = ts >> 32;
-			raw[9] = ts >> 40;
-			raw[10] = ts >> 48;
-			raw[11] = ts >> 56;
-			if(Bseek(f, s->offset, 0) != s->offset){
-				werrstr("couldn't seek to offset %zd", s->offset);
-				return -1;
+
+			if(t->audio.format == FmtMp4a){
+				sz = 7 + s->size;
+				raw[0] = frame[0];
+				raw[1] = frame[1];
+				raw[2] = frame[2];
+				raw[3] = (t->audio.channels&3)<<6 | (sz>>11)&3; /* channels, frame length */
+				raw[4] = (sz>>3); /* frame length */
+				raw[5] = (sz&7)<<5 | 0x1f; /* frame length, fullness */
+				raw[6] = 0xfc; /* fullness, number of frames */
+				if(Bseek(f, s->offset, 0) != s->offset){
+					werrstr("couldn't seek to offset %zd", s->offset);
+					return -1;
+				}
+				if(Bread(f, raw+7, s->size) != s->size){
+					werrstr("couldn't read sample (%d bytes)", s->size);
+					return -1;
+				}
+				if(Bwrite(out, raw, 7 + s->size) != 7 + s->size) /* eof? */
+					break;
+			}else if(t->video.format != 0){
+				raw[0] = s->size;
+				raw[1] = s->size >> 8;
+				raw[2] = s->size >> 16;
+				raw[3] = s->size >> 24;
+				raw[4] = ts;
+				raw[5] = ts >> 8;
+				raw[6] = ts >> 16;
+				raw[7] = ts >> 24;
+				raw[8] = ts >> 32;
+				raw[9] = ts >> 40;
+				raw[10] = ts >> 48;
+				raw[11] = ts >> 56;
+				if(Bseek(f, s->offset, 0) != s->offset){
+					werrstr("couldn't seek to offset %zd", s->offset);
+					return -1;
+				}
+				if(Bread(f, raw+12, s->size) != s->size){
+					werrstr("couldn't read sample (%d bytes)", s->size);
+					return -1;
+				}
+				if(Bwrite(out, raw, 12 + s->size) != 12 + s->size) /* eof? */
+					break;
+				ts += s->duration; /* sample's "time offset" is ignored here */
+			}else{
+				sysfatal("don't know how to dump this one");
 			}
-			if(Bread(f, raw+12, s->size) != s->size){
-				werrstr("couldn't read sample (%d bytes)", s->size);
-				return -1;
-			}
-			if(Bwrite(out, raw, 12 + s->size) != 12 + s->size) /* eof? */
-				break;
-			ts += s->duration; /* sample's "time offset" is ignored here */
 		}
 	}