Skip to content

Commit 3fcad71

Browse files
committed
fixed bug with closing a video filter - we need to only close the next sink after all incoming sources are closed
1 parent 70dfa1a commit 3fcad71

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

source/ffmpeg-cpp/ffmpeg-cpp/Frame Sinks/VideoFilter.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ namespace ffmpegcpp
7878
this->timeBase = timeBase;
7979
}
8080

81+
AVRational* frameRate = timeBase;
82+
8183
/* buffer video source: the decoded frames from the decoder will be inserted here. */
8284
AVPixelFormat pixelFormat = (AVPixelFormat)frame->format;
8385
snprintf(args, sizeof(args),
84-
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
86+
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d:frame_rate=%d/%d",
8587
frame->width, frame->height, frame->format,
8688
timeBase->num, timeBase->den,
87-
frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den);
89+
frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
90+
frameRate->den, frameRate->num);
8891

8992
char bufferString[1000];
9093
snprintf(bufferString, sizeof(bufferString), "buffer=%s [in_%d]; ", args, i+1);
@@ -211,9 +214,19 @@ namespace ffmpegcpp
211214
int ret = av_buffersrc_add_frame_flags(bufferSources[streamIndex], NULL, AV_BUFFERSRC_FLAG_KEEP_REF);
212215
PollFilterGraphForFrames();
213216

214-
// close our target as well
215-
target->Close();
217+
// close this input
218+
inputs[streamIndex]->Close();
216219

220+
// close our target only if all inputs are closed
221+
bool allClosed = true;
222+
for (int i = 0; i < inputs.size(); ++i)
223+
{
224+
if (!inputs[i]->IsClosed()) allClosed = false;
225+
}
226+
if (allClosed)
227+
{
228+
target->Close();
229+
}
217230
}
218231

219232
void VideoFilter::PollFilterGraphForFrames()

source/ffmpeg-cpp/ffmpeg-cpp/Frame Sinks/VideoFilterInput.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@ namespace ffmpegcpp
7575

7676
return true;
7777
}
78+
79+
void VideoFilterInput::Close()
80+
{
81+
closed = true;
82+
}
83+
84+
bool VideoFilterInput::IsClosed()
85+
{
86+
return closed;
87+
}
7888
}

source/ffmpeg-cpp/ffmpeg-cpp/Frame Sinks/VideoFilterInput.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ namespace ffmpegcpp
1515
void WriteFrame(AVFrame* frame, AVRational* timeBase);
1616

1717
bool HasFrame();
18+
bool IsClosed();
1819
bool FetchFrame(AVFrame** frame, AVRational** timeBase);
1920
bool PeekFrame(AVFrame** frame, AVRational** timeBase);
2021

22+
void Close();
23+
2124

2225
private:
2326

2427
AVFifoBuffer *frame_queue;
2528
AVRational* timeBase;
2629

2730
bool frameReceived = false;
31+
bool closed = false;
2832
};
2933

3034

0 commit comments

Comments
 (0)