Editing AVCHD in Linux

Almost every inexpensive high definition camcorder sold today uses AVCHD to encode and store its video. This document describes how to edit AVCHD source with Cinelerra and create high definition BD5, BD9 and Blu-ray disks. Our approach is similar to HDV 1080i editing using proxy files by Herman Vosseler. The workflow has been tested with sample source from a Canon HG10 camcorder. A method for lossless cut and paste editing of AVCHD source in described in Lossless AVCHD Editing in Linux.

Needed Software

This method relies on open source software on Linux

Capture

Plug the camcorder into a usb port, mount it as a usb storage device and copy the m2ts files. Quick transfer of the video source to the computer is the the main advantage AVCHD camcorders. However, transcoding AVCHD into an editable format may be slower than capturing an HDV tape.

Proxy Files

Proxy files make editing operations faster and can be used to create DVDs to preview your work. Create standard definition mjpeg Quicktime proxy files for each of your m2ts source files with
$ ffmpeg -i s001.m2ts -r 30000/1001 -acodec pcm_s16le -vcodec mjpeg \
    -interlace 0 -deinterlace -s 720x480 -aspect 3:2 -y s001.mov
The version of ffmpeg used here includes patches for the -interlace 0 flag. These patches are available from DVD compliant mpeg2 on Linux. If you perfer not to compile ffmpeg yourself omit the -interlace 0 flag from the above command.

Note the display aspect of -aspect 3:2 is wrong but necessary because Cinelerra requires the pixel aspect ratio to be square to read the file. The display aspect ratio that Cinelerra actually uses for editing is defined explicity in format preferences under settings.

Load the proxy files into Cinelerra's timeline and edit. Smart render jpeg Quicktime to create standard definition previews of your work. If desired, convert the Quicktime output to DVD compliant mpeg2 and create a standard definition DVD. When you are done save the editing project and quit Cinelerra.

Intermediate Format

Cinelerra can not import AVCHD files directly on the timeline, therefore we transcode AVCHD to mpeg2 before rendering it. Do this with
$ ffmpeg -i s001.m2ts -r 30000/1001 -acodec mp2 -vcodec mpeg2video \
    -interlace 1 -top 1 -flags +ildct+ilme \
    -ab 384k -b 24000k -f mpegts -y s001.m2t
$ mpeg3toc s001.m2t s001.toc
Increase the bitrate to -ab 448k -b 34000k or greater for better quality.

Again the -interlace 1 and -top 1 flags are only available using the patched version of ffmpeg available from DVD complaint mpeg2 on Linux. These flags may be omitted with only minor loss in quality.

Final Rendering

Make a copy of the xml project file created by Cinelerra. Replace s001.mov with s001.toc and replace Quicktime for Linux with MPEG in the copy of the xml project file. Start Cinelerra, set the format to 1440x1080 and resize the tracks. Now render the project using the script pipe-x264 and burn it to BD5 as described in H264 HD Video Workflow.

Further Notes

The creation of the high definition mpeg2 files from AVCHD source runs at about 15 frames per second on my computer. This means transcoding AVCHD to a format Cinelerra can edit is slower than capturing HDV from tape. AVCHD source can be losslessly authored to BD5 with reencoding necessary only for rendered effects and transitions. Therefore a workflow with essentially zero transcoding is possible. See Lossless AVCHD Editing in Linux for more information about such a workflow. If done properly, zero transcoding also implies a quick workflow that retains the advantages of the fast download of AVCHD source.

If Cinelerra could decode AVCHD the same way it can decode HDV source, then a direct AVCHD to h264 transcode would be possible. Rendering the entire project with a multi-pass variable bitrate encoder can create a noticably more efficient video stream than the original AVCHD source. Moreover, it is easier to ensure such an encode will meet the requirements for playback in Blu-ray players.

Kdenlive can decode AVCHD and renders h264 using libx264 through ffmpeg. However, the resulting video stream may not include nal hrd packets. I've heard tsmuxer creates them when multiplexing blu-ray, but I see no way to specify the field order. The only alternative seems to be rendering to an intermediate format and then reencoding with x264 for burning to a BD5 or BD9 disk.

The current workflow transcodes the AVCHD source twice. The main drawback of this workflow is the additional time necessary to create the intermediate format. If quality is impacted increase the bitrate for the intermediate format to 34000k or more.


Last Updated: Sun Mar 27 22:07:55 PDT 2011