iEntry 10th Anniversary LinuxHaxor WH MH

How To Convert Any Video File Format Under Linux


This video tutorial will explain how to losslessly convert any video file format, including quicktime .mov, flash .flv files, open source .ogv, .mp4, .wmv, .asf and more. I show you how to install ffmpeg, check the formats and codecs available to you, convert a file to a new format (windows media and .asf in this example) without any loss in quality during the decoding and encoding process, and create and run a script file that will enable you to run a batch conversion on any number of files at the same time.

Anyone who has tried to convert multimedia files in Windows knows how challenging it can be. There are a ton of different programs out there to do it, but most of them either leave a watermark in your video, lower the resolution of your video, or both, unless you pay hundreds of dollars. ffmpeg can do this for you quickly, conveniently, and completely free – and can even be used in Windows! This video was created for Ubuntu, but will work for most Linux distributions, and the code you learn here to convert a file can be applied to the Windows version as well, though Windows’ scripting language is different so you will need to adjust the batch conversion script.

Follow me on Twitter and check out my blog.


Single File Conversion

sudo apt-get install ffmpeg

ffmpeg -formats (lists all available formats based on the currently installed codecs, to be used with -vcodec, -acodec, and -f)

ffmpeg -i inputfilename.ext -vcodec wmv2 -sameq -acodec wmav2 -f asf outfile.asf

ffmpeg – start ffmpeg
(-i inputfilename.ext – tells ffmpeg the file name and extension from which to convert)
(-vcodec wmv2 – use video codec wmv2)
(-sameq – use same video quality as source file)
(-acodec wmav2 – use audio codec wmav2)
(-f asf – choose output format, sometimes known as a container, in this case asf)

Bonus Batch Conversion

sudo touch convert.sh (here we use touch to create a blank file, not always necessary to do that rather than through a text editor but it is safer with permissions and such)

gksu gedit convert.sh (this is only available for gnome desktops, i.e. ubuntu and the like, so you can tell people to use whatever text editor they like)

sudo chmod 0777 convert.sh (like last time, chmod changes file or directory permissions, in this case giving access to everyone to read, write, execute the script)

./convert.sh (runs the script convert.sh on files in the /Videos directory)

ls (ls -l lists all files and directories plus permissions)


script:

for f in *.MOV; do ffmpeg -i “$f” -vcodec wmv2 -sameq -acodec wmav2 “${f%.MOV}.asf”; done


