Transcode to iphone friendly format

cmisip

Joined: 2011-02-20
Posts: 22
Posted: Sat, 2011-03-12 13:39

I needed to be able to upload my AVCHD videos from my sony vixia and have the videos playable on my iphone so I created
a few patches to make this work. Use these patches at your own risk.

I created a patch for transcode that adds the following features:
select mp4 or flv output
select local (server side encoding), remote (via ssh and nfs ) encoding or create bash script for local and remote encoding
qt-faststart (for mp4 files only)
2 pass encoding
vpre fastfirstpass, hq and iphone presets hardcoded from rodrigopolo.com
create iphone compatible 320p video (if source video has enough resolution as there is no upscaling)
change flowplayer call in transcode view page to support the ipad plugin

PreSetup:

>>>Setup remote encoding:
1. You need to have the same absolute path to the gallery save directory on both local and remote machines
For example: local = mymainserver.chris.net, remote =myxps8100.chris.net
I use a symlink from /usr/share/gallery3/
ln -sf /mnt/BACKUP/GALLERY /usr/share/gallery3/var
Then nfs export that in /etc/exports
/mnt/BACKUP/GALLERY myxps8100.chris.net(rw)
Then on the remote machine's /etc/fstab
mymainserver.chris.net:/mnt/BACKUP/GALLERY /mnt/BACKUP/GALLERY nfs rw,soft,user 0 0
** Make sure that the gallery var directory is writeable by the apache user in both the local and remote machines. This means
that they have the same uid/gid on both systems. The remote system especially needs a writeable directory for the ffmpeg 2 pass log files so I setup
mine to have /home/apache (as ssh defaults to this ) and /bin/bash shell. You also need a place for .ssh
2. Passwordless ssh needs to be setup for the apache user to the remote machine.

3. Then you can run the generated run.sh script in /usr/share/gallery3/var/modules/transcode/script/run.sh as the local apache user

>>>Setup Gallery and flowplayer for iphone playback

Follow the instructions in this thread

http://gallery.menalto.com/node/101033

>>> Setup Gallery to allow unsupported videos to be imported
>>> Setup the videos module and the server add module to include the .m2ts extension in the list of browseable files

>>> Install transcode module version 10

>>> Optionally install videos module

To apply these patches. Just create a patches directory in the gallery root dir and save the patches there. You can skip the videos patches
if you are not using that module. Then you can copy and paste the following on to the running terminal:

echo "---------Applying gallery/models/item.php patch to remove flv and mp4 restriction"
patch --no-backup-if-mismatch -p1 < patches/modules.gallery.models.item-flvmp4restrictionremove.patch

echo "---------Applying videos module patch to allow m2ts files"
patch --no-backup-if-mismatch -p1 < patches/videos.allow-m2ts-extension.patch

echo "---------Applying videos module patch to allow iphone playback on videos view page"
patch --no-backup-if-mismatch -p1 < patches/videos.flowplayer-iphone.patch

echo "---------Applying server_add m2ts patch"
patch --no-backup-if-mismatch -p1 < patches/server_add.addm2ts.patch

echo "---------Applying transcode patch"
patch --no-backup-if-mismatch -p1 < patches/transcode.full.mp4.patch

Post Setup:

To setup the admin transcode page:

1. You need to have at least -vcodec libx264 in the extra ffmpeg flags field. I use:
-strict experimental -deinterlace -vcodec libx264
This is where the vcodec is specified so the run script will fail without this. This project is not done for me yet so I haven't hardcoded it.

2. If you want to encode via remote or remote-script, the remote user and remote machine is mandatory although, the settings will be saved
without any warning. Maybe somebody can write code to check for this.

3. As stated in the admin page, selecting the iphone compatible mode, changes the output format to mp4 and selects the 320p resolution although
the resolution may not be exactly 320p as the video height is calculated keeping in mind that the full width of the video must fit the 480 pixel limit. The iphone
3gs with iOS 4 does not need videos to be padded.

4. Setting qt-faststart in the admin page has no effect in the encoding process unless output mode is mp4 although it will not tell you this.

5. If you simply want to import a properly formatted video with no transcoding, just unselect all of the resolutions including the iphone compatible mode.

6. If you are using remote and remote-script, make sure the remote machine has ffmpeg and qt-faststart in the same paths as local machine as the admin page
only checks for local paths.

Issues:
1. On very large files, server add module creates multiple copies of the video with a unique extension to each copy. I think this is an issue
with latency from copying large files. This issue shows up as well if you have local transcode process running with a smaller video file as the
transcode process further adds to the latency. Using the script or remote-script encoding mode alleviates this for the most part. Just check
the run.sh that is generated and make edits as needed or if you have the time and the cpu, just delete the duplicate videos in gallery.

2. If the source file resolution is not large enough, you may not be able to transcode to the resolutions you selected as there is no upscaling in the code.

I have not tested much the flv side of the module as I am primarily using mp4 so hopefully I did not break anything. I maintained the original video bitrates for
flvs but I increased the audio bitrates and used the hardcoded vpre's. So hopefully, the flv side is not far from what the original author intended.

Hopefully, this works for you guys. So far it seems to be working in my setup. I am not a php programmer but I have access to google so sorry if the code
seems amateurish.

danneh3826 is the author of the transcode module. There is no way I could have come up with something like this from scratch.
I used the encoding presets from rodrigopolo.com.

Improvements and patches welcome.

Incidentally, if you are interested in iphone related stuff in gallery, you can install jaipho as an alternative to the flash based cooliris slideshow viewer following the instructions here:

http://gallery.menalto.com/node/101012

Now if somebody can write an iphone friendly UI.

Have fun.
Chris

3/26/10
Updated: Increase bitrates for mp4 encoding and adjust the iphone preset and resolution.

AttachmentSize
modules.gallery.models.item-flvmp4restrictionremove.patch_.gz568 bytes
server_add.addm2ts.patch_.gz619 bytes
videos.allow-m2ts-extension.patch_.gz426 bytes
transcode.full_.mp4_.patch_.gz6.37 KB