Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Video conversion script for Nokia N95 (and others)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
meulie
l33t
l33t


Joined: 17 Jun 2003
Posts: 845
Location: a Dutchman living in Norway

PostPosted: Thu May 08, 2008 10:02 am    Post subject: Video conversion script for Nokia N95 (and others) Reply with quote

Hi all!

This is the script I use to convert AVI files to MP4 for viewing on my Nokia N95:
Code:

#!/usr/bin/ruby -w
#
# Copyright (C) 2007 Thomer M. Gil [http://thomer.com/]
# Thanks to Brian Moore for bugfixes.
#
# This program is free software. You may distribute it under the terms of
# the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# This program converts video files to mp4, suitable to be played on an Nokia N95.
# It is careful about maintaining the proper aspect ratio.
#

require 'getoptlong'

DEFAULT_ARGS = "-f mp4 -vcodec libxvid -maxrate 1000 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec mpeg4aac"
DEFAULT_AUDIO_BITRATE = 96
DEFAULT_VIDEO_BITRATE = 768
WIDTH = 320.0
HEIGHT = 240.0

$options = {}
opts = GetoptLong.new(
  [ "-a", GetoptLong::REQUIRED_ARGUMENT ],      # audio bitrate
  [ "-h", GetoptLong::NO_ARGUMENT ],            # help
  [ "-b", GetoptLong::REQUIRED_ARGUMENT ],      # video bitrate
  [ "-v", GetoptLong::NO_ARGUMENT ]             # verbose
)
opts.each { |opt, arg| $options[opt] = arg }

if $options['-h']
  puts <<EOF
mp4ize - encode videos to mp4 for an iPod

Usage: mp4ize file1.avi [file2.mpg [file3.asf [...]]]


Options:

  -h       : this help
  -v       : verbose
  -a RATE  : override default audio bitrate (#{DEFAULT_AUDIO_BITRATE})
  -b RATE  : override default video bitrate (#{DEFAULT_VIDEO_BITRATE})
EOF
  exit
end

audio_bitrate = $options['-a'] || DEFAULT_AUDIO_BITRATE
video_bitrate = $options['-b'] || DEFAULT_VIDEO_BITRATE

ARGV.each do |infile|
  outfile = infile.dup
  ext = File.extname(outfile)
  outfile.sub!(/#{ext}$/, '.mp4')

  # open the file to figure out the aspect ratio
  w, h = nil, nil
  IO.popen("ffmpeg -i '#{infile}' 2>&1") do |pipe|
    pipe.each_line do |line|
      puts line
      if line.match(/Video:.+ (\d+)x(\d+)/)
        w, h = $1.to_f, $2.to_f
      end
    end
  end

  begin
    aspect = w/h
  rescue
    puts "Couldn't figure out aspect ratio."
    exit
  end

  height = (WIDTH / aspect.to_f).to_i
  height -= 1 if height % 2 == 1
  pad = ((HEIGHT - height.to_f) / 2.0).to_i
  pad -= 1 if pad % 2 == 1

  File.unlink(outfile) if File.exists?(outfile)
  cmd = "ffmpeg #{DEFAULT_ARGS} -i '#{infile}' -s #{WIDTH.to_i}x#{height} -padtop #{pad} -padbottom #{pad} -ab #{audio_bitrate} -b #{video_bitrate} '#{outfile}'"
  puts cmd if $options['-v']
  system cmd
end


It's probably not perfect (the original was written for some fruit-product that shows video's...), so I've posted it here in the hope that there are perhaps other people here with suggestions for improvements... 8)
_________________
Greetz,
Evert Meulie
Back to top
View user's profile Send private message
kernelOfTruth
Watchman
Watchman


Joined: 20 Dec 2005
Posts: 5678
Location: Vienna, Austria; Germany; hello world :)

PostPosted: Thu May 08, 2008 6:03 pm    Post subject: Reply with quote

*subscribes*

I haven't tried this script out but I'm already loving it now :)

movies on the phone - here I come :D
_________________
Unofficial minimal livecd x86/amd64 w/reiser4+truecrypt (by Neo2)
2.6.37.2_plus_v1: BFS, CFS,THP,compaction, zcache or TOI
Hardcore Linux user since 2004 :D
Back to top
View user's profile Send private message
micmac
l33t
l33t


Joined: 28 Nov 2003
Posts: 989

PostPosted: Thu May 08, 2008 7:00 pm    Post subject: Reply with quote

Don't know about the Nokias, but you could give THIS a shot as well and post if it works for you.

Regards
mic
Back to top
View user's profile Send private message
alienvenom
Tux's lil' helper
Tux's lil' helper


Joined: 12 Jan 2005
Posts: 123
Location: San Francisco, CA

PostPosted: Fri May 09, 2008 12:33 am    Post subject: Reply with quote

This script sucks. It uses ruby... WTF?

Here's a simple bash script that doesn't require *yet another* language interpreter.

**anyway**

From: http://ubuntuforums.org/showthread.php?t=497848

Code:
#! /bin/bash
clear
if [ -n "$1"]; then
   echo "please specify file to convert"
   
else

   if [ -n "$2"]; then
      newName=$(echo $1 | cut -d '.' -f1)
   
   else
      newName=$2
   fi

   echo "coverting $1 to $newName.mp4"

   ffmpeg -i "$1" -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320x240 -acodec aac -ar 24000 -ab 64 -ac 2 "$newName.mp4"

fi


Also, does the N95 do XVID native? Why are you using XVID?
Back to top
View user's profile Send private message
predatorfreak
l33t
l33t


Joined: 13 Jan 2005
Posts: 708
Location: USA, Michigan.

PostPosted: Fri May 09, 2008 1:27 am    Post subject: Reply with quote

alienvenom wrote:
Also, does the N95 do XVID native? Why are you using XVID?


XVID IS MPEG-4, it's just a different implementation. Some like XVID over libavcodec MPEG-4. I prefer libavcodec MPEG-4.
_________________
System: predatorbox
Distro: Arch Linux x86_64
Current projects: blackhole, convmedia and anything else I cook up.
Back to top
View user's profile Send private message
alienvenom
Tux's lil' helper
Tux's lil' helper


Joined: 12 Jan 2005
Posts: 123
Location: San Francisco, CA

PostPosted: Fri May 09, 2008 1:34 am    Post subject: Reply with quote

N95 does NOT support XVID. It supports MPEG-4 AVC (h264).
Back to top
View user's profile Send private message
yngwin
Developer
Developer


Joined: 19 Dec 2002
Posts: 4394
Location: Suzhou, China

PostPosted: Fri May 09, 2008 8:17 pm    Post subject: Reply with quote

It actually seems to support both.
_________________
"Those who deny freedom to others deserve it not for themselves." - Abraham Lincoln
Free Culture | Defective by Design | EFF
Back to top
View user's profile Send private message
slackline
Veteran
Veteran


Joined: 01 Apr 2005
Posts: 1316
Location: /uk/sheffield

PostPosted: Fri Aug 01, 2008 8:22 am    Post subject: Reply with quote

alienvenom wrote:
This script sucks. It uses ruby... WTF?

Here's a simple bash script that doesn't require *yet another* language interpreter.

**anyway**

From: http://ubuntuforums.org/showthread.php?t=497848

Code:
#! /bin/bash
clear
if [ -n "$1"]; then
   echo "please specify file to convert"
   
else

   if [ -n "$2"]; then
      newName=$(echo $1 | cut -d '.' -f1)
   
   else
      newName=$2
   fi

   echo "coverting $1 to $newName.mp4"

   ffmpeg -i "$1" -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320x240 -acodec aac -ar 24000 -ab 64 -ac 2 "$newName.mp4"

fi


Also, does the N95 do XVID native? Why are you using XVID?


Just tried out this script and '-acodec aac' results in an error 'Unknown codec aac' despite ffmpeg being built with USE="aac". If you chance this to '-acodec libfaac' then the script works fine.

slack
_________________
"Science is what we understand well enough to explain to a computer.  Art is everything else we do." - Donald Knuth
Back to top
View user's profile Send private message
DeepBass909
Tux's lil' helper
Tux's lil' helper


Joined: 23 Jan 2005
Posts: 81
Location: Netherlands

PostPosted: Tue Aug 19, 2008 9:42 pm    Post subject: Reply with quote

slack---line wrote:
alienvenom wrote:
This script sucks. It uses ruby... WTF?

Here's a simple bash script that doesn't require *yet another* language interpreter.

**anyway**

From: http://ubuntuforums.org/showthread.php?t=497848

Code:
#! /bin/bash
clear
if [ -n "$1"]; then
   echo "please specify file to convert"
   
else

   if [ -n "$2"]; then
      newName=$(echo $1 | cut -d '.' -f1)
   
   else
      newName=$2
   fi

   echo "coverting $1 to $newName.mp4"

   ffmpeg -i "$1" -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320x240 -acodec aac -ar 24000 -ab 64 -ac 2 "$newName.mp4"

fi


Also, does the N95 do XVID native? Why are you using XVID?


Just tried out this script and '-acodec aac' results in an error 'Unknown codec aac' despite ffmpeg being built with USE="aac". If you chance this to '-acodec libfaac' then the script works fine.

slack


You need to replace "aac" with "libfaac", then it works.

I'm now converting my first trail video with the cmd-line of the bash-script for my Nokia N78. So far I had no luck with converting into a working version...
Back to top
View user's profile Send private message
slackline
Veteran
Veteran


Joined: 01 Apr 2005
Posts: 1316
Location: /uk/sheffield

PostPosted: Wed Aug 20, 2008 6:17 am    Post subject: Reply with quote

DeepBass909 wrote:
slack---line wrote:

If you change this to '-acodec libfaac' then the script works fine.

slack


You need to replace "aac" with "libfaac", then it works.


:wink:
_________________
"Science is what we understand well enough to explain to a computer.  Art is everything else we do." - Donald Knuth
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum