Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to cut a video file into small parts (0.5-5s) and encode these parts to h.264/aac with ffmpeg. I'm using this command:

ffmpeg -i 1.avi -ss 00:05:00 -t 00:00:01,50 -vcodec libx264 -threads 0 -vpre default -acodec libfaac out1.mp4

In VLC, some pieces are playing without video, sound only, other pieces had video artifacts like this:

enter image description here

Maybe I missed some necessary arguments for ffmpeg?

share|improve this question
up vote 3 down vote accepted

I tried it with FFmpeg version 0.8.5, using an AVI input file just like you.

The following command produced correct results:

ffmpeg -i 1.avi -ss 00:00:05 -t 00:00:01.50 -vcodec libx264 -vpre default -acodec libfaac out1.mp4

Here are some tips to get it working:

Update to the latest version of FFmpeg.

For Ubuntu, follow the tutorials here. I've been using them myself.

On OS X, install FFmpeg using Homebrew, by calling brew install ffmpeg.

On Windows, just download the precompiled versions.

Use the correct length format.

Note that the duration format is using decimal points, not commas, e.g. hh:mm:ss[.xxx].

Remove the -threads 0 option.

Enabling -threads 0 however gave me the error "nal buffer is too small". I don't even know why they allow a value of zero here, and unless you have a specific reason to do so, I would just leave this argument out. Ideally, it should enable auto-threads in libx264, but there might be a bug I'm not aware of.

Encode without B-pictures.

Depending on the size of the output video, I don't know if libx264 is even able to reliably produce output using B-pictures that reference one or more intra-coded pictures. This might even lead to the artifacts you describe.

You can try to disable B-pictures (or "B-frames") with -bf 0.

share|improve this answer
Thank you for your response. My ffmpeg version is 0.5.1, it's from ubuntu reps =(. Are you compiled ffmpeg yourself? I will try to cut my video considering your advice. – Rnd_d Nov 14 '11 at 14:45
@Rnd_d Yes, I did. It would make sense to re-compile from source, which isn't that hard on Ubuntu. There are excellent tutorials here, just make sure you open the one for your Ubuntu version. I've been using these tutorials to compile all FFmpeg versions I'm using for Ubuntu. – slhck Nov 14 '11 at 14:47
Thank you very very much! I've compiled last version of ffmpeg usgin tutorials you considered. Quality of encoded video and audio has improved! Disabling b-frames actually got rid of artifacts. – Rnd_d Nov 14 '11 at 16:41
You're welcome! If you have any questions about the flags FFmpeg and libx264 use, there's a good guide here. – slhck Nov 14 '11 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .