Results 1 to 8 of 8

Thread: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash script.

  1. #1
    Join Date
    Apr 2005
    Location
    Astoria, Oregon
    Beans
    197
    Distro
    Ubuntu 14.04 Trusty Tahr

    Lightbulb Cool ffmpeg command converts to quality xvid avi. Help me automate with bash script.

    Some time ago, I found this really cool command made by someone. I don't even remember where I found it. I tried it and it converts mkv files and mp4 files very reliably to xvid-mp3 avi files that to my eyes, rival the originals in quality and are WAY SMALLER, and they play on my standalone divx player! SO COOL! See here:

    Code:
    mencoder -mc 0 -noskip -vf expand=:::::16/9,scale=720:480,hqdn3d,harddup -ovc xvid -oac mp3lame -xvidencopts fixed_quant=3.8:me_quality=6:noqpel:nogmc:trellis:chroma_me:chroma_opt:hq_ac:vhq=4:lumi_mask:max_key_interval=300:quant_type=mpeg:max_bframes=2:closed_gop:nopacked:profile=asp5:autoaspect:bvhq=1 -lameopts vbr=2:q=6:aq=2 -o "NEW_FILENAME" "FILE_TO_CONVERT"
    Just replace FILE_TO_CONVERT with the actual filename of the file you want to convert. Replace NEW_FILENAME with the new filename you want. Put .avi at the end of the filename, of course. I like to add "xvid.mp3" like this - Robin_Hood.xvid.mp3.avi

    I want to share that command that works so well for me on my Ubuntu 12.04 installation. Note that I do have a few extras installed, such as ffmpeg, lame, and, I think, ubuntu-restricted-extras among others.

    QUESTION:
    Can you guys help me write a script that will simply do this to all *mkv or *.mp4 files in a directory? This will help me learn how to make my own bash scripts, a skill I have been lacking, but always wanted to learn!

    Technically I suppose there's another subforum for this question, but I wanted to share the command itself here, and I know that this is a very trivial type of task which any skilled admin ought to be able to do, so . . .

  2. #2
    Join Date
    Dec 2006
    Beans
    7,349

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    You might be better to use FFmpeg rather than MEncoder, I have personally found better quality encodes with FFmpeg...
    You think that's air you're breathing now?

  3. #3
    Join Date
    Apr 2005
    Location
    Astoria, Oregon
    Beans
    197
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    Why did I say ffmpeg? It's mencoder. I'm going to go do one, and watch the output.
    Anyway, thanks for the pointer, andrew.46. I'll go look up how to use ffmpeg.
    By the way, it was here on ubuntuforums where I found the mencoder command.
    It was recommended here by user eye208. Some other interesting suggestions are also given in that thread, including a couple of possible solutions for my current question.

    However, I am still open to suggestions for a good method of batch-processing high-bitrate mp4 files into nice xvids. These days I use my computer to play the videos usually, but a few friends still use their DVP642 or other standalone divx players, so there's another reason why I want to to this.

    Thanks, all.

  4. #4
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    1. Get ffmpeg
    Get a recent build of ffmpeg from FFmpeg (or compile ffmpeg). The repository contains old, buggy junk that you don't need to waste your time using.

    2. Encode

    Note the ./ since we're using the downloaded ffmpeg binary):

    Code:
    ffmpeg -i input.mkv -vcodec mpeg4 -acodec libmp3lame -qscale:v 2 -qscale:a 5 output.avi
    • Control video quality with "-qscale:v". 2-5 is a good range and a lower value is a higher quality. 2 is often considered roughly visually lossless.
    • Control audio quality with "-qscale:a". Range is 0-9. 0-3 will produce transparent results and 4 should be close to perceptual transparency. See Recommended LAME Encoder Settings for more info.


    3. "Batch" process
    You can use a bash for loop:
    Code:
    mkdir newvids
    for f in *.mkv; do ffmpeg -i "$f" -vcodec mpeg4 -acodec libmp3lame -qscale:v 2 -qscale:a 5 newvids/"${f%.mkv}.avi"; done
    See some additional options at What are good parameters for encoding high quality MPEG-4? (I'm unsure if this is up to date).

  5. #5
    Join Date
    Apr 2005
    Location
    Astoria, Oregon
    Beans
    197
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    Wow! Thanks, FakeOutdoorsman! I'm gonna try it.
    I see what you did there! That's just exactly the kind of help I was looking for!
    OK! w00t!

  6. #6
    Join Date
    Aug 2013
    Beans
    4,941

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    Quote Originally Posted by FakeOutdoorsman View Post
    The repository contains old, buggy junk that you don't need to waste your time using.

    .
    For those interested.

    Check out http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=729203
    and
    https://bugs.launchpad.net/ubuntu/+s...v/+bug/1263278

    There is a ppa which provides up to date real ffmpeg (no, not Jon Severinsson's, which is old)

    https://launchpad.net/~samrog131/+archive/ppa

    This can be made the default ffmpeg (for compiling media players e.g) with update-alternatives.
    http://askubuntu.com/questions/36129...quantal-server

  7. #7
    Join Date
    Dec 2006
    Beans
    7,349

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    A few explanatory notes here if you wish to use xvidcore:

    http://ffmpeg.org/ffmpeg-codecs.html#libxvid

    I see my old frien 'theads' is in there too. Also the global options:

    http://ffmpeg.org/ffmpeg-codecs.html#codec_002doptions
    You think that's air you're breathing now?

  8. #8
    Join Date
    Dec 2006
    Beans
    7,349

    Re: Cool ffmpeg command converts to quality xvid avi. Help me automate with bash scri

    My brain finally clicked: there is a very nice shell script that has been around a long time that uses MEncoder to produce quality xvid files:

    http://xvidenc.sourceforge.net/

    It is in the Ubuntu repositories...
    You think that's air you're breathing now?

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •