Motion - Convert To 3gp

Script that converts your avi files into 3gp files

Introduction

Ever wanted to connect with your mobile phone to motion and download the latest movies? This script makes it possible. It converts every finished movie made by motion into a 3gp video file. Basically any compatible device will be able to view the created files. Phones, PDAs etc. The script makes use of the onffmpegclose option in motion.conf and converts movies using ffmpeg

Code

#!/usr/bin/python
import os
from os import system,path,unlink
from sys import argv
outpath="/home/sites/motion/web/3gp"   # destination of the converted files
outbps=6      # kbits per second
outfps=6      # frames per second

def to3gp(infile, outfile, bps, fps):

   ffmpeg="ffmpeg -i %s -r %d -s qcif -b %d -an -map 0.0 -f 3gp %s </dev/null"
   system(ffmpeg % (infile, fps, bps, outfile))

def insert_avi(infile):
   basename=path.basename(infile)
   pos=basename.rfind('.')
   if pos==-1:
      label=basename
      basename=basename+".3gp"
   else:
      label=basename[:pos]
      basename=label+".3gp"
   outfile=path.join(outpath,basename)
   to3gp(infile, outfile, outbps, outfps);

insert_avi(argv[1])

Download

Download script: convert_to_3gp.py

Installation

What do you need to install before?

ffmpeg is needed by the script apache o compatible browser is needed to connect via wap or browser to the specified directory

How do you install the program?

Copy the file to a folder, edit options in the script (file location, quality) and add the command line to 'onffmpegclose' option in motion.conf (something like onffmpegclose /usr/local/bin/convert_to_3gp.py)

To download the file directly with your cell phone, you should add the following code in your apache httpd.conf to allow directory listing.

<Files /the_directory_you_specified_in_convert_to_3gp.py/>
  order allow,deny
  allow from all
  Options Indexes
</Files>

In my case, i also had to add a mime type for 3gp movies in my mime.types configuration of apache. Without it, my movies wouldn't be recognised by my phone.
video/3gp                                       3gp
I think that's all. Have fun!

Comments and Bug Reports

Thanks go to Gabriel for writing that little script, and Mike Lees for making the code even shorter.

This script is stable. No future versions expected. Feel free to edit and improve.

Tested phones:

Nokia 6230, 6600

-- PatrickWagner - 03 Apr 2005


As of Motion 3.2.3 the motion.conf syntax is:

on_movie_end /usr/local/bin/convert_to_3gp.py

As of Motion 3.2.4_snap4 the %f paramater must be added to above command:

on_movie_end /usr/local/bin/convert_to_3gp.py %f

-- GordonCompton - 05 Nov 2005

I am using motion Version 3.2.7 on Fedora Core 7. When I add the above line to the config file it will only execute the script if i stop the motion service. The same is true if I have motion running in non-deamon mode, I have to -c and stop motion, only then will the script run.

Any Ideas as to why this happens?.

-- JohnPowell - 06 Apr 2008

RelatedProjectsForm edit

ProjectSummary Tiny Python script to convert your avi files to 3gp, viewable on a wide range of mobile phones and PDA's
ProjectStatus Inactive
ReleaseVersion
ProjectSubmitter PatrickWagner
Topic revision: r10 - 06 Apr 2008, JohnPowell
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.