Small pieces of video split by ffmpeg are not playing or playing with artifacts

1

1

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?

Rnd_d

Posted 2011-11-14T11:56:53.653

Reputation: 133

Answers

3

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.

slhck

Posted 2011-11-14T11:56:53.653

Reputation: 182 472

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 – 2011-11-14T14:45:49.500

@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 – 2011-11-14T14:47:55.130

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 – 2011-11-14T16:41:58.297

You're welcome! If you have any questions about the flags FFmpeg and libx264 use, there's a good guide here.

– slhck – 2011-11-14T21:38:38.470