BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Linux Users Corner (http://www.blackberryforums.com/forumdisplay.php?f=83)
-   -   vid2bb.sh: using mencoder to create videos (http://www.blackberryforums.com/showthread.php?t=65660)

rivviepop 02-19-2007 01:51 PM

vid2bb.sh: using mencoder to create videos
 
Originally posted in the 8100 forum in the encoding thread; this is a little script I wrote based on the parameters they've worked out. It's worked great for me.

== snip ==

Getting the right params to mencoder to produce top quality video is always a chore, but using method 1 in the original post is working wonderfully for me -- I've converted all sorts of stuff (WMV/AVI/MPG/FLV/MOV) and so far only the FLV conversions have audio sync problems (nothing new). I'm even going to say that the videos look better (and run smoother!) on my Pearl than any S60 device I've used.

Stupid Bash Trick time -- here's a helper script, save it as "vid2bb.sh" somewhere in your $PATH on Linux/OSX. Make it executable then run with a simple "vid2bb.sh <FILE>" command, the output will be in the input directory.

Code:

#!/bin/bash

FILE=$1

## 8100, 240x260 res
## uncomment one of the below depending on your input format
#RES=240:135            # resolution, 16:9 ratio
RES=240:180            # resolution, 4:3 ratio

## 8800, 320x240 res
## uncomment one of the below depending on your input format
#RES=320:180            # resolution, 16:9 ratio
#RES=240:180            # resolution, 4:3 ratio

## generic
ABR=64                  # audio bitrate
VBR=230                # video bitrate

mencoder "$FILE" \
        -o "${FILE%.*}_bb.avi" \
        -of avi \
        -ovc lavc \
        -oac lavc \
        -lavcopts vcodec=mpeg4:vbitrate=$VBR:acodec=mp3:abitrate=$ABR \
        -vf scale=$RES

Note that the above takes the input filename, chops off the extension and adds a "_bb.avi" to the end of the output file to help you know which files are your BB ready ones. A quick sort, drag&drop and they're on your device.

My setup is Fedora Core 6 with the FreshRPMS mplayer builds installed (which grabs all the latest libavcodec and so on), as well as the Essential codecs pack (from the MPlayer website) unxipped to /usr/lib/win32/ -- these codecs always seem to produce better quality.

LunkHead 02-23-2007 06:33 PM

And one last sticky request please :)

indramilo 02-25-2007 11:07 AM

man... I love Linux Philosophy

and thanks for the code rivviepop :D

rivviepop 02-25-2007 03:56 PM

Quote:

Originally Posted by indramilo
and thanks for the code rivviepop :D

my pleasure! :) I'll tell you a little secret - I own [ bash-fu ] My professional life over the years as a systems engineer has given me ample opportunity to become one with the bourne. I thank my workplace and boss (who rocks) for allowing me to get nerdy on company time.

LunkHead 02-28-2007 09:48 PM

Well, no doubt you are the man rivvie... Love the info on you're site... It ROCKS!

erroneus 03-02-2007 10:05 AM

Yes, I have used this scriptlet many times. Here's a problem though... and I hope it can be addressed quickly (as in today) because I'll be flying to Japan tomorrow and will be there for two weeks. I'd like to watch a couple of full-length movies on my BB8100!

Here's the problem. I encoded two movies down to BB size but these are formatted for wide-screen display. What do I need to change to make it look right on my BB display? Right now, they come out squished up horizontally.

Okay... right now, I'm re-coding it... don't have the original files available to me at the moment... hope the quality stays good. I set the target aspect ratio to be wider... I have no idea how the BB will play it though...

Okay, I recoded two movies. I just set the RES from 240:180 to 240:120 and it looks much better now... no notable decrease in size and so no decrease in quality is expected.... looks pretty good so far. I can still read the subtitles so I'm good. :)

rivviepop 03-02-2007 01:26 PM

Quote:

Originally Posted by erroneus
because I'll be flying to Japan tomorrow

*jealous* Can I come? I'm super harajuku friendly. :)

Quote:

Here's the problem. I encoded two movies down to BB size but these are formatted for wide-screen display. What do I need to change to make it look right on my BB display? Right now, they come out squished up horizontally.
Ugh, never a fun problem; this is the dreaded 16:9 <=> 4:3 conversion problem (if I read/understand your post correctly). Help me out here -- are you saying the original movie is in 4:3 format and it's coming out 16:9, or the other way around? No, wait... ok this line:

RES=240:180

...is a 4:3 ratio. So, it sounds like you have a 16:9 movie -- what you want to do is adjust that ratio set to be 16:9, so maybe:

RES=240:135

...which is a 16:9 ratio exactly (well, exact as my little TI calculator can do :) ). I bet that'll get rid of your squishedness.

erroneus 03-02-2007 02:07 PM

Yeah, I decided to actually read the script and the answer seemed obvious. I didn't use a calculator like you did, so I didn't come up with a figure as exact. The proportions look good enough though. :)

rivviepop 03-02-2007 03:26 PM

Quote:

Originally Posted by erroneus
Yeah, I decided to actually read the script and the answer seemed obvious. I didn't use a calculator like you did, so I didn't come up with a figure as exact. The proportions look good enough though. :)

Cool cool, I just updated the scriptlet to clarify that, so maybe it'll help the next person who comes along. :)

rivviepop 03-03-2007 02:33 PM

I just added hopefully the correct res sizes for the 8800 (320x240) devices, I'm about to go troll the 8800 forum for a guinea pig. If you have an 8800 try it out and report back.

erroneus 03-04-2007 04:37 PM

I wonder if there's a way to add a command-line or two to determine the aspect ratio of the source video and simply either make a selection of aspect ratios or calculate the new, scaled down size for the target video file?

Well, I'm in Japan now and watching videos on the phone during the flight was pretty cool! Here's some tips! Disable the radio and bluetooth for impressive battery life. They want you to turn those things off during flight anyway, but there's a pretty good reason to comply right there. On the flight back, I'm going to re-code as many episodes of "Scrubs" as I can to fit on my 1GB mem card. (I wanted to get a 2GB card, but the price point wasn't attractive enough... the ratios are out of whack but then again, I saw a deal online recently where a 1GB card was like $15 or something like that...ridiculously cheap while 2GB remains at about $50....)

Yes, the 8800 being released within a day or two after I bought my 8100 gave me reason to pause. But then again, I might have gone with the 8100 anyway. The size is perfect. Going bigger doesn't appeal to me much at all.

rivviepop 03-04-2007 08:31 PM

Quote:

Originally Posted by erroneus
I wonder if there's a way to add a command-line or two to determine the aspect ratio of the source video and simply either make a selection of aspect ratios or calculate the new, scaled down size for the target video file?

Yeah, it's on my list of things to do. :) If nothing else I want a commandline switch to choose a res, but it just hasn't been the highest priority item on my list of stuff. Maybe some day...but not today.

tuxi 03-25-2007 06:59 PM

I'm an 8800 user and will be happy to help with getting this script to work for me. I've been a Linux user for six years and am presently using Fedora Core 6 and Ubuntu 6.10. My BlackBerry is generally used with my company laptop, which has Windows XP.

When I've tried the script, I've had the video only show a couple of frames. I've tried with multiple mp4 formats as the source. All videos were rendered using Kino from personal DV files.

LunkHead 03-25-2007 07:01 PM

Sweet! AND Welcome to the forums!!!!!!

rivviepop 03-25-2007 07:14 PM

Quote:

Originally Posted by tuxi
When I've tried the script, I've had the video only show a couple of frames. I've tried with multiple mp4 formats as the source. All videos were rendered using Kino from personal DV files.

This smells like poor encoding/decoding libs (I can't say for sure, but it's the first thing that comes to mind based on experience). Do you:

- have a newer mplayer installed from FreshRPMS? (or maybe RF or ATrpms)
linky: http://zod.freshrpms.net/rpm.html?id=888

- have the "win32" DLL files unzipped to /usr/lib/win32/ on your machine?
linky: http://www.mplayerhq.hu/design7/dload.html
direct x86 snag: http://www3.mplayerhq.hu/MPlayer/rel...061022.tar.bz2

As we all know, video encoding/decoding w/linux can be sort of hit or miss depending on your source; on my laptop I have the above two in place which does't produce any bad videos (most of the time, of course there are exceptions) and actually they're quite good.

Feel free to upload a smaller mp4 (if legal) that's giving you trouble and I'll give it a whirl, see what happens on my end.

LunkHead 03-25-2007 07:16 PM

My vids are ALL horrid! :razz:

@rivviepop don't you owe me a beer???? lol :)

tuxi 03-26-2007 09:51 PM

Quote:

Originally Posted by rivviepop
This smells like poor encoding/decoding libs (I can't say for sure, but it's the first thing that comes to mind based on experience). Do you:

- have a newer mplayer installed from FreshRPMS? (or maybe RF or ATrpms)

- have the "win32" DLL files unzipped to /usr/lib/win32/ on your machine?
linky:
direct x86 snag:

I checked to see if my machine was setup as you describe before I ran the script.
rpm -qi mencoder gives
Code:

Name        : mencoder                    Relocations: (not relocatable)
Version    : 1.0                              Vendor: Freshrpms.net
Release    : 0.34.rc1try2.fc6              Build Date: Tue 09 Jan 2007 04:22:36 AM CST
Install Date: Sat 10 Feb 2007 07:50:47 AM CST      Build Host: python3.freshrpms.net
Group      : Applications/Multimedia      Source RPM: mplayer-1.0-0.34.rc1try2.fc6.src.rpm
Size        : 7362484                          License: GPL
Signature  : DSA/SHA1, Tue 09 Jan 2007 04:23:30 AM CST, Key ID 692ac459e42d547b
Packager    : Matthias Saou <matthias@rpmforge.net>
URL        : --
Summary    : MPlayer’s Movie Encoder
Description :
MPlayer’s Movie Encoder is a simple movie encoder, designed to encode
MPlayer-playable movies to other MPlayer-playable formats. It encodes to
MPEG-4 (DivX/XviD), one of the libavcodec codecs and PCM/MP3/VBRMP3 audio
in 1, 2 or 3 passes.  Furthermore  it has stream copying abilities, a
powerful filter system (crop, expand, flip, postprocess, rotate, scale,
noise, rgb/yuv conversion) and more.

I'll PM you with a URL to pick up the example video.

LunkHead 03-26-2007 10:26 PM

Looks OK to me but I will await rivviepop's response since he is far more advanced than me....

Quote:

Originally Posted by tuxi
I checked to see if my machine was setup as you describe before I ran the script.
rpm -qi mencoder gives
Code:

Name        : mencoder                    Relocations: (not relocatable)
Version    : 1.0                              Vendor: Freshrpms.net
Release    : 0.34.rc1try2.fc6              Build Date: Tue 09 Jan 2007 04:22:36 AM CST
Install Date: Sat 10 Feb 2007 07:50:47 AM CST      Build Host: python3.freshrpms.net
Group      : Applications/Multimedia      Source RPM: mplayer-1.0-0.34.rc1try2.fc6.src.rpm
Size        : 7362484                          License: GPL
Signature  : DSA/SHA1, Tue 09 Jan 2007 04:23:30 AM CST, Key ID 692ac459e42d547b
Packager    : Matthias Saou <matthias@rpmforge.net>
URL        : --
Summary    : MPlayer’s Movie Encoder
Description :
MPlayer’s Movie Encoder is a simple movie encoder, designed to encode
MPlayer-playable movies to other MPlayer-playable formats. It encodes to
MPEG-4 (DivX/XviD), one of the libavcodec codecs and PCM/MP3/VBRMP3 audio
in 1, 2 or 3 passes.  Furthermore  it has stream copying abilities, a
powerful filter system (crop, expand, flip, postprocess, rotate, scale,
noise, rgb/yuv conversion) and more.

I'll PM you with a URL to pick up the example video.


rivviepop 03-26-2007 10:32 PM

Quote:

Originally Posted by tuxi
I'll PM you with a URL to pick up the example video.

OK, I have the video here, mplayer tells me it's a 4:3 and it's playing just fine on my laptop. I converted it to both a 240x180 and 320x240 (which are both 1.33:1 ratio, 4:3) and they both play perfectly fine on my Pearl without any issues. I'll PM you back a link in a sec after I upload them somewhere.

You had asked about what the right size is in PM -- well, the *specs* say an 8800 is supposed to be able to play 320x240 (which would be fullscreen) but I don't have one to test with over my way, so I am unsure. But the 240x180 version should probably play fine on your device, I would imagine it might have a black border on the left and right though? (you'll have to tell me)

Regardless, let us know how these vids I converted work on your 8800...

tuxi 03-27-2007 06:56 AM

Quote:

Originally Posted by rivviepop
<snip>
You had asked about what the right size is in PM -- well, the *specs* say an 8800 is supposed to be able to play 320x240 (which would be fullscreen) but I don't have one to test with over my way, so I am unsure. But the 240x180 version should probably play fine on your device, I would imagine it might have a black border on the left and right though? (you'll have to tell me)

Regardless, let us know how these vids I converted work on your 8800...

Both of your videos performed better than my attempts at 320x240. I had already prepared a 240x180 prior to getting the link, so I also tested it. Both your and my 240x180 videos played with no hesitation. Your 320x240 version hesitated at the beginning, but it started playing OK after 30-60 frames.

All of the 4:3 videos play with black bars on the side since the display on the 8800 is apparently 16:9. I stick with my assertion that if 320 pixels is the width, then 180 must be the height. If this is correct, the proper 4:3 size is 240x180, and the player has to reduce the video size on the fly if it is in a higher resolution.

A question on the win32 codecs:
I copied the newest codecs into /usr/lib/win32. Some of the older codecs (with slightly different names) remain in the directory. Should I purge the directory and recopy the newest only? Thanks.


All times are GMT -5. The time now is 09:00 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.