问题
I wish to determine the MIME type of the contents of a pipe. The pipe is outputting a transcoded video stream, so there is no corresponding file extension.
Can I determine the MIME type in these circumstances using say ffprobe -i pipe:0
or some equivalent? Is there a canonical mapping of codecs or container formats to MIME type?
回答1:
You can use DetectContentType to guess the content type based on the magic numbers: http://golang.org/pkg/net/http/#DetectContentType
回答2:
My suggestion would be to either:
1) Transfer the MIME type over the pipe before sending the data.
or
2) Look at the first couple of bytes (header) of the stream, normally video and audio files identify their format in the first 2 to 3 bytes.
or
3) Read the format specifications of the different formats you are expecting and try to figure out the the format based on common patterns (sync points where available, for instance).
来源:https://stackoverflow.com/questions/10985953/mime-type-for-transcoded-stream