mencoder Linux CLI video editing how to encode video file into xvid and split by time into multiple parts

Mencoder is great, you can throw anything at it, including video files from your camera and have it encode into xvid or almost any other format.

In my case I took 640x480 video from my Canon and reduced the size by 1/3 with the options below (there are many other options that you can read about in the manual but I like to keep it simple). 

Mencoder Encode

mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts fixed_quant=4 -o <output.avi>

Mencoder Split

Split the first 9 minutes of video into a part

mencoder -endpos 00:09:00 -ovc copy -oac copy inputfile.xvid -o outputfile.xvid

*We're kind of cheating because without specifying "-ss" (the start position) it defaults to starting at the beginning which would be the same as "-ss 00:00:00"

Note that we don't need the -ss (start time) flag because we are taking the first 9 minutes of the video.  It gets a little tricky (and this is not well documented or known by some) when you want to take a portion of videon in the middle (meaning not the first x minutes and not the last x minutes).

Split 9 minutes of video starting from the 9 minute point

This is where I consider mencoder to be unintuitive, here is the code I was using and lots would ask "why is mencoder ignoring the endpos"?  It actually isn't, what you thought you were telling mencoder is different than what is actually happening.

Take this code for example:

mencoder -ss 00:09:00 -endpos 00:18:00 -ovc copy -oac copy inputfile.xvid -o outputfile.xvid

At first I assumed this means "start at 9 minutes" and "end at 18 minutes".  Actually it means "start at 9 minutes" and "end at 27 minutes".  In other words "endpos" doesn't work as I believe it should and here's why from the mencoder manual:

  -endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see -ss and -sb)
              Stop at given time or byte position.
              NOTE: Byte position is enabled only for MEncoder and will not be accurate, as it  can  only  stop  at  a
              frame  boundary.   When  used in conjunction with -ss option, -endpos time will shift forward by seconds
              specified with -ss.

So what the manual means is that endpos is relative to ss.  That means if you say you "start at 5 minutes" and "end at 9 minutes", you're actually saying 5 minutes + 9 minutes = end at 14 minutes.   So you can see that mencoder isn't ignoring you, it just takes the start position and adds the end position value and that is what ultimately becomes the endpos.  I don't agree with that, mencoder is a great tool but I think this stumps a lot of people because it doesn't make sense.

Split 9 minutes of video from the end

mencoder -ss 00:18:00 -ovc copy -oac copy inputfile.xvid -o outputfile.xvid

*This is cheating again by just specifying the start, it will take everything from the start point until the video finishes.

In essence you're specifying "-endpos 00:27:00" assuming the movie ends at 27 minutes, but you get the idea.


Tags:

mencoder, linux, cli, editing, encode, xvid, multiple, partsmencoder, format, canon, reduced, manual, filename, avi, ovc, oac, mp, xvidencopts, fixed_quant, output, endpos, inputfile, outputfile, specifying, quot, ss, defaults, tricky, documented, portion, videon, unintuitive, ignoring, isn, doesn, hh, kb, mb, sb, byte, enabled, accurate, boundary, conjunction, specified, relative, adds, ultimately, stumps, finishes, essence,

Latest Articles

  • How to install Windows or other OS and then bring to another computer by using a physical drive and Virtual Machine with QEMU
  • PXE-E23 Error BOOTx64.EFI GRUB booting is 0 bytes tftp pxe dhcp solution NBP filesize is 0 Bytes
  • vagrant install on Debian Mint Ubuntu Linux RHEL Quick Setup Guide Tutorial
  • RHEL 8 CentOS 8, Alma Linux 8, Rocky Linux 8 System Not Booting with RAID or on other servers/computers Solution for dracut and initramfs missing kernel modules
  • How to Upgrade to Debian 11 from Version 8,9,10
  • Ubuntu Linux Mint Debian Redhat Cannot View Files on Android iPhone USB File Transfer Not Working Solution
  • Virtualbox Best Networking Mode In Lab/Work Environment without using NAT Network or Bridged
  • debootstrap how to install Ubuntu, Mint, Debian install
  • Linux grub not using UUID for the root device instead it uses /dev/sda1 or other device name solution
  • How To Restore Partition Table on Running Linux Mint Ubuntu Debian Machine
  • Debian Ubuntu apt install stop daemon questions/accept the default action without prompting
  • iptables NAT how to enable PPTP in newer Debian/Ubuntu/Mint Kernels Linux
  • Grandstream Phone Vulnerability Security Issue Remote Backdoor Connection to 207.246.119.209:3478
  • Linux How to Check Which NIC is Onboard eth0 or eth1 Ubuntu Centos Debian Mint
  • VboxManage VirtualBox NAT Network Issues Managment Troubleshooting
  • Dell PowerEdge Server iDRAC Remote KVM/IP Default Username, Password Reset and Login Information Solution
  • Nvidia Tesla GPUs K40/K80/M40/P40/P100/V100 at home/desktop hacking, cooling, powering, cable solutions Tutorial AIO Solutions
  • Stop ls in Linux Debian Mint CentOS Ubuntu from applying quotes around filenames and directory names
  • Thunderbird Attachment Download Error Corrupt Wrong filesize of 29 or 27 bytes Solution
  • Generic IP Camera LAN Default IP Settings DVR