.m4a is considered audio/m4a or audio/mp4 - ios

I'm trying to make an audio upload to S3 and I'm a little confused what I should declare my mime type as. My audio file is an m4a recorded on an iphone as kAudioFormatMPEG4AAC. Would this be considered audio/m4a or audio/mp4? I'm seeing conflicting answers online.

The m4 in m4a is short-hand for MPEG-4, just like mp4 is short-hand for MPEG-4.
In fact, m4a, m4v and mp4 files all have the same internal MPEG-4 atom structure. The difference between the files is their content (video files have video atoms as well as audio atoms.)
The codec of the audio can also be different despite using the same file extension, for example both alac and AAC formats use the MPEG-4 container format with the m4a file extension.
So to answer your question, it really doesn't make much difference. My personal preference would be audio/mp4 since that is effectively saying
Audio data in MPEG-4 container
Whereas, audio/m4a is like saying
Audio data in MPEG-4 container containing audio

Use audio/mp4. audio/m4a may work, but it's invalid.
MP4 MIME type registration:
2. Selection of MIME Types for MP4 Files
The MIME types to be assigned to MP4 files are selected according to
the contents. Basic guidelines for selecting MIME types are as
follows:
a) if the file contains neither visual nor audio presentations, but
only, for example, MPEG-J or MPEG-7, use application/mp4;
b) for all other files, including those that have MPEG-J, etc., in
addition to video or audio streams, video/mp4 should be used;
however:
c) for files with audio but no visual aspect, including those that
have MPEG-J, etc., in addition to audio streams, audio/mp4 may be
used.
In any case, these indicate files conforming to the "MP4"
specification, ISO/IEC 14496-1:2000, systems file format.
Further, the list of standard MIME types includes audio/mp4, not audio/m4a, and non-standard MIME types should include “x-”, like audio/x-m4a.

In 2021 for me audio/mp4 for an .m4a file worked on Firefox + Chrome (Linux), Opera (Android) but not on iPhone Safari. For some formats the OS plays a role due to codecs.
I used a source tag with type attribute set and I also set the same type in the Content-Type header of the streamed / downloaded file.
https://en.wikipedia.org/wiki/HTML5_audio#Supported_audio_coding_formats
https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery/Cross-browser_audio_basics
https://developer.mozilla.org/en-US/docs/Web/HTTP/Configuring_servers_for_Ogg_media
Also see: How to play .m4a with HTML5 audio in IE(9+) and Safari (Pad)?

Related

libffmpeg: writing an RTSP stream to an output file

