@@ -50,6 +50,13 @@ export function getShortMIMEString(info) {
5050 if ( ! info ) throw `Invalid ProbeInfo` ;
5151 if ( ! info . streams || info . streams . length === 0 ) throw `No streams in ProbeInfo` ;
5252
53+ // mp3 files are always considered audio/.
54+ if ( info . format . format_name === 'mp3' ) {
55+ return 'audio/mpeg' ;
56+ }
57+
58+ // Otherwise, any file with at least 1 video stream is considered video/.
59+ // Otherwise, any file with at least 1 audio stream is considered audio/.
5360 const type = info . streams . some ( s => s . codec_type === 'video' ) ?
5461 'video' :
5562 info . streams . some ( s => s . codec_type === 'audio' ) ? 'audio' : undefined ;
@@ -98,16 +105,30 @@ export function getShortMIMEString(info) {
98105export function getFullMIMEString ( info ) {
99106 /** A string like 'video/mp4' */
100107 let contentType = `${ getShortMIMEString ( info ) } ` ;
108+ // If MP3, just send back the type.
109+ if ( contentType === 'audio/mpeg' ) {
110+ return contentType ;
111+ }
112+
101113 let codecFrags = new Set ( ) ;
102114
103115 for ( const stream of info . streams ) {
104116 if ( stream . codec_type === 'audio' ) {
105- // TODO! At least mp4a!
117+ switch ( stream . codec_tag_string ) {
118+ case 'mp4a' : codecFrags . add ( getMP4ACodecString ( stream ) ) ; break ;
119+ // TODO: vorbis.
120+ // TODO: opus.
121+ default :
122+ }
106123 }
107124 else if ( stream . codec_type === 'video' ) {
108125 switch ( stream . codec_tag_string ) {
109126 case 'avc1' : codecFrags . add ( getAVC1CodecString ( stream ) ) ; break ;
110127 case 'vp09' : codecFrags . add ( getVP09CodecString ( stream ) ) ; break ;
128+ // We don't handle these as video streams with codecs, so skip them.
129+ case 'png' :
130+ case 'mjpeg' :
131+ continue ;
111132 default :
112133 throw `Could not handle codec_tag_string ${ stream . codec_tag_string } yet. ` +
113134 `Please file a bug https://github.com/codedread/bitjs/issues/new` ;
@@ -116,7 +137,6 @@ export function getFullMIMEString(info) {
116137 }
117138
118139 if ( codecFrags . length === 0 ) return contentType ;
119-
120140 return contentType + '; codecs="' + Array . from ( codecFrags ) . join ( ',' ) + '"' ;
121141}
122142
@@ -215,3 +235,22 @@ function getVP09CodecString(stream) {
215235
216236 return frag ;
217237}
238+
239+ /**
240+ * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#mp4a
241+ * @param {ProbeStream } stream
242+ * @returns {string }
243+ */
244+ function getMP4ACodecString ( stream ) {
245+ let frag = 'mp4a.40' ;
246+ switch ( stream . profile ) {
247+ case 'LC' :
248+ frag += '.2' ;
249+ break ;
250+ // TODO: more!
251+ default :
252+ throw `Cannot handle AAC stream with profile ${ stream . profile } yet. ` +
253+ `Please file a bug https://github.com/codedread/bitjs/issues/new` ;
254+ }
255+ return frag ;
256+ }
0 commit comments