What is refFrames and what to do when this value does not match Davinci Resolve

Started by x2abc33d, April 04, 2020, 11:12:38 PM

Previous topic - Next topic

x2abc33d

I'm trying to use Avidemux to split an H.264 video recorded by OBS, edit some parts with Davinci Resolve, export them back with H.264 and combine the parts with Avidemux again. The goal is to avoid re-encoding the untouched parts both to save on time (still not quite a lost cause by now since I might be doing this to future videos) and to avoid degrading the quality to a reasonable extent.
I made sure to do all of my cuts on I-frames, but when trying to combine even one original and one edited clip I ran into the generic "Codec or codec settings across a cut point of the pasted video do not match" error. After scouring the log file I noticed:

[ADM_Composer::checkSegmentStartsOnIntra] 21:28:52-961 refFrames value does not match.
[ADM_Composer::checkSegmentStartsOnIntra] 21:28:52-961 SPS mismatch, saved video will be broken.


If this is indeed the cause of the error, could someone please tell me if refFrames have something to do with the number of look-back frames for B-frames? (I can't find any similarly named properties in ffmpeg -show_streams output, for example)

Could someone suggest a potential fixes for the mis-match problem? As far as I can tell Davinci only lets me enable or disable "Frame reordering" (which I guess is related to B-frames), (not anything more detailed like the bf and b_depth options in libx264 http://ffmpeg.org/ffmpeg-codecs.html#libx264_002c-libx264rgb). When I disable "Frame reordering" I get more mismatches:

[ADM_Composer::checkSegmentStartsOnIntra] 22:10:18-047 hasPocInfo value does not match.
[ADM_Composer::checkSegmentStartsOnIntra] 22:10:18-047 log2MaxPocLsb value does not match.
[ADM_Composer::checkSegmentStartsOnIntra] 22:10:18-047 refFrames value does not match.
[ADM_Composer::checkSegmentStartsOnIntra] 22:10:18-047 SPS mismatch, saved video will be broken.

Perhaps there's a way to re-encode the Davinci output to match what the unedited clips that I've got?

ffmprobe -show_stream info for an unedited clip:
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=8464031/1015687500
codec_tag_string=avc1
codec_tag=0x31637661
width=1920
height=1080
coded_width=1920
coded_height=1088
has_b_frames=1
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=42
color_range=tv
color_space=bt470bg
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=60/1
avg_frame_rate=507843750/8464031
time_base=1/62500
start_pts=2000
start_time=0.032000
duration_ts=16928062
duration=270.848992
bit_rate=46259114
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=16251
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=VideoHandler


ffmprobe -show_stream info for the Davinci Resolve output:
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1/120
codec_tag_string=avc1
codec_tag=0x31637661
width=1920
height=1080
coded_width=1920
coded_height=1088
has_b_frames=1
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=42
color_range=tv
color_space=bt709
color_transfer=unknown
color_primaries=bt709
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=60/1
avg_frame_rate=60/1
time_base=1/15360
start_pts=0
start_time=0.000000
duration_ts=82176
duration=5.350000
bit_rate=51687869
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=321
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=VideoHandler

eumagga0x2a

If a H.264 stream was produced with libx264, it is very likely that a SEI message with x264 encoder parameters is present in the first access unit of the stream. When saving in copy mode not from the first keyframe of a video, Avidemux looks for this SEI message and injects it into the stream as FFmpeg uses it to apply some quirks: https://github.com/mean00/avidemux2/blob/master/avidemux/common/ADM_muxerGate/src/ADM_videoCopySeiInjector.cpp

This info might allow to fine-tune x264 to produce compatible output.

eumagga0x2a

To address the question about reference frames, if I am not completely off, this parameter equals the maximum length of the list of already decoded pictures which a later P-frame may depend on. A B-frame uses two lists (forward and backward references), which means that the total maximum number of references for a B-frame equals 2*refFrames.

QuoteAs far as I can tell Davinci only lets me enable or disable "Frame reordering" (which I guess is related to B-frames)

Correct, no frame reordering = no B-frames.