Skip to content

Commit

Permalink
Fixed AV when closing a copy never or corrupted video stream that was…
Browse files Browse the repository at this point in the history
… never able to be opened
  • Loading branch information
Craig Moksnes committed Sep 3, 2020
1 parent a8adbed commit 09112d6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions VideoUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TVideoConverter = class
fStreamInputDTS: TArray<Int64>;

fProgramFilter: Integer;
fFinished: Boolean;
fOpened, fFinished: Boolean;
fOnInterrupt: TVideoInterruptEvent;

function GetErrorStr(const aErrorCode: Integer): String;
Expand Down Expand Up @@ -147,6 +147,8 @@ procedure TVideoConverter.Open;
lRet := avformat_write_header(fOutputFormatContext, nil);
if lRet < 0 then
ErrorFmt('Error occurred writing output header: %s', [GetErrorStr(lRet)]);

fOpened := True;
except
on e: EVideoConverterError do
raise;
Expand Down Expand Up @@ -249,8 +251,9 @@ procedure TVideoConverter.Close;
begin
fFinished := True;
try
if Assigned(fOutputFormatContext) then
av_write_trailer(fOutputFormatContext);
if fOpened then
if Assigned(fOutputFormatContext) then
av_write_trailer(fOutputFormatContext);

// NOTE: FFMPEG code internally frees avformat context before closing avio

Expand Down

0 comments on commit 09112d6

Please sign in to comment.