VideoHelp Forum




+ Reply to Thread
Results 1 to 15 of 15
  1. Hi,

    whilst trying to improve my .flv quality see https://forum.videohelp.com/threads/336285-ffmpeg-to-flv-audio-quality-improvement?p=20...94#post2089394,

    I came across the issue of the command needing a width and height size thus resizing the output video - I need a script that will convert all sizes of video whilst retaining it's aspect ratio

    VIDEOHELP.COM member poisondeathray put it well "a way to automatically scale properly , because what if the input video has a 4:3 AR, or a 2.35:1 AR ? . What if it's some other combination ? You would have to code some script to compensate for that, otherwise they will be distorted"

    has anyone come across this ?

    I was thinking of just taking out the variable -s all together...
    Last edited by richiedood; 27th Jun 2011 at 18:44.
    Quote Quote  
  2. I added a post in your other thread, about a method in avisynth, but not sure how to code it in ffmpeg , or maybe you can run it in wine

    https://forum.videohelp.com/threads/336285-ffmpeg-to-flv-audio-quality-improvement?p=20...=1#post2089397


    What is your goal for display ? Maybe describe how you have this setup and what types of files you typically encounter . I'm assuming something like people uploading files to your site ?
    Quote Quote  
  3. you got it exactly it is a site that will recieve multiple file formats (even if someone uploads a video they took on their iphone holding it up rather than sideways...

    one example was a video i took of a wedding on a sony handnycam 4:3 mpg and the result was distorted - so the black border method could be solution,

    I have tried to search the web for ffmpeg auto resize and haven't found much on the subject...
    Quote Quote  
  4. I'm not sure if there are any elegant solutions out there , except to write some user guidelines like youtube

    Some videos might be cropped, some might be letterboxed, how would you detect that without human intervention ? e.g. 1920x1080 frame size would be detected as 16:9, but if it was letterboxed , the active image area might be 1920x800 for 2.4:1. Someone might upload the same video as a cropped 1920x800... instead of 1920x1080... But the image should be the same. I'm sure you get the idea, there are waaay too many permutations

    Another gotcha - that sony handycam example is probably interlaced... would you deinterlace it ? How would you auto script it to deinterlace some but not others ? You can't resize interlaced footage properly, unless you deinterlace first

    Way too many issues....
    Quote Quote  
  5. I tried without the -s setting and changed to
    Code:
     -vpre fast
    looking nice- however it is increasing the size again by a few mb

    also there's no stopping it being imax size lol,

    ahh what about a max file size?
    Quote Quote  
  6. you can use abr or 2pass encoding instead if you need an exact filesize

    Or select a different crf value. That crf value will give different bitrates according to content complexity - this is the ideal way to encode if a certain quality level is your primary goal , because you might be giving too much bitrate for some videos, too little for others. This way the video gets the desired "quality" level
    Quote Quote  
  7. o.k. tried crf 23 chopped a 3 mbs of and quality still good
    probably time for me to look at abr and 2pass

    do you have some example commands for those?
    Quote Quote  
  8. But that's the problem - how do you know what bitrate to choose? A complex animation with explosions and fire and special effects might require 10x the bitrate for a certain "quality" level than a simple static interview sequence .

    But since you're setting this up for a website, abr would probably be a better option . Youtube and similar sites do this

    The command in x264 CLI is --bitrate , not sure what the ffmpeg version is, it's probably -b

    have a look here, yes it is -b
    http://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
    Quote Quote  
  9. tried without the -s setting and changed to
    Code:
    -vpre fast
    looking nice- however it is increasing the size again by a few mb
    I missed what you said earlier. The reason the filesize is increasing is the video output is the same dimension 1280x720 in and 1280x720 out. So when you use CRF encoding, a higher bitrate is required to maintain the same level of quality as specifed by "CRF 22". If you scale to a lower frame size, you require less bitrate. Does that make sense ?
    Quote Quote  
  10. Yes that makes sense,

    by frame size I assume you mean width and height...but is what I am trying to get away from.

    you are right in ffmeg -b = bitrate

    do you know what bit rate youtube uses or what is a good one?
    Quote Quote  
  11. Originally Posted by richiedood View Post
    Yes that makes sense,

    by frame size I assume you mean width and height...but is what I am trying to get away from.

    you are right in ffmeg -b = bitrate

    do you know what bit rate youtube uses or what is a good one?


    It varies by frame size, and they have been known to change it all the time . You can download and check

    I think their recent 720p versions use about 2 - 2.5Mb/s, but again , it varies
    Quote Quote  
  12. O.K. I changed the command,

    but think -b 2500k may be wrong as didn't make a difference in file size

    Code:
    ffmpeg -i test.mp4  -vcodec libx264 -vpre fast -crf 23 -b 2500k -acodec libfaac -ab 256k -ar 48000  tues.flv

    Code:
     ffmpeg -i test.mp4  -vcodec libx264 -vpre fast -crf 23 -b 2000k -acodec libfaac -ab 256k -ar 48000  tues.flv
    FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
      built on Dec  4 2010 15:35:31 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
      configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
      libavutil     50.15. 1 / 50.15. 1
      libavcodec    52.72. 2 / 52.72. 2
      libavformat   52.64. 2 / 52.64. 2
      libavdevice   52. 2. 0 / 52. 2. 0
      libavfilter    1.19. 0 /  1.19. 0
      libswscale     0.11. 0 /  0.11. 0
      libpostproc   51. 2. 0 / 51. 2. 0
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 1
        compatible_brands: isomavc1
      Duration: 00:01:57.36, start: 0.000000, bitrate: 2672 kb/s
        Stream #0.0(und): Video: h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 2513 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc
        Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 157 kb/s
    File 'tues.flv' already exists. Overwrite ? [y/N] y
    [libx264 @ 0x1bf821d0]using SAR=1/1
    [libx264 @ 0x1bf821d0]using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
    [libx264 @ 0x1bf821d0]profile High, level 3.1
    [libx264 @ 0x1bf821d0]264 - core 107 - H.264/MPEG-4 AVC codec - Copyleft 2003-2010 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00
    Output #0, flv, to 'tues.flv':
      Metadata:
        encoder         : Lavf52.64.2
        Stream #0.0(und): Video: libx264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], q=10-51, 2000 kb/s, 1k tbn, 30 tbc
        Stream #0.1(und): Audio: libfaac, 48000 Hz, stereo, s16, 256 kb/s
    Stream mapping:
      Stream #0.0 -> #0.0
      Stream #0.1 -> #0.1
    Press [q] to stop encoding
    frame= 3518 fps= 10 q=-1.0 Lsize=   42971kB time=117.27 bitrate=3001.9kbits/s dup=0 drop=1
    video:40441kB audio:2370kB global headers:0kB muxing overhead 0.374475%
    [libx264 @ 0x1bf821d0]frame I:30    Avg QP:18.46  size: 23079
    [libx264 @ 0x1bf821d0]frame P:2791  Avg QP:22.72  size: 13538
    [libx264 @ 0x1bf821d0]frame B:697   Avg QP:26.31  size:  4210
    [libx264 @ 0x1bf821d0]consecutive B-frames: 68.4% 12.0%  8.2% 11.4%
    [libx264 @ 0x1bf821d0]mb I  I16..4: 40.2% 56.3%  3.5%
    [libx264 @ 0x1bf821d0]mb P  I16..4:  4.9%  9.5%  0.4%  P16..4: 42.7% 10.7%  4.7%  0.0%  0.0%    skip:27.2%
    [libx264 @ 0x1bf821d0]mb B  I16..4:  1.2%  1.1%  0.2%  B16..8: 25.9%  4.7%  0.4%  direct: 8.4%  skip:58.1%  L0:44.5% L1:44.6% BI:10.8%
    [libx264 @ 0x1bf821d0]8x8 transform intra:63.2% inter:81.6%
    [libx264 @ 0x1bf821d0]coded y,uvDC,uvAC intra: 36.7% 55.4% 10.8% inter: 17.4% 23.3% 0.6%
    [libx264 @ 0x1bf821d0]i16 v,h,dc,p: 36% 26% 15% 23%
    [libx264 @ 0x1bf821d0]i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 19% 33%  4%  5%  5%  6%  5%  5%
    [libx264 @ 0x1bf821d0]i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 17% 21%  5% 11%  9%  9%  6%  5%
    [libx264 @ 0x1bf821d0]i8c dc,h,v,p: 56% 20% 19%  4%
    [libx264 @ 0x1bf821d0]Weighted P-Frames: Y:2.3%
    [libx264 @ 0x1bf821d0]ref P L0: 74.5% 14.3% 11.0%  0.1%
    [libx264 @ 0x1bf821d0]ref B L0: 87.4% 12.6%
    [libx264 @ 0x1bf821d0]ref B L1: 96.8%  3.2%
    [libx264 @ 0x1bf821d0]kb/s:2825.08
    Quote Quote  
  13. you can't use both -crf and -b , they are mutually exclusive for rate control. It's one or the other

    remove the crf
    Quote Quote  
  14. Member
    Join Date
    Oct 2010
    Location
    England
    Search Comp PM
    Originally Posted by richiedood View Post
    I came across the issue of the command needing a width and height size thus resizing the output video - I need a script that will convert all sizes of video whilst retaining it's aspect ratio

    VIDEOHELP.COM member poisondeathray put it well "a way to automatically scale properly , because what if the input video has a 4:3 AR, or a 2.35:1 AR ? . What if it's some other combination ? You would have to code some script to compensate for that, otherwise they will be distorted"

    I was thinking of just taking out the variable -s all together...
    There's another way to change the size of the video with ffmpeg; the video filter 'scale'. For example:
    ffmpeg -i input.mp4 -vf scale=640:360 output.mp4

    One advantage of this method is the ability to set one dimension, and let ffmpeg calculate the other based on the aspect ratio. This sounds like what you want to do:
    ffmpeg -i input.mp4 -vf scale=854:-1 output.mp4

    In the example above, if the original .mp4 has the dimensions 640x360 (aspect ratio 16:9), setting scale=854:-1 will make ffmpeg calculate the height of the output video as 480px.
    If the original file is 640x480 (4:3), the converted video will be 854:641 (approx.)

    However, ffmpeg seems to have some issues with honouring/modifying the aspect ratio of some source files. For example, I've got some MPEG .ts files recorded off satellite, and ffmpeg can't handle the aspect ratio properly.
    The '-aspect' command works inconsistently (or not at all, in some cases).

    ffmpeg's 'video filters' (-vf) are a relatively new addition to the program, and borrow some concepts from mplayer/mencoder - but mplayer/mencoder gives more control over the video processing with significantly less quirks.

    You might want to consider using mencoder. If you're interested, I can post some command line examples.

    What resolution/aspect ratio are you trying to convert your videos to? Are you aiming for a fixed width, and have the height calculated (or vice versa). Or are you wanting to convert to a fixed width and height, and have the frame padded out with black bars, etc?
    Quote Quote  
  15. thanks for you detailed response,

    I have sorted my iphone scaling issue

    Code:
    ffmpeg -i btw.flv -vcodec mpeg4 -s 480x320  -b 512k  -acodec libfaac -strict experimental -ac 2  -ab 256k -ar 44100 test.mp4
    even by putting the size in when it plays on the iPhone it keeps it's aspect ratio


    now all i need to is adjust this for the ipad but looking on the web wasn't much help apparently 1024x768 is the size ipad plays.

    Code:
    ffmpeg -i VID.mov -vcodec mpeg4 -s 1024x768 -b 512k  -acodec libfaac -strict experimental -ac 2  -ab 256k -ar 44100 sat.mp4
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!