Skip to content

Commit

Permalink
Merge pull request #2 from Sappharad/master
Browse files Browse the repository at this point in the history
Do not delete the original file when MP4Optimize fails!!!
  • Loading branch information
dgilman committed Dec 15, 2019
2 parents a0ca7a0 + dec0364 commit 9344079
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions aacgain/aacgain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,15 +817,21 @@ int aac_close(AACGainHandle gh)
{
//use MP4Optimize to undo the wasted space created by MP4File::Modify
//send optimize output to a temp file "just in case"
MP4Optimize(gd->temp_name, temp_name);

//rename the temp file back to original name
int rc = remove(gd->mp4file_name);
if (rc == 0)
rc = rename(temp_name, gd->mp4file_name);
if (rc)
fprintf(stderr, "Error: attempt to create file %s failed. Your output file is named %s",
gd->mp4file_name, temp_name);
if(MP4Optimize(gd->temp_name, temp_name)){
//rename the temp file back to original name
int rc = remove(gd->mp4file_name);
if (rc == 0)
rc = rename(temp_name, gd->mp4file_name);
if (rc)
fprintf(stderr, "Error: attempt to create file %s failed. Your output file is named %s",
gd->mp4file_name, temp_name);
}
else{
//Optimize failed, keep the originals and remove temp files.
//The unoptimized temp file does not play in the app I tried it with, so you will not want it anyway.
fprintf(stderr, "Error: attempt to optimize file %s failed. The file was not modified.", gd->mp4file_name);
remove(temp_name); //Probably does not exist, but no harm in trying to remove it.
}
free((void*)temp_name);
}
remove(gd->temp_name);
Expand Down

0 comments on commit 9344079

Please sign in to comment.