[FFmpeg-user] FLV to MP4 - negative CTS

Alexander Bokovikov openworld at uralweb.ru
Wed Apr 18 12:34:02 CEST 2012

Hi, All,

Am using FFMPEG from today's Git.

Could anybody explain it to me how to fix the problem:
For some reason the video source provides H264 FLV stream with some negative
CTS. So, "CompositionTime" field in the AVC frame header in FLV has negative
24-bit values like FFFFBE, which is -66, as far as I believe. FFMPEG can't
process such values when I try to use "copy" mode for both vcodec and acodec
parameters. An error message appears saying about incorrect parameter and

DTS 35, next:100366 st:0 invalid dropping
PTS 35, next:100366 invalid dropping st:0
[mp4 @ 0x803220] pts has no value
DTS 67, next:133732 st:0 invalid dropping
[mp4 @ 0x803220] pts (101) < dts (134) in stream 0
av_interleaved_write_frame(): Invalid argument

Then I've tried to use "copy" mode for the audio track only, but have used
usual libx264 paramters for the video:

-vcodec libx264 -preset medium -crf 23

Now I see another situation: conversion goes up to the end, but with many
warning lines like this:

[flv @ 0x802c20] negative cts, previous timestamps might be wrong

Nevertheless I don't see a visible A/V missynch. At least I'm not sure if it
appears or not.

I also tried to use both audio and video track re-encoding with libx264 +
libvo_aacenc. None of errors appear in this case, but I'm not sure if a/v
synch is correct. It looks like there is a little missynch (less then 1 sec)
which doesn't grow with time.

I'm writing a tool to fix this movie. Could anybody suggest what to do with
the negative CTS values in FLV? For example, am I correct in my
understanding, that negative CTS means that this frame should stand at some
earlier position in the FLV stream, but for some unknown reason it couldn't
be inserted at that proper time, so it was inserted here, but with the
negative CTS? If so, then would it be correct to shift this frame back in
timeline to the value of its CTS (in absolute value) and set CTS value to
zero? Or is there any correct way to eliminate negative CTS values?

The short FLV example is here:

Thank you.

More information about the ffmpeg-user mailing list