[FFmpeg-user] smarter scaling filter

Jim Worrall coniophora at gmail.com
Sun Dec 11 01:31:27 CET 2011


On Dec 9, 2011, at 5:01 PM, Jim Worrall wrote:

> 
> 
> I found out I could reduce this expression even further, and it still seems to produce the wrong result:
> 
> -vf "scale = st(0,1) * 640 : ld(0) * 480"
> 
> The first function, st(0,1), evaluates to 1, and the output file has a width of 640.
> The second function, ld(0), apparently evaluates to 0, and the output retains its original height.
> 
> Isn't ld(0) supposed to reload var 0 with a value of 1?
> Does a variable not survive a colon, or what? 
> Is it possible I screwed up the compilation and made a bad ffmpeg?
> 
> I could really use some help here guys!
> 
> Jim
> 
> ffmpeg version 0.8.7.git-5b98ea1, Copyright (c) 2000-2011 the FFmpeg developers
>   built on Dec  9 2011 16:52:59 with clang 3.0 (tags/Apple/clang-211.12)
>   configuration: --prefix=/Volumes/Ramdisk/sw --cc=clang --enable-gpl --enable-version3 --enable-filters --arch=x86_64 --enable-hardcoded-tables --disable-indevs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo-aacenc --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libx264 --enable-libvorbis --enable-libtheora --enable-libspeex
>   libavutil    51. 31. 0 / 51. 31. 0
>   libavcodec   53. 42. 0 / 53. 42. 0
>   libavformat  53. 24. 0 / 53. 24. 0
>   libavdevice  53.  4. 0 / 53.  4. 0
>   libavfilter   2. 52. 0 /  2. 52. 0
>   libswscale    2.  1. 0 /  2.  1. 0
>   libpostproc  51.  2. 0 / 51.  2. 0
> 
> 
And now the epilogue of my monologue:

I submitted a bug report, and it was converted to a feature request.  
Currently, the VARIABLES DO NOT SURVIVE BETWEEN EXPRESSIONS.  
This info has been added to the manual.  

Just in case anyone wants to do this in the future, here is a filter that works without 
internal, user-created, FFmpeg variables.  It's a bit ghastly, but it works.  
Video of any size or aspect ratio will be scaled down (but not up) to fit into the 
display dimensions of the device while maintaining aspect ratio.  
The dimensions of the device, or frame, are represented by 
$FW (width), $FH (height) and $FA ($FW/$FH).  

-vf "scale = min(1\,gt(iw\,$FW)+gt(ih\,$FH)) * (gte(a\,$FA)*$FW + \
lt(a\,$FA)*(($FH*iw)/ih)) + not(min(1\,gt(iw\,$FW)+gt(ih\,$FH)))*iw : \
min(1\,gt(iw\,$FW)+gt(ih\,$FH)) * (lte(a\,$FA)*$FH + \
gt(a\,$FA)*(($FW*ih)/iw)) + not(min(1\,gt(iw\,$FW)+gt(ih\,$FH)))*ih" 

Jim


More information about the ffmpeg-user mailing list