If you liked this article, please share it on del.icio.us, StumbleUpon or Digg. I’d appreciate it.


  • bigbrovarNo Gravatar

    May 19th, 2009 03:37

    Nice guide, but most new users always have a pathological fear of commandline, and when they say Linux is not ready for the desktop. what they actually mean is that we are not ready to learn the commandline no matter how easy it might seem. Fortunately There are tools that have been able to unlock almost every commandline utility (at least for desktop use) on linux hence the use of commandline solution should not be the first to be thrown towards a new user.

    For your guide there is a tool called Winff which can be downloaded from http://www.winff.org that unlocks the powers of ffmpeg in a simple, easy to use gui interface. winff works like a charm and as video profiles for all ranges of iPods,Palm,and even android phones amongst others. I use it often and it has never failed me. I would prefer it over using ffmpeg from commandline any day.

  • BigWhaleNo Gravatar

    May 19th, 2009 05:08

    Few tips:

    When writing commands that should be typed in use $ as a prefix:

    $ ffmpeg -formats

    $ sudo chmod 0777 foo.sh

    The comments and explanation that you enclosed with parentheses should be written as all comments in shell scripts – prefixed by #:

    #
    # This commad will make everything go away and delete all your files
    #

    $ rm *

    When writing a shell scripts it is always wise to start them with

    #!/bin/bash

    in the first line. For example if user would be running some other shell instead of bash (tcsh, csh, …) your for() loop wouldn’t work since it works only in bash.

    The convert.sh won’t work if someone will copy and paste it into file. Because command will span over two lines. It should be written like this:

    for f in *.MOV; do ffmpeg -i “$f” -vcodec wmv2 -sameq -acodec wmav2 \
    “${f%.MOV}.asf”; done

    or (the one I prefer)

    for f in *.MOV
    do
    ffmpeg -i “$f” -vcodec wmv2 -sameq -acodec wmav2 “${f%.MOV}.asf”;
    done

    Ok, now I’ll start sounding like a real pain in the ass… I guess someone has to? Or?

    Anyway, you should enclose all the code in this site in <pre> tags. Right now your quotes are replaced with something that is not a quote in bash or any other shell script. Copy pasting will break the script and your commands. Is this blog running on WordPress? Try using some code highlighting plugins. I’m using WP-CodeBox on my blog. It is pretty. :)

    One more last thing, 777 are bad permissions, bad bad bad. ;) 755 should be more than enough for simple video conversion.

    Ok, now really a last thing. Touching the file before editing doesn’t really matter if you chmod it later.

    That’s enough. I better stop now. :>

  • kyioNo Gravatar

    May 19th, 2009 06:57

    how can i convert my files to xvid codec using double pass filter?

  • Binny V ANo Gravatar

    May 19th, 2009 08:55

    Here is my collection of ffmpeg commands.

  • hombreloboNo Gravatar

    May 19th, 2009 12:18

    mm, I tried:

    ffmpeg -i kk.mov -vcodec h264 -sameq -acodec acc -f m4v kk.m4v

    and I get an error: “unkonwn encoder” although h264 seems to be in the list of encoders ….

    And thanks for the video !!

  • DrewLahoozNo Gravatar

    May 19th, 2009 12:36

    Can this be used to convert video files to sound files….say mp4 to mp3? Thanks!

  • Jimmy DolittleNo Gravatar

    May 19th, 2009 16:20

    Wow, aint she a little cutie! Hey now!!

  • No Gravatar

    May 19th, 2009 16:50

    why do you use sudo to touch and edit your file? It’s more save to use gedit in user-mode. If you want the script to be owned by root and/or in /usr/local/bin, you can use chown and mv with sudo.

    Also, like BigWhale point out, permissions shouldn’t be more then 755. 777 is very bad.

  • carlosNo Gravatar

    May 19th, 2009 16:53

    just go here and you will find the easy way to do any (almost) conversion in linux

    http://www.gnome-look.org/content/show.php/Audio%2BVideo%2BImage%2BText%2BISO+Convert?content=92533

  • AlexNo Gravatar

    May 19th, 2009 16:54

    The introduction seems a little misleading; given that you’re dealing with lossy video compression codecs, I think it is by definition impossible to convert them losslessly. When going to or from a lossy-compressed format, there will always be some quality lost; it may be imperceptible, but the more times you repeat the process the more you’ll see it.

  • TobiasNo Gravatar

    May 19th, 2009 17:09

    Sorry, but this is more than a cheap nitpick. What you are doing is more getting a quality in the same ballpark in a different format. But it’s not a lossless conversion at all.

    For example, if you save a jpeg file over and over again with the same quality settings (viz. -sameq) then the image will degrade more and more. Because jpeg is not lossless and neither are most of video codecs.

    Don’t bother to read, but this would be the wikipedia article: http://en.wikipedia.org/wiki/Lossless

  • TobiasNo Gravatar

    May 19th, 2009 17:10

    Yeah, what he said.

  • andresNo Gravatar

    May 19th, 2009 17:12

    I think I’m in love, hot and geek ;)

  • love_moss_notNo Gravatar

    May 19th, 2009 17:29

    $Girl, I love you…

    Muah!!!

  • Tetsuo ShimaNo Gravatar

    May 19th, 2009 18:05

    Here is a nice GUI that has ffmpeg installed. Works great.

    http://www.erightsoft.com/SUPER.html

  • UpshotNo Gravatar

    May 19th, 2009 18:28

    Bookmarked for later reference! Thanks for the tip. Nice useful command line tool.

  • elmimmoNo Gravatar

    May 19th, 2009 18:35

    Sorry to bang with the same, but I am still wondering what of the doesn’t-mean-lossless meanings of lossless she is referring to?

    Like loosing no hair because of lack of frustration? That might be it, yeah…

  • Hypermagic2No Gravatar

    May 19th, 2009 18:38

    There’s a much easier way. Install Wine and install MediaCoder in Wine. It has all the necessary codecs internalized and works great.

  • pipNo Gravatar

    May 19th, 2009 19:23

    You are awesome, however there is this little app called WinFF that makes this so much easier. Look it up in add/remove in ubuntu.

  • NixieNo Gravatar

    May 19th, 2009 19:45

    Thanks for the feedback – yes, the code could be cleaned up, and thanks for letting me know about winff. Yes, my language could be more precise about lossless. The conversion adds imperceptible loss, so I improperly called it lossless.

    I may bash Windows, and it is fun to do so, but I still use it for gaming and other things, so don’t think I am some sort of cult follower. I just like to use the right tools for the task at hand, and ffmpeg does its job very well and very quickly, with no fuss. I haven’t tested the code in Windows but the same command line should work with the Windows version as well.

    hombrelobo – are you sure you’re using the proper audio codec? It should be aac, not acc, right?

  • michaelNo Gravatar

    May 19th, 2009 20:03

    um. this is NOT lossless. this is LOSSY transcoding. i.e. LESS QUALITY than the original.

    lossless transcoding with ffmpeg would use -vcodec copy and -acodec copy (or an uncompressed equivalent such as WAV, PCM, HUFFYUV, etc)

    so… a totally useless thread. thanks.

  • NixieNo Gravatar

    May 19th, 2009 20:35

    I’m sorry that you felt it was worthless. I feel it was worthwhile to make, regardless of a particular mistake, and it seems to have helped some people. Unfortunately you can’t please everyone.

  • BobCFCNo Gravatar

    May 19th, 2009 23:15

    Handbrake works on Ubuntu. I haven’t got round to it yet but I hear it is like the VLC of video conversion and uses ffmpeg underneath

    http://handbrake.fr/

  • Jeff LittleNo Gravatar

    May 19th, 2009 23:56

    what about real audio?

  • Michael RileyNo Gravatar

    May 20th, 2009 03:05

    I appreciate you really sticking to the “right” way to do it in linux, providing the command line references for it, it’s always useful to have it in that format.

    Thanks for the writeup, I’m following you on twitter :)

  • lossyNo Gravatar

    May 20th, 2009 03:14

    Just take out that lossless crap already. thanks. whatever gave you the impression any encoding to a compressing format could be lossless?

  • Television VoyeurNo Gravatar

    May 20th, 2009 05:36

    Thanks for the batch script, I’ll use it with the bulk save feature on http://www.vidimonkey.uni.cc to save some youtube dailymotion veoh videos.

  • hombreloboNo Gravatar

    May 20th, 2009 05:40

    @nixie yes, you are right, it should be aac … :D …. but still the same error, “Unknown encoder ‘h264′”

    By the way, I am using Arista, personally I think it is far better than WinFF or handbrake: http://programmer-art.org/projects/arista-transcoder

    And thanks for the videos !!!

  • JulianNo Gravatar

    May 20th, 2009 06:28

    Good work!

    The ‘lossless’ issue is a minor one- don’t mind the naysayers. Numerous people will appreciate this video greatly. Most of all, you’re helping to make the command line accessible with a well produced and informative video. One of the best I’ve seen yet.

    Keep up the good work!

    (/me fwd’s the video liberally)

  • niceone!No Gravatar

    May 20th, 2009 09:45

    avidemux works pretty good, i’m a newbie and its GUI, so its all good. I like the command line as well, and I know its so powerful and quick but I don’t have time to read all that stuff! Oh yeah you’re hot, I agree…THIS is how you promote Linux :) in Other Operating Systems.http://forums.overclockers.com.au/showthread.php?t=781809

  • Stirling WestrupNo Gravatar

    May 20th, 2009 20:21

    Of course, this only works on codecs that Linux can read. I recently came
    across some old IV50 videos from ages ago when I ran Windows. There is no
    Linux codec for this format, and the various workarounds that involve using
    .dll files borrowed from 32-bit windows don’t work on a 64-bit Linux (which is
    what I am running.)

    Its looking like I’m going to have to go and ask someone with a windows box
    to convert them to XVID for me.

  • irlandesNo Gravatar

    May 20th, 2009 23:46

    Nixie, I am old enough to be your grand-dad, maybe your great-grand-dad. But, I am not dead, so I also think you are hot. However, since I am old, my definition of hot is different than the young guys. To me, smart is hot, and you sure seem smart-hot, heh, heh.

    Physically hot is very temporary. Smart-hot lasts almost forever, unless you get dementia when you are 80. A smart 60 year old woman is still fun to be around. There is no such thing as a 60 year old ‘babe’.

    Don’t take any nonsense off guys who only think you are physically hot. Hang around guys who think you are smart-hot. Trust me on this. You are not the first smart-hot woman I have known in my nearly 70 years.

    You should be safe with Linux guys; most are smarter than average, too.

    And, I agree, the lossless booboo is trivia, pure trivia.

    I found this very interesting, thanks for posting it! Linux since December 1999. Currently using Kubuntu 6.10; 7.04; 7.10; 8.04; GOs; Mandriva; CentOs; and ready to install Kubuntu 9.04 tomorrow on my two computers. I multi-boot which gives me a lot of distros to play with. I have a large storage FAT 32 partition, and set up links to each distro as needed so everything important is available on all distros.

  • Some Arch FanNo Gravatar

    May 21st, 2009 14:49

    Other frontends for ffmpeg are hypervc (Hyper Video Converter) and shazam.

    http://www.gtk-apps.org/content/show.php/Hyper+Video+Converter?content=88970
    http://shazam.sourceforge.net/

  • give me text tutsNo Gravatar

    May 22nd, 2009 15:23

    Can we not get any more video tutorials? I was hoping this video thing was just a temp fad on LinuxHaxor, but it’s still here. :(

  • The HulkNo Gravatar

    May 30th, 2009 20:08

    What is a “container”? What is asf? and what is outfile.asf? You did not explain these things in your video.

    I tried to convert a file in the using ffmpeg four times. I kept getting error messages. The forth time is worked. Now let’s see if it plays.

  • The HulkNo Gravatar

    May 30th, 2009 20:10

    By the way I have a core 2 duo. I noticed that while encoding one core is at 100% and the other is at 11%. Is something wrong?

  • Badry Darkoush

    June 1st, 2009 03:42

    Hi Nixie,
    Thank you for these nice CLI tutorial , keep up the good work .
    for GUI programs this another tool for converting video : MMC (MobileMediaConverter)
    http://www.miksoft.net/mobileMediaConverterDown.htm
    it’s uses ffmpeg for back-end .
    Cheers,
    Free-Programmer

  • BigWhaleNo Gravatar

    June 3rd, 2009 04:39

    The Hulk,

    Your CPU usage means that ffmpeg is utilizing 100% of one core and the other core is used by different processes. This is normal, since ffmpeg is not multi-threaded application and doesn’t know how to use more than one core.

  • Hale SmithNo Gravatar

    June 14th, 2009 12:52

    What a complete bull, you could download ffmpeg or any other FOSS on a Windows platform that has the same functionality with a GUI front end, to convert your video files. Nice touch on the FUD side of things, next time try viewing Flash or DVD or Blue ray on Linux without having Video Tear. A GRAINY conversion on Video on a Windows platform, ha! That’s a lot of laugh.

  • Anonymous InsiderNo Gravatar

    June 17th, 2009 22:36

    Your presentation is pretty nice.

    Now, could you do a presentation to refute this:

    http://www.montanalinux.org/lfnw-2009-lunduke.html

    It’ll be nice if you can refute this too:

    http://www.krsaborio.net/research/2000s/09/0128.htm

    Thank you.

  • morganNo Gravatar

    September 1st, 2009 09:25

    ok so you have downloaded all the sections to a movie and want to join them back together……what is the best program to do this?

  • sundaymickyNo Gravatar

    September 10th, 2009 06:42

    You can try Cucusoft DVD and Video Converters Suite which includes Cucusoft Ultimate DVD and Video Converter Suite. It is the best all-in-one DVD and video conversion software converts DVDs and videos to play on almost any portable device including iPod, iPhone, Zune, PSP, video capable MP3 players, video capable mobile phones, and Pocket P.C., etc.

  • peteNo Gravatar

    September 20th, 2009 20:04

    There is one MAJOR problem and one minor problem with the scripts that people are people are using to convert the files.

    “${f%.MOV}.asf”

    The above code snippet does one thing; it renames the file from:
    .MOV to .asf

    The problem is that their is no check to see if there is an existing file
    name. For example you’re converting. “movie.MOV” and run it through
    the script. The result should be “movie.asf”.

    SUMMARY:
    “movie.MOV” to “movie.asf”

    There is no check to see if “movie.asf” exists. If it does exist; then the
    file will be overwritten. You could loose a file or wind up reconverting
    the same file.

    The minor problem is that script assumes that there are files with spaces
    in their names. Not actually a bad thing; but it really should be
    converted to something else: (IE: underscrore, period, something).

    Just as long as people understand that they may clobber / overwrite a file
    then tis ok.

    Just a suggestion:
    1) script to remove spaces and special characters from filenames
    while checking to see that I don’t over write files when the get renamed.

    2) Script the conversion program to make sure that the files to be
    converted don’t over write existing files.

    3) break out popcorn.

    Just a heads up to people about the potential for having your files
    overwritten.

    Regards,
    Pete

  • phantomNo Gravatar

    September 20th, 2009 20:46

    Nice Troll Hale Smith:

    Nice touch on the FUD side of things, next time try viewing Flash or
    DVD or Blue ray on Linux without having Video Tear.
    A GRAINY conversion on Video on a Windows platform, ha! That’s a
    lot of laugh.

    1) Really I got Flash 10 running on Linux. Clueless +1
    2) DVD there are codecs in the variousrepositories that allow you to watch
    DVD’s providing that you’re not in a coutry that has some laws about
    distributing certain codecs. If you are in such a country you can buy
    your own codecs through: wwwfluendo.com/ Clueless +2
    3) GRAINY conversion. Well WMP out of the box has poor support
    for a lot of video codecs. You need to add tons to make WMP functional
    such as Divx, mpeg4 part 10, etc. Unless you use a video player that
    supports it. IE: VLC, mplayer, etc. You can risk downloading codecs
    from various sites; but your only going to wind up using:
    Norton an McAfee
    Spybot
    Winddwos Defender
    Malwarebytes
    and etc to fix you machine.

    Regards Troll..

  • DanhNo Gravatar

    April 17th, 2010 17:39

    i can be helped with ffmpeg but i am using windows xp, i think it works the same.

