Page 1 of 5 123 ... LastLast
Results 1 to 10 of 45

Thread: Script to create android (480x320) compatible mp4 video using ffmpeg

  1. #1
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Script to create android (480x320) compatible mp4 video using ffmpeg

    If you're interested I created a python script to create compatible mp4 video for android G1/Dream/Hero from any video file using ffmpeg. It will figure out the padding top and bottom to fit the screen and keep the original video aspect ratio, see attached. To install and use:

    To install:
    1. save attached file to /tmp/
    2. put the file into a folder in your PATH, in this case /usr/bin: "sudo cp /tmp/android-video.py /usr/bin"
    3. give the file exec rights: "sudo chmod +x /usr/bin/android-video.py"
    4. install ffmpeg with mp4 etc support, try using the following (works for Jaunty and Intrepid):
      Code:
      sudo apt-get install ffmpeg ubuntu-restricted-extras
      A full set of methods can be found in this thread: HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg


    To use:
    1. go to the terminal and cd to the directory where video exists
    2. run "android-video.py videofile1 videofile2..."
    3. new gnome-terminals will be spawned for each video conversion required
    4. New files with the same name as originals will be created but with a .mp4 extension added


    Note: you'll need ffmpeg installed...

    If you want to change the video conversion settings they are all set at the top of the script as follows:

    Code:
    TEMP_INFO_PATH = "/tmp/android-video.info"
    TARGET_VIDEO_WIDTH = 480
    TARGET_VIDEO_HEIGHT = 320
    TARGET_AUDIO_CHANNELS = 2
    TARGET_AUDIO_SAMPLING_RATE = 16000
    TARGET_AUDIO_BIT_RATE = 64000
    TARGET_FRAME_RATE = 23.976
    TARGET_VIDEO_BIT_RATE = 500000
    NO_PADDING = False
    In theory it could be used for future devices with other screen sizes and requirements...

    Hope you find it useful..I do

    Edit: I've updated the script to handle input video aspect ratio's lower than what the android offers, this will result in left and right padding of the output video rather than the usual top and bottom padding as seen with modern day films.
    Attached Files Attached Files
    Last edited by kaivalagi; November 6th, 2009 at 01:10 PM. Reason: updated script to fix "odd"ities

  2. #2
    Join Date
    Sep 2006
    Beans
    3,529

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    FFmpeg from the repository will need restricted encoders, such as mpeg4 and libfaac, to be enabled:

    HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg

  3. #3
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    Quote Originally Posted by FakeOutdoorsman View Post
    FFmpeg from the repository will need restricted encoders, such as mpeg4 and libfaac, to be enabled:

    HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg
    I can't recall compiling ffmpeg before now, I think I am using the one from the standard repos just fine...I'll take a look though, thanks for the heads up.

    Edit: The below looks likely though (thanks for the ffmpeg thread link!):

    Code:
    sudo apt-get install ffmpeg ubuntu-restricted-extras
    Last edited by kaivalagi; August 18th, 2009 at 07:43 PM.

  4. #4
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Script update

    I've updated the script to handle input video aspect ratio's lower than what the android offers, this will result in left and right padding of the output video rather than the usual top and bottom padding as seen with modern day films.

    New script attached to the first post

  5. #5
    Join Date
    Feb 2006
    Location
    Moshi, Tanzania
    Beans
    805
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    Awesome, works wonders.

    I confirm that this works with any need for compilation or whatnot, the command-line provided is the only thing you need to make it work (tested on Jaunty, playback on my new HTC Hero ).

    Small tip: instead of installing the script to /usr/bin, I like to create a ~/bin folder, and put it here. This way it's automagically in my PATH without making it available to other users. You might need to logout/login again for this to work (adding ~/bin to the path is done on login by the ~/.profile script).

    Thanks a lot!

    - Trib'

  6. #6
    Join Date
    Sep 2006
    Beans
    3,529

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    Quote Originally Posted by kaivalagi View Post
    I can't recall compiling ffmpeg before now, I think I am using the one from the standard repos just fine...I'll take a look though, thanks for the heads up.

    Edit: The below looks likely though (thanks for the ffmpeg thread link!):

    Code:
    sudo apt-get install ffmpeg ubuntu-restricted-extras
    Compiling FFmpeg is just one option to enable restricted encoders. You can also install ubuntu-restricted-extras as you pointed out, but I prefer to recommend installing libavcodec-unstripped-51 (Intrepid) or libavcodec-unstripped-52 (Jaunty) which is what you really need if you want to use the repository FFmpeg. The ubuntu-restricted-extras metapackage automatically includes these packages, but it also installs a bunch of other packages and I think it is a little bloated.

  7. #7
    Join Date
    Jan 2007
    Location
    Manchester, UK
    Beans
    10
    Distro
    Hardy Heron (Ubuntu Development)

    Talking Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    Hello

    Just a quick message to say thanks for this script, i have installed as a Nautilus script so that i can just right click the avi choose scripts and then android-video.py and it works perfectly

    thanks again

  8. #8
    Join Date
    Jul 2007
    Beans
    1

    Unhappy Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    i cant get this to work


    ************************************************** *****
    * android-video.py *
    * Description: Converts any video to MP4 suitable for *
    * viewing on Google Android (480x320) *
    * Author: Kaivalagi *
    * Created: 2009-08-16 *
    ************************************************** *****

    ****************************
    * PROCESSING: /home/ts/zzz
    ****************************

    *** Retrieving file info from ffmpeg using this:
    ffmpeg -i '/home/ts/too' 2> /tmp/android-video.info.328db59e-a17e-11de-9f26-0030056aa91e

    *** ERROR: input width and height were not found/used - bug in code needs fixing...!!!
    *** ERROR: Failed to process input file:
    /home/ts/zzz

    Traceback (most recent call last):
    File "/usr/bin/android-video.py", line 150, in <module>
    requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding = getPadding(inputwidth, inputheight)
    File "/usr/bin/android-video.py", line 106, in getPadding
    return requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding
    UnboundLocalError: local variable 'requiredwidth' referenced before assignment

    *******************************
    * PROCESSING: /home/ts/zzz *
    *******************************

    *** Retrieving file info from ffmpeg using this:
    ffmpeg -i '/home/ts/Smooth' 2> /tmp/android-video.info.328db59f-a17e-11de-9f26-0030056aa91e

    *** ERROR: input width and height were not found/used - bug in code needs fixing...!!!
    *** ERROR: Failed to process input file:
    /home/ts/zzzz

    Traceback (most recent call last):
    File "/usr/bin/android-video.py", line 150, in <module>
    requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding = getPadding(inputwidth, inputheight)
    File "/usr/bin/android-video.py", line 106, in getPadding
    return requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding
    UnboundLocalError: local variable 'requiredwidth' referenced before assignment

    *******************************
    * PROCESSING: /home/ts/zzz *
    *******************************

    *** Retrieving file info from ffmpeg using this:
    ffmpeg -i '/home/ts/[DivX]' 2> /tmp/android-video.info.328db5a0-a17e-11de-9f26-0030056aa91e

    *** ERROR: input width and height were not found/used - bug in code needs fixing...!!!
    *** ERROR: Failed to process input file:
    /home/ts/[zzz]

    Traceback (most recent call last):
    File "/usr/bin/android-video.py", line 150, in <module>
    requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding = getPadding(inputwidth, inputheight)
    File "/usr/bin/android-video.py", line 106, in getPadding
    return requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding
    UnboundLocalError: local variable 'requiredwidth' referenced before assignment

    ***********************************
    * PROCESSING: /home/ts/dvdrip.avi *
    ***********************************

    *** Retrieving file info from ffmpeg using this:
    ffmpeg -i '/home/ts/dvdrip.avi' 2> /tmp/android-video.info.328db5a1-a17e-11de-9f26-0030056aa91e

    *** ERROR: input width and height were not found/used - bug in code needs fixing...!!!
    *** ERROR: Failed to process input file:
    /home/ts/dvdrip.avi

    Traceback (most recent call last):
    File "/usr/bin/android-video.py", line 150, in <module>
    requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding = getPadding(inputwidth, inputheight)
    File "/usr/bin/android-video.py", line 106, in getPadding
    return requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding
    UnboundLocalError: local variable 'requiredwidth' referenced before assignment

    **************************
    * PROCESSING: /home/ts/1 *
    **************************

    *** Retrieving file info from ffmpeg using this:
    ffmpeg -i '/home/ts/1' 2> /tmp/android-video.info.328db5a2-a17e-11de-9f26-0030056aa91e

    *** ERROR: input width and height were not found/used - bug in code needs fixing...!!!
    *** ERROR: Failed to process input file:
    /home/ts/1

    Traceback (most recent call last):
    File "/usr/bin/android-video.py", line 150, in <module>
    requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding = getPadding(inputwidth, inputheight)
    File "/usr/bin/android-video.py", line 106, in getPadding
    return requiredwidth, requiredheight, top_padding, bottom_padding, left_padding, right_padding
    UnboundLocalError: local variable 'requiredwidth' referenced before assignment
    Last edited by tost_ts; September 14th, 2009 at 11:39 PM.

  9. #9
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    @tost_ts - do you actually have ffmpeg installed? e.g. run:

    Code:
    sudo apt-get install ffmpeg ubuntu-restricted-extras
    or compile and install, see the first post for info on this.

    It looks like my script is failing to get video dimensions which it does so using "ffmpeg -i <filepath>"

    Hope that helps

  10. #10
    Join Date
    Dec 2005
    Beans
    113

    Re: Script to create android (480x320) compatible mp4 video using ffmpeg

    Shouldn't the script be able to handle aspect-ratio separate from resolution? Widescreen DVB SD-recordings are stored in 720x576, even though they are targeting a 16:9 AR.

    Sample ffmpeg info from a SD-recording in mythtv:
    Code:
    Input #0, mpegts, from '2520_20090916000501.mpg':
      Duration: 00:41:30.06, start: 9431.566544, bitrate: 6443 kb/s
      Program 1 
        Stream #0.0[0x200]: Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR 16:9], 10000 kb/s, 25 tbr, 90k tbn, 50 tbc
        Stream #0.1[0x280](nor): Audio: mp2, 48000 Hz, stereo, s16, 256 kb/s
    There could be an option to use x264, although that adds another SW requirement. It may give slightly better video quality, at the cost of longer conversion time.

    Conversion-time could also be slightly improved by using ffmpegs -threads option on multi-core machines.

Page 1 of 5 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •