Conversion script for Jlime videos

Hans Bezemer thebeez at xs4all.nl
Tue Aug 23 11:57:32 EDT 2011


Hi!

If someone is interested, I hacked together a small 4tH script that you feed a 
filename and the display resolution (width, height) of a movie and it figures 
out which FFMPEG command you have to give to get an Jlime MPlayer compatible 
movie.

MPEG2 streams allow for anamorphic display, that means the display on the 
screen is different from the actual resolution. Of couse, you get a letterbox 
that way, but it won't be distorted.

If I'm courageous I can feed the resulting string to 4tHs SYSTEM library which 
means it starts and executes FFMPEG as well. If we get that far it won't be 
difficult to make a native executable out of it, so you don't even have to 
install 4tH.

Hans Bezemer

---8<---
\ ffmpeg -i Bladerunner.m4v -ac 1 -ar 22050 -s 320x132
\ -padbottom 54 -padtop 54 -aspect 4:3 Bladerunner.mpg

char . constant '.'                    \ a dot character
512 constant /command                  \ size of command line
/command string command                \ allocate command line

: number? args number error? ;         ( n1 -- n2 f)
: odd? dup 1 and ;                     ( n -- n f)
: +one? if 1+ then ;                   ( n f -- n+1)
: -one? if 1- then ;                   ( n f -- n-1)
: +string command +place ;             ( a n --)
: +number <# #s #> +string ;           ( n -- )
: basename begin dup while 2dup 1- chars + c@ '.' <> while 1- repeat ;
: usage argn 4 < abort" Usage: nanocalc filename width height" ;

: margins                              ( n --)
  dup odd? >r
  s"  -padbottom " +string r@ -one? +number
  s"  -padtop "    +string r> +one? +number
;
                                       ( n --)
: padding? dup if margins else drop then ;

: calculate                            ( -- n1 n2)
  240 3200000
  2 number? abort" Invalid width" /
  3 number? abort" Invalid height" * 10000 /
;

: compose                              ( n1 n2 -- a n3)
  command >r s" ffmpeg -i " r@ place
  1 args +string s"  -ac 1 -ar 22050 -s 320x" +string
  odd? +one? dup +number - 2/ padding? s"  -aspect 4:3 " +string
  1 args basename +string s" mpg" +string r> count
;

: nanocalc usage calculate compose ;

nanocalc type cr
---8<---

-- 
Absolutely no trees were killed to produce this sig. Well, OK, we had to tie 
one up and torture it. That's it.

Visit our website! http://thebeez.home.xs4all.nl/4tH/

*** Home of the 4tH compiler! ***




More information about the discussion mailing list


interactive