1

I have an app that allows the user to either select a video from their library or take video with the camera and them upload it to a server. I need the video to be in a particular format (m4v, h.264, AAC) when I send it to the server. In iOS 5 and perhaps earlier, the video records as a .mov file (albeit with h.264 and AAC).

How can I convert the video to m4v? Admittedly I'm a little sketchy on the details and differences in video encoding, so forgive me if I'm being ignorant here.

David Beck
  • 10,099
  • 5
  • 51
  • 88

1 Answers1

4

David, can I suggest that your server does the transcoding? Doing the transcoding on a phone is complicated and tedious. However, iPhone's already use h.264 and AAC encoding so are you sure you need to even do anything? .mov vs .m4v might not really matter for you, all the extension indicates is what atoms the container supports. I've found that 90% of the time videos are pretty basic and use the minimal feature set of a container format. For a comparison check the wiki page: http://en.wikipedia.org/wiki/Comparison_of_container_formats.

You can always double check the structure of the files using Atom Box Viewer (there is a 2 day trial download period and it can be useful for investigating video file structure) http://www.jongbel.com/?page_id=114. Unfortunately, it's not very intuitive since it assumes you have an understanding of video containers, however, you can pretty quickly tell if your target container matches the container you get from the iPhone.

If you do need to enforce container/content semantics though, short of writing your own transcoder I suggest you look into using ffmpeg http://ffmpeg.org/. ffmpeg supports lots of different containers and formats for both audio and video. For example you can enforce your standards by calling it like this:

ffmpeg.exe -i inputFile.mp4 -vcodec libx264 -s 320x240 -acodec libfaac outputFile.m4v

The example I gave you is very simple, to break it down its this:

-i => input file
-vcodec libx264 => video codec set to use h.264 using the x264 encoder. to list more you can do: ffmpeg -formats
-s 320x240 => here I'm just explicitly specifying my size. If you don't set a size it will use whatever the input source size is
-acodec libfaac => use the faac AAC encoding library to transcode the audio

and finally the output file as the last parameter

You can get more specific too if you want, specifying how many passes of encoding you want (2 pass will be give you better compression with less artifacts), what your target bitrate is (maybe you want to limit your transcode to a certain amount of data so you can effectively stream it?).

Let me suggest you go to http://forum.doom9.org/ which is an excellent forum for more details on video encoding/transcoding. This other link http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs has other ffmpeg configurations that you may find useful.

Also a usable GUI for you to play with settings is http://handbrake.fr/ (handbrake) which is effectively an ffmpeg wrapper.

Handbrake bundles ffmpeg with its installation so I would get it from there. Be mindful of the licensing on ffmpeg/handbrake as they are distributed in france and I'm not sure you can distribute it with your application, but you may be able to use it server side. I'm always fuzzy on the legalities of this stuff.

I hope this at least points you in the right direction.

devshorts
  • 8,572
  • 4
  • 50
  • 73