I'm working with libffmpeg in an iOS app. My goal is to connect to an RTSP source and write the media out to a file that can later be used with the iOS media player. Ideally I'd like to do this without transcoding the incoming data. I also want to be able to later re-encode the media with AVAssetExportSession if the user chooses to do so.
Because I want to create a file that is compatible with iOS, I'm limited (I believe) to mpeg, mp4 or quicktime (mov) formats.
Whenever I try to use one of these formats, I see the following warnings during my call to avformat_write_header:
[mov # 0x16401c00] Codec for stream 0 does not use global headers but container format requires global headers
[mov # 0x16401c00] Codec for stream 1 does not use global headers but container format requires global headers
My understanding is that the header wants to know the ultimate file size, which I do not know (the RTSP server is live streaming a camera, and the user stops the recording whenever they want). I guess that makes sense, but I know that others have successfully done this using the ffmpeg command line, so I'm confused as to what else I need to do here.
If I ignore the warning, I can still proceed with writing the file. If I choose mpeg or mp4 formats, my app crashes when I call av_write_trailer. If I use mov, I can successfully close the file, and the file does play back, but usually fails when I try to hand it to the AVAssetExportSession.
I would appreciate any insight into this. Thanks.
Frank
I found what appears to be a solution -- at least, it eliminates the warning. I had to set the CODEC_FLAG_GLOBAL_HEADER on both the audio and video codecs, before calling avcodec_open2.

Can I cast m3u files to Chromecast?

is it possible to cast m3u8 file.? I am using avplayer. In google cast site they mentioned that it only support formats : -
AAC
MP3
MP4
WAV
WebM
link : https://developers.google.com/cast/docs/media
If m3u8 is supporting, how can I implement it programatically?
m3u8 playlists are supported. You can read the docs; there is not much difference between casting an mp4 or m3u8; you may need to make sure CORS headers are sent from the content server. To see an example, look at the official sample CastVideos-android sample that can play such content.

Streaming Technique from pocketcast in xcode

I've been asked by my client whether it is possible to download a video and stream it once a bit has downloaded, just like pocketcasts does. His reasoning is this will allow him to store his video files on a site such as godaddy and bypass the need to stream the file to the phone which normally requires a dedicated server.
Is this even possible? if so do you know anywhere I can look to find out how pocketcasts does it? At the moment my app just streams an mp4.
Thanks for looking,
Matt
Since you're targetting iOS, HLS (HTTP Live Streaming) is your friend: https://developer.apple.com/streaming/
Please see my answer here for how you can use it: Simultaneously downloading and playing a song that is pieced together from multiple URLs
It's very easy to run a long movie through the mediafilesegmenter tool from Apple (or FFMPEG) which spits out a number of small .ts files (MPEG 2 Transport Stream). Then you create a manifest (a .m3u8 file) which describes how these files fit together (which mediafilesegment will create for you too!). Then you just put the manifest file and the .ts files on a hosting provider (like GoDaddy) and you're all set.
For example, given a file called test.mp4, first turn it into a .ts file with ffmpeg:
ffmpeg -i test.mp4 -acodec copy -vcodec copy -bsf h264_mp4toannexb test.ts
Then turn it into a series of HLS segments with mediafilesegmenter (the same can be done using the ffmpeg segment muxer, but mediafilesegmenter seems to be more robust):
mediafilesegmenter -t 3 test.ts
The result is a bunch of 3 second clips (that's what -t 3 means) and an manifest file called prog_index.m3u8. The contents of that look like:
#EXTM3U
#EXT-X-TARGETDURATION:3
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:2.99520,
fileSequence0.ts
#EXTINF:2.99520,
fileSequence1.ts
#EXTINF:2.99520,
fileSequence2.ts
#EXTINF:2.99520,
fileSequence3.ts
...
#EXTINF:0.37440,
fileSequence75.ts
#EXT-X-ENDLIST
Simply putting all of the .ts files and the .m3u8 file on a web server and pointing your AVPlayer or MPMoviePlayerController in iOS at the URL for the .m3u8 will get you an excellent streaming performance.

How iOS HTML5 video player detects a file type?

Now i am implementing a video playback on my site and for mobile devices i use HTML 5 video player:
<video src="/get_video.php/myfile.mov" controls width="400" height="250"></video>
In src attribute stored url to php file which output a contents of video file. MIME-type of file i don't know(it's dynamic) so i send content type header - application/octet-stream.
And my iPhone cant play this video: screenshot
So Question: How to force the player to play videos?
Thanks.
First of all, I recommend reading these resources on Video tags:
http://www.w3schools.com/tags/tag_video.asp
http://www.w3schools.com/tags/att_video_src.asp
https://developer.mozilla.org/en-US/docs/HTML/Element/video
As I understand, you have to specify in your MIME type a real video type (vs application/octet-stream). You mentioned that it's dynamic, however on the server side you know which file are you reading (so, you can figure out file format).
Supported types are:
video/mp4
video/webm
video/ogg

Writing QuickTime files manually

In the app I'm working on, there's an AVIRecord class that manually write AVI headers and JPEG frames into a video files. They are .avi files with MJPEG codec, according to my media player (using KLite codec pack).
My question is: is this AVI compressed or uncompressed? Because the file size is basically sum of all the jpeg frames.
Can I write a similar code to produce a .mov file (Quicktime format)? By similar i mean: writing headers to the file, putting each frames manually into the files.
The app I am working on is supposed to save the jpeg stream from a IP Cam and save it under quicktime format.
Most file formats like AVI, MOV do not compress the video and audio bitstreams present in them. File formats are used to store video and audio decodeable units with associated metadata like timestamps. So when you add JPEGs to AVI file, it does not get compressed any further.
You can create MOV file with MJPEG video, similar to way you have been able to create AVI file with MJPEG video. However you would need creator for MOV (similar to the one you have for AVI).
MOV file format has been specified by Apple. A version of the format is available at http://developer.apple.com/standards/qtff-2001.pdf

Resources