[FFmpeg-user] Problem concatenating segments

George R. Welch george at grwelch.com
Fri Jan 24 18:24:13 EET 2020


Greetings,

I get video files from another division.  It is my task to cut out a 
part of the video, and replace it with a part I create.  The videos I 
receive are h264 with aac audio.  It is very strongly hoped that this 
can be done without re-encoding the parts of the original which we keep.

I have been using ffmpeg for cutting up the file I receive, and I've 
been using the concat demuxer to concatenate the pieces of the original 
with the part I make.  This has worked well (over a dozen times) until 
recently.

In order for concat to work correctly, I take care to make sure the 
video I make fits the one I am inserting it into (same frame rate, refs, 
etc).  I also take care to only cut the original movie at I frames.

I have run into trouble with the most recent job.  When I concatenate 
the parts, there is a slight glitch when it transitions from the part I 
made to the other.

As far as I can tell, the only thing that is different from the previous 
runs is that the file I am given is encoded with B frames, whereas that 
had never happened before.

An oddity is that when I cut the original video, the timestamp does not 
begin at zero:

$ ffmpeg -i input.mkv -ss [start-time] -t [duration] -c copy part1.mkv
[seems to work]

Now look at the result:

$ ffprobe -hide_banner -show_frames -select_streams v part1.mkv

Here is the first frame:

[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=1968
pkt_pts_time=1.968000
pkt_dts=1968
pkt_dts_time=1.968000
best_effort_timestamp=1968
best_effort_timestamp_time=1.968000
...

I don't understand why the first frame does not start at zero.  I have 
tried adding "-seek_timestamp 1" but it has no effect.

When I use concat to place this part after my video, then there is a 
glitch at the transition.

However, if I change the flag to the input:

$ ffmpeg -ss [start-time] -i input.mkv -t [duration] -c copy part1.mkv

then ffmpeg generates some errors:

[matroska @ 0x7ffadb028600] failed to avoid negative pts -58 in stream 1.
Try -avoid_negative_ts 1 as a possible workaround.

Repeating the command with -avoid -avoid_negative_ts 1 still generates 
the same message, and the output is the same.

Now when I look at the first frame it does start at zero, but there is 
still a glitch at the transition after concatenating.

Does anyone have any suggestions?  Is it impossible to concat segments 
with B frames?

Thank you in advance,

--George



More information about the ffmpeg-user mailing list