«

»

Aug 14

Capture and convert live AVCHD output to MP4

Capture and create MP4 from live AVCHD video camcorder using ffmpeg. This is an example using the AVCHD input from a SONY or PANASONIC HD camera on Windows. I use cygwin so I can create pipes or automate things in Windows. I use ffmpeg.exe to grab the video from the camera and convert/re-encode to other formats and containers, as desired.

The firs step is to find the name of your video camcorder:

./ffmpeg.exe -list_devices true -f dshow -i dummy

This creates a lot of output, but the entries of interest start with the word ‘dshow’ and since we want at least one audio device and one video device, preferably (but not necessarily required to be) the same device, we use these two:

[dshow @ 0000000004d8bea0]  “HX-WA2″ 

[dshow @ 0000000004d8bea0]  “Microphone (HX-WA2)”

Next, grab the MTS format input, convert to an FLV format stream, then convert the FLV stream to MP4 – all in one command and all real-time:

./ffmpeg.exe -f dshow -r 20 -i video”=HX-WA2″:audio=”Microphone (HX-WA2)” -y -r 20 -pix_fmt yuv420p -vcodec libx264 -b:v 1.5M -b:a 192k -f flv – | ./ffmpeg -f flv -i – -y -c copy -copyts filename.mp4

I had to tweak my command above because the video and audio were about a second out of sync.  Depending on whether the video is ahead or behind, the offset will be either a negative or positive value.  In my case I needed a negative offset of 1 second, and the video and audio were perfect!  The only caveat of recording with an offset is that the first couple of seconds were jumbled and out of sync. That is okay, I just need to start recording a couple of seconds before any needed content:

./ffmpeg.exe -f dshow -r 20 -itsoffest -00:00:01 -i video”=HX-WA2″:audio=”Microphone (HX-WA2)” -y -r 20 -pix_fmt yuv420p -vcodec libx264 -b:v 1.5M -b:a 192k -f flv – | ./ffmpeg -f flv -i – -y -c copy -copyts filename.mp4

 

Leave a Reply