Trackbacks

  1. popurls.com // popular today
  2. esti ajánló: levélfordítás gmail l… « klog gyártósor
  3. How To Convert Any Video File Format Under Linux | LinuxHaxor.net | File Search Engine Ispey
  4. How To Convert Any Video File Format Under Linux — WhoCares?
  5. Web Sites of Interest » links for 2009-05-19
  6. links for 2009-05-19 « My place
  7. How To Convert Any Video File Format Under Linux | LinuxHaxor.net
  8. makin257's status on Wednesday, 20-May-09 10:34:20 UTC - Identi.ca
  9. How To Convert Any Video File Format Under Linux « Internet Making Money
  10. Convert between video formats « 0ddn1x: tricks with *nix
  11. Vídeo: A Nixie explica como instalar CODECs no Linux
  12. Articles Collection of May’09 « Dako-Tux

Subscribe without commenting


Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.


  • depression self help
  • buy ultram
  • stomache ulcers
  • vitamin for hair loss
  • breast cost enhancement
  • apotheke online
  • diflucan male
  • simple remedy obesity
  • male sexual arousal
  • help for heart failure
  • medical discount international drug
  • soma information
  • compare viagra cialis
  • headache help
  • valium on line
  • heart attack causes preventions cure
  • order medrol
  • allegra side effects
  • cialis 5
  • antibiotic men
  • drug stop smoking
  • natural weight loss supplement
  • phentermine no doctor
  • tramadol use
  • alternative arthritis remedies
  • online levitra
  • pharmacy phentermine
  • heart rates in cardiac arrhythmias
  • drugs for rhuematiod arthritis
  • new antidiabetic drugs
  • hair regrowth
  • non-prescription treatments for erectile dysfunction
  • stop psoriasis itching
  • cialis cheap prices
  • hiv medications
  • womens health
  • buy online tramadol
  • valium 5 mg
  • treatment of arthritis
  • medication for cats
  • phentermine no prescription fast delivery
  • diet pill side effects
  • tramadol cod
  • rate weight loss products
  • skin infections antibiotics
  • pet treats available
  • tips for gaining muscle mass
  • no prescription cialis
  • psoriasis on the face
  • buy pain med
  • online phamacy viagra
  • strengthen immune system
  • buy levitra no prescription
  • pfizer viagra
  • pain prescription online
  • buy cialis delived next day
  • prevent pregnancy
  • cheapest phentermine online free shipping
  • woman sexual enhancement
  • side effects of blood pressure tablets
  • vitamin c deficiency
  • heart failure online
  • canada drugs on line
  • light cure for pain
  • high blood pressure cause
  • generic for actos
  • generic for nexium
  • alcohol celebrex
  • pills for weight loss
  • drugs for adhd
  • prescription pills
  • buy alpha lipoic acid
  • new smoking cessation drugs
  • order cialis jelly
  • generic viagra
  • ambien withdrawl symptoms
  • weight loss ideas
  • all natural breast enhancers
  • oral chlamydia
  • cialis by mail
  • allergy sinus tablets
  • anxiety meds online
  • treat muscle spasms
  • pediatric diarrhea
  • buy phentermine cheap
  • 100mg tramadol
  • menopause tablets
  • the cialis
  • gout cures
  • verapamil
  • medication to help stop smoking
  • xanax and drug testing
  • latest treatment for heart attack
  • viagra information
  • online pharmacies pain meds
  • cheap body building supplement
  • treatment for vomiting
  • body building diet nutrition
  • drug free high blood pressure help
  • cialis 30mg
  • non prescription drugs
  • cheap levitra
  • penis enlarger
  • celexa no prescription
  • cheap pharmacy no prescription
  • medication on line prescription
  • diarrhea children treatment
  • avodart prescription
  • asthma facts
  • back acne and dry skin
  • mebendazole tablets
  • body building online course
  • buy cheap low blood sugar
  • alternative arthritis remedy
  • cheap depression medications
  • anti depression medicine
  • buy tramadol online without prescription
  • does clomid work
  • osteoporosis and bone health
  • irritable bowel syndrome treatments
  • stopping diabetes
  • metabolic weight loss
  • bupropion pharmacy
  • antifungal drug
  • otc scabies cream
  • treatment for stroke
  • severe neck muscle spasm
  • drug zolpidem
  • canadian pharmacy drug
  • natural hair loss treatment
  • walmart pharmacy
  • headache help
  • bust enlarge
  • flu shots
  • new medicines for depression
  • viagra cialis levitra comparison
  • valium and xanax
  • baby flu
  • klonopin blood pressure
  • ambien no prescription
  • soma vicodine
  • levitra tablet
  • viagra in britain
  • blood pressure medication names
  • depression effexor
  • levaquin online
  • sex with levitra
  • treatment of heart attacks
  • claritin for allergies
  • viagra by mail
  • weight loss supplement
  • stomach pains and gas constipation
  • viagra cialis levitra
  • levitra canada
  • dose nexium
  • discount viagra in the usa
  • muscle building food
  • help for snoring
  • ranitidine interaction
  • itching ointment
  • severe acne treatments
  • different anti depressants
  • eye allergy medicine
  • buy vitamins
  • alternative treatment joint pain
  • flaxseed oil
  • medicines used for headaches
  • how heart rate regulated
  • muscle pain treatment
  • speed of viagra
  • cheapest phentermine online
  • buy phentermine online without a prescription
  • united pharmacy
  • buying pain relievers pills
  • body building diets
  • what valium does
  • online pharmacy mexico
  • professional viagra cheap
  • age of anxiety
  • drugs for male health
  • buying medications online without a prescription
  • viagra cialis on line
  • what does a valium look like
  • pharmacy mexico
  • buy soma drug
  • what burns body fat
  • new adhd drugs
  • prednisone prednisolone
  • online viagra
  • valium 5 mg
  • lipitor and zocor
  • powerful weight loss
  • 20mg levitra
  • anti obesity
  • pet medications
  • generic name viagra
  • long lasting condoms
  • bronchitis treatment in pregnancy
  • phentermine with hoodia
  • obesity care