Message ID | 20220223150355.944-2-jamrial@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,1/4,v2] ffmpeg: flush delayed frames in codec copy scenarios | expand |
Quoting James Almer (2022-02-23 16:03:53) > A keyframe could be buffered in the bsf and not be output until more packets > had been fed to it. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > Changed the check from pkt to !eof, since a packet is always provided. > > fftools/ffmpeg.c | 4 +++- > fftools/ffmpeg.h | 1 + > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c > index 44043ef203..2b61c0d5aa 100644 > --- a/fftools/ffmpeg.c > +++ b/fftools/ffmpeg.c > @@ -890,6 +890,8 @@ static void output_packet(OutputFile *of, AVPacket *pkt, > > /* apply the output bitstream filters */ > if (ost->bsf_ctx) { > + if (!eof && pkt->flags & AV_PKT_FLAG_KEY) > + ost->seen_kf = 1; Shouldn't this also be set when no bsfs are used?
On 3/31/2022 8:47 AM, Anton Khirnov wrote: > Quoting James Almer (2022-02-23 16:03:53) >> A keyframe could be buffered in the bsf and not be output until more packets >> had been fed to it. >> >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> Changed the check from pkt to !eof, since a packet is always provided. >> >> fftools/ffmpeg.c | 4 +++- >> fftools/ffmpeg.h | 1 + >> 2 files changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c >> index 44043ef203..2b61c0d5aa 100644 >> --- a/fftools/ffmpeg.c >> +++ b/fftools/ffmpeg.c >> @@ -890,6 +890,8 @@ static void output_packet(OutputFile *of, AVPacket *pkt, >> >> /* apply the output bitstream filters */ >> if (ost->bsf_ctx) { >> + if (!eof && pkt->flags & AV_PKT_FLAG_KEY) >> + ost->seen_kf = 1; > > Shouldn't this also be set when no bsfs are used? Afaict only in streamcopy with bsfs scenarios can packets be temporarily withheld, so it's not necessary.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 44043ef203..2b61c0d5aa 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -890,6 +890,8 @@ static void output_packet(OutputFile *of, AVPacket *pkt, /* apply the output bitstream filters */ if (ost->bsf_ctx) { + if (!eof && pkt->flags & AV_PKT_FLAG_KEY) + ost->seen_kf = 1; ret = av_bsf_send_packet(ost->bsf_ctx, eof ? NULL : pkt); if (ret < 0) goto finish; @@ -2035,7 +2037,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p } if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && - !ost->copy_initial_nonkeyframes) + !ost->copy_initial_nonkeyframes && !ost->seen_kf) return; if (!ost->frame_number && !ost->copy_prior_start) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 82f3db6b6d..6a19dc9c7c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -534,6 +534,7 @@ typedef struct OutputStream { int inputs_done; const char *attachment_filename; + int seen_kf; int copy_initial_nonkeyframes; int copy_prior_start; char *disposition;
A keyframe could be buffered in the bsf and not be output until more packets had been fed to it. Signed-off-by: James Almer <jamrial@gmail.com> --- Changed the check from pkt to !eof, since a packet is always provided. fftools/ffmpeg.c | 4 +++- fftools/ffmpeg.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)