Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Having an MPEG4 (MP4 container, H264 AVC video, AAC audio) video clip downloaded from YouTube, how to crop a particular piece of it (remove everything before a particular starting point timestamp an after a particular finish point timestamp) with free Linux tools?

PS: I don't mind employing a patented or even a BLOB codec library.

share|improve this question
    
Does the fact that it's from YouTube matter somehow? –  Michael Mrozek Apr 11 '12 at 19:13
    
I don't think so, but I am not sure. I've specified it for my question to be more precise and the example to be more practical. As far as I know codecs and containers are a messy subject with tons of variations and incompatible implementations, so, maybe, it does matter. –  Ivan Apr 11 '12 at 19:19
add comment

1 Answer

up vote 2 down vote accepted

You can use mencoder (in your distribution, it should come in the package mplayer). If you wanted to extract 3 minutes starting at 21:50, you would do

mencoder -ss 21:50 -endpos 3:00 your-video.mp4 -o output.mp4 -oac copy -ovc copy

It's not exact: the starting point will be adjusted to the beginning of a frame. It's possible to work around this, if it's a problem (usually it isn't).

share|improve this answer
    
mencoder: Symbol `ff_codec_bmp_tags' has different size in shared object, consider re-linking MEncoder SVN-r33713-4.6.1 (C) 2000-2011 MPlayer Team -endpoint is not an MEncoder option –  Ivan Apr 11 '12 at 21:26
    
Sorry, it's endpos. My mistake. -- Fixed. –  angus Apr 11 '12 at 21:58
    
It worked, but... 1. Audio format 0x4134504d is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it (I've used PCM succesfully) 2. WARNING: OUTPUT FILE FORMAT IS _AVI_ - seriously? –  Ivan Apr 11 '12 at 22:48
1  
AVI is the default. See mencoder -of help for a list of available output formats. In any case, you could extract audio and video separately (-novideo or -ovc null, -nosound or -oac null) and then put them together using another tool, like mkvmerge. –  angus Apr 12 '12 at 10:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.