Skip to content

Commit

Permalink
Fix wav audio recording
Browse files Browse the repository at this point in the history
Always use `av_wrte_trailer()` even for audio recordings, because an
invalid wav file was generated otherwise.
  • Loading branch information
Aikku93 committed Jan 24, 2024
1 parent f915ec5 commit 2ad7dd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/common/ffmpeg.cpp
Expand Up @@ -339,34 +339,34 @@ recording::MediaRet recording::MediaRecorder::Record(const char *fname, int widt
ret = setup_common(fname);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
// video stream
ret = setup_video_stream_info(width, height, depth);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
ret = setup_video_stream(width, height);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
// audio stream
ret = setup_audio_stream();
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
// last details
ret = finish_setup(fname);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
return MRET_OK;
Expand Down Expand Up @@ -409,12 +409,12 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint8_t *vid)
return MRET_OK;
}

void recording::MediaRecorder::Stop()
void recording::MediaRecorder::Stop(bool initSuccess)
{
if (oc)
{
// write the trailer; must be called before av_codec_close()
if (!audioOnlyRecording)
if (initSuccess) // only call av_write_trailer() if initialization went ok
av_write_trailer(oc);
}
isRecording = false;
Expand Down Expand Up @@ -521,21 +521,21 @@ recording::MediaRet recording::MediaRecorder::Record(const char *fname)
ret = setup_common(fname);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
// audio stream
ret = setup_audio_stream();
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
// last details
ret = finish_setup(fname);
if (ret != MRET_OK)
{
Stop();
Stop(false);
return ret;
}
return MRET_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/common/ffmpeg.h
Expand Up @@ -67,7 +67,7 @@ class MediaRecorder
// start audio only
MediaRet Record(const char *fname);
// stop both
void Stop();
void Stop(bool initSuccess = true);
bool IsRecording()
{
return isRecording;
Expand Down

0 comments on commit 2ad7dd1

Please sign in to comment.