Tuesday, April 20, 2010

AVCHD (Lite) iPhoto Importing

A few months ago I bought a Panasonic DMC-TS1 digital camera. One great thing about this camera is that it shoots 720p HD videos. They look amazing. The problem is that iPhoto does not recognize the HD video format (AVCHD) used by the camera.

iMovie is able to import the videos, but converts them to a much larger file format in the process.

I really like the ability to intermix my photos and videos within iPhoto and generate slideshows that include both. Most of the solutions on the internet that I've found require a lengthy re-encode, which also results in a quality loss.

Luckily, I came across a thread that describes a near perfect solution that is completely free! Rather than re-encode the H.264 video and AC3 audio used by the camera, you simply have to convert the file format from MTS to MP4 (or M4V as Apple likes to call it). The audio and video remain untouched during the conversion.

This can be done with a freeware command line utility called ffmpeg. The command format is extremely simple (and fast!):

./ffmpeg -i [INPUT].mts -acodec copy -vcodec copy [OUTPUT].m4v

For those that don't enjoy running things from the command line it is also possible to implement an Automator application to handle the conversion. I've modified the Automator application from the thread mentioned above to automatically set the time and date of the new file to match the original file. This optional step helps keep things easy when importing into iPhoto.

I have also bundled everything you need into an Automator app called "CovertToMp4", including ffmpeg and the command line utilities needed to modify the date/time of the new files. Beware, if you modify and save the application using Automator it will overwrite the ffmpeg and utility binaries in the bundle. Be sure to copy them out before you save!

To use the bundled application, first copy the "ConvertToMp4" application to your "Applications" directory (it won't work in any other directory as it needs absolute paths to find ffmpeg). Then drag and drop the MTS files you want to convert on top of the application icon. A m4v file of the same name will be generated. These m4v files can then be imported into iPhoto. I've found that dragging more than 5 or 6 at a time doesn't always work.

I usually create a directory on my Desktop and copy the MTS files from my camera to that directory before doing the conversion. On my camera the MTS files can be found in the /PRIVATE/AVCHD/BDMV/STREAM directory on the SD card.

I've only tested this on my iMac, so let me know if you have any problems getting it to run on your system.

One last thing... Quicktime does not natively support AC3 audio, so if your camera uses AC3 for audio you will need to install the a52codec or Perian (which includes additional a/v file formats and codecs using Quicktime).

27 comments:

  1. Thanks for this info. This was invaluable to me and pushed me over the edge to buy a digital camera that records in AVCHD since I knew I could organize my videos in iPhoto.

    Your Automater apps works great, but I want to be able to keep the ffmpeg binary up to date. Could you post the ./configure arguments you used to build ffmpeg?

    Also, when you ran make install, did you just copy the ffmpeg binary from somewhere like /usr/local or were you able to have the binary compiled into another directory?

    Many thanks.

    ReplyDelete
  2. Thank you so much for creating this automator application. You solved my importing/ conversion problems with my new camera. You are a genius!

    ReplyDelete
  3. Your a god! This utility works great

    ReplyDelete
  4. This is awesome. Why the heck doesn't Apple do this for us with iPhoto...

    ReplyDelete
  5. @Noel:
    I agree with you. Apple should do something about this.Asheville Used Motorcycles

    ReplyDelete
  6. Fantastic App with only a small problem for me. For me it doesn't update the date and time of the m4v file. When importing it to iphoto it has the time of a few secconds before when i converted it.
    Am I doing anything wrong?
    For two or three files it's not a big deal fixing that manually of course, but if I have let's say 100 videos I don't want to change every file manually.
    Thanks a lot!

    ReplyDelete
  7. I've installed the automator in my applications folder, and have tried to drag and drop an mts file on the automator icon. Nothing happens. What am I doing wrong?

    ReplyDelete
  8. HECFAA,

    Did you copy just the "ConvertToMp4" automator app into the applications folder? Not the included folder, just the app.

    ReplyDelete
  9. Not sure if anyone has the same problem, but Quicktime doesn't seem to load the Perian plugin all the time when the videos are accessed from iPhoto. I've got the same config as the author and its really odd when it occasionally plays the AC3 sound layer with a lot of digital noise. Video works without a hitch though. Anybody noticed that the sound volume seemed to drop as well?

    ReplyDelete
  10. I get the error message "The application ffmpeg has quit unexpectedly". Any ideas?

    ReplyDelete
  11. Thanks for the great app. It's incredible that iPhoto doesn't handle this AVCHD natively.

    I have a problem though. Some of the files I convert have audio that is all crackly static. The audio of the original AVCHD files is fine (or at least plays fine on my camera). Has anyone noticed the same thing? Is there a solution for it?

    ReplyDelete
  12. I gave the same problem with audio! Any help ?

    ReplyDelete
  13. For those who get the error message "The application ffmpeg has quit unexpectedly" download and try this version:
    http://bit.ly/jnFF20

    Download, unzip, and move ReWrap2M4V and ffmpeg to the Applications folder.

    Hope it works for you too.

    ReplyDelete
    Replies
    1. Hi, I've tried this file and method, and when I play the converted m4v files in QuickTime (after importing to iPhoto), I get no audio.

      I'm sure these files have audio, since you can hear it when you play back on the camera.

      Any ideas what I might be doing wrong? Thank you!!

      Delete
    2. Update: I read the last line on the post and downloaded Perian http://www.perian.org/ and now the audio works fine! Thank you for providing this service!!!

      Delete
  14. I am using Mac osx 10.6.8...ie the latest version.. on my macbook pro. Your convertor app no longer works. Is there an update? It used to work great.
    Appreciate your help.
    Thanks,
    Gerald

    ReplyDelete
  15. Oh, mam, I don't know how to thank you!
    You're genius and I love you :)

    :: Marta

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. I just tried installing "ReWrap2M4V and ffmpeg" & "A52Codec".

    It works fine w/ Mac OSX 10.6.8 except when the video gets to the end the sound was a bit broken then went into silence.

    So what is wrong?? The original files is prefect though~~


    Thx heaps again!!!!!!


    Gerald: Have a go at it see if u have the same prob??


    regards,
    Janice

    ReplyDelete
  19. Hi Jonathan,

    same happens in my case. Date and time seems to be gone and set to current date...have you figured out how to preserve original time and date?

    Thanks in advance,

    ReplyDelete
  20. Hi and thanks for making this script.

    FCP X still doesn't recognise the M4v. Any ideas for the simplest import workflow for AVCHD. Sony camera HSX9V

    ReplyDelete
  21. Hi. This app is really great!!!. My only problem is that the new file has the original created date but the modify date is the date of conversion. Any ideas to keep also the same modify date??

    ReplyDelete
  22. Add the option -copyts to the ffmpeg command line.

    ReplyDelete
  23. Just wanted to say again... this is awesome! Thank you for posting!

    ReplyDelete