How do you splice out a part of an xvid encoded avi file, with ffmpeg? (no problems with other files)

Im using the following command, which works for most files, except what seems to be xvid encoded ones

/usr/bin/ffmpeg -sameq -i file.avi -ss 00:01:00 -t 00:00:30 -ac 2 -r 25 -copyts output.avi

So this should basically splice out 30 seconds of video + audio, starting from 1 minute mark.

It does START encoding at the 00:01:00 mark but it goes all the way to the end of the file for some reason, ignoring that I want just 30 seconds.

The output looks like this.

FFmpeg version git-ecc4bdd, Copyright (c) 2000-2010 the FFmpeg developers
  built on May 31 2010 04:52:24 with gcc 4.4.3 20100127 (Red Hat 4.4.3-4)
  configuration: --enable-libx264 --enable-libxvid --enable-libmp3lame --enable-libopenjpeg --enable-libfaac --enable-libvorbis --enable-gpl --enable-nonfree --enable-libxvid --enable-pthreads --enable-libfaad --extra-cflags=-fPIC --enable-postproc --enable-libtheora --enable-libvorbis --enable-shared
  libavutil     50.15. 2 / 50.15. 2
  libavcodec    52.67. 0 / 52.67. 0
  libavformat   52.62. 0 / 52.62. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.20. 0 /  1.20. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
[mpeg4 @ 0x17cf770]Invalid and inefficient vfw-avi packed B frames detected
Input #0, avi, from 'file.avi':
  Metadata:
    ISFT            : VirtualDubMod 1.5.10.2 (build 2540/release)
  Duration: 00:02:00.00, start: 0.000000, bitrate: 1587 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 672x368 [PAR 1:1 DAR 42:23], 25 tbr, 25 tbn, 25 tbc
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
File 'lol6.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to 'lol6.avi':
  Metadata:
    ISFT            : Lavf52.62.0
    Stream #0.0: Video: mpeg4, yuv420p, 672x368 [PAR 1:1 DAR 42:23], q=2-31, 200 kb/s, 25 tbn, 25 tbc
    Stream #0.1: Audio: mp2, 48000 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
[mpeg4 @ 0x17cf770]Invalid and inefficient vfw-avi packed B frames detected
[buffer @ 0x184b610]Buffering several frames is not supported. Please consume all available frames before adding a new one.
frame= 1501 fps=104 q=0.0 Lsize=   15612kB time=30.02 bitrate=4259.7kbits/s    ts/s
video:15303kB audio:235kB global headers:0kB muxing overhead 0.482620%

if I convert this file to mp4 for example, and then perform the same action, it works perfectly.


I presume your "convert to MP4" operation is just a container change, not a full re-encode of the A/V data streams. So perhaps FFmpeg is getting hung up on something broken in those AVI containers. This line in your output might support this:

[mpeg4 @ 0x17cf770]Invalid and inefficient vfw-avi packed B frames detected

You could try creating a new AVI container -- let FFmpeg copy the entire file, eg with:

ffmpeg -i input.avi -vcodec copy -acodec copy output.avi

This should create a new AVI container and copy the data streams. Then try your command again. If it works, you've got broken AVIs (or possibly an FFmpeg bug) -- either way, you can put all your videos into new AVI containers and get it done that way.

If that doesn't work, you might look further into the broken XviDs and see what they have in common.


I wonder if your problem is the same as in this article:
Convert any video file for an iPod or iPhone

You want to use your fancy new Apple iPod Video or Apple iPhone, but you don't know how to convert video so it will play.

Ubuntu 9.10 (Karmic Koala) ships with a version of ffmpeg without libfaac support because of licensing issues. This means you will need to compile ffmpeg yourself. This guide explains how.

The article explains, step-by-step, how to compile ffmpeg by hand or create a modified ffmpeg package, that includes libfaac to support Advanced Audio Coding (AAC).