Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

Video conversion script for Nokia N95 (and others)

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
10 posts • Page 1 of 1
Author
Message
meulie
l33t
l33t
User avatar
Posts: 845
Joined: Tue Jun 17, 2003 12:07 pm
Location: a Dutchman living in Norway
Contact:
Contact meulie
Website

Video conversion script for Nokia N95 (and others)

  • Quote

Post by meulie » Thu May 08, 2008 10:02 am

Hi all!

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

Code: Select all

#!/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
Top
kernelOfTruth
Watchman
Watchman
User avatar
Posts: 6111
Joined: Tue Dec 20, 2005 10:34 pm
Location: Vienna, Austria; Germany; hello world :)
Contact:
Contact kernelOfTruth
Website

  • Quote

Post by kernelOfTruth » Thu May 08, 2008 6:03 pm

*subscribes*

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

movies on the phone - here I come :D
https://github.com/kernelOfTruth/ZFS-fo ... scCD-4.9.0
https://github.com/kernelOfTruth/pulsea ... zer-ladspa

Hardcore Gentoo Linux user since 2004 :D
Top
micmac
l33t
l33t
Posts: 996
Joined: Fri Nov 28, 2003 8:38 pm

  • Quote

Post by micmac » Thu May 08, 2008 7:00 pm

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

Regards
mic
Top
alienvenom
Tux's lil' helper
Tux's lil' helper
Posts: 123
Joined: Wed Jan 12, 2005 8:00 pm
Location: San Francisco, CA
Contact:
Contact alienvenom
Website

  • Quote

Post by alienvenom » Fri May 09, 2008 12:33 am

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: Select all

#! /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?
Top
predatorfreak
l33t
l33t
User avatar
Posts: 708
Joined: Thu Jan 13, 2005 2:15 am
Location: USA, Michigan.
Contact:
Contact predatorfreak
Website

  • Quote

Post by predatorfreak » Fri May 09, 2008 1:27 am

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.
Top
alienvenom
Tux's lil' helper
Tux's lil' helper
Posts: 123
Joined: Wed Jan 12, 2005 8:00 pm
Location: San Francisco, CA
Contact:
Contact alienvenom
Website

  • Quote

Post by alienvenom » Fri May 09, 2008 1:34 am

N95 does NOT support XVID. It supports MPEG-4 AVC (h264).
Top
yngwin
Retired Dev
Retired Dev
User avatar
Posts: 4572
Joined: Thu Dec 19, 2002 1:22 pm
Location: Suzhou, China

  • Quote

Post by yngwin » Fri May 09, 2008 8:17 pm

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
Top
slackline
Veteran
Veteran
User avatar
Posts: 1479
Joined: Fri Apr 01, 2005 7:22 pm
Location: /uk/sheffield
Contact:
Contact slackline
Website

  • Quote

Post by slackline » Fri Aug 01, 2008 8:22 am

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: Select all

#! /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
Top
DeepBass909
Tux's lil' helper
Tux's lil' helper
Posts: 81
Joined: Sun Jan 23, 2005 9:32 pm
Location: Netherlands
Contact:
Contact DeepBass909
Website

  • Quote

Post by DeepBass909 » Tue Aug 19, 2008 9:42 pm

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: Select all

#! /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...
Top
slackline
Veteran
Veteran
User avatar
Posts: 1479
Joined: Fri Apr 01, 2005 7:22 pm
Location: /uk/sheffield
Contact:
Contact slackline
Website

  • Quote

Post by slackline » Wed Aug 20, 2008 6:17 am

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
Top
Post Reply

10 posts • Page 1 of 1

Return to “Unsupported Software”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic