Skip to content

Commit

Permalink
fix: fix export audio mute issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wlanjie committed May 13, 2020
1 parent 611bc9d commit dc262ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions library/src/main/cpp/editor/video_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,16 +909,31 @@ void VideoExport::ProcessAudioExport() {

int audio_size = 0;
// 如果是图片,或者是视频中没音频的,补空音频
if (current_media_clip_->type == IMAGE || av_play_context_->audio_index == -1) {
if (current_media_clip_->type == IMAGE) {
if (audio_current_time_ < current_media_clip_->end_time) {
audio_size = FillMuteAudio();
}
} else if (current_media_clip_->type == VIDEO) {
audio_size = Resample();
if (av_play_context_->status != PLAYING) {
// 视频文件还没打开时,等待
pthread_mutex_lock(&audio_mutex_);
pthread_cond_wait(&audio_cond_, &audio_mutex_);
pthread_mutex_unlock(&audio_mutex_);
}

if (av_play_context_->audio_index == -1) {
// 视频文件无音频的情况,补全空音频
if (audio_current_time_ < current_media_clip_->end_time) {
audio_size = FillMuteAudio();
}
} else {
audio_size = Resample();
}
}
if (export_index_ >= clip_deque_.size()) {
break;
}
// 当前视频或者补全图片的音频到时间了, 等待下一个视频
if (audio_size <= 0) {
pthread_mutex_lock(&audio_mutex_);
pthread_cond_wait(&audio_cond_, &audio_mutex_);
Expand Down Expand Up @@ -1031,7 +1046,7 @@ int VideoExport::Resample() {
}
unsigned int audio_buf1_size = 0;
int wanted_nb_sample = frame->nb_samples;
int resample_data_size;
int resample_data_size = 0;
if (swr_context_) {
const uint8_t **in = (const uint8_t **) frame->extended_data;
uint8_t **out = &audio_buf1;
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/cpp/player/av_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ int av_play_play(const char *url, float time, AVPlayContext *context) {

context->duration = context->format_context->duration / 1000;

LOGE("video duration: %lld", context->duration);
if (context->av_track_flags & VIDEO_FLAG) {
int64_t d = av_rescale_q(context->format_context->streams[context->video_index]->duration,
context->format_context->streams[context->video_index]->time_base
Expand Down Expand Up @@ -694,6 +695,7 @@ void av_play_pause(AVPlayContext* context) {
}

void av_play_seek(AVPlayContext* context, float seek_to) {
LOGE("enter: %s seek_to: %f", __func__, seek_to);
float total_time = (float) context->format_context->duration / AV_TIME_BASE;
seek_to = seek_to >= 0 ? seek_to : 0;
seek_to = seek_to <= total_time ? seek_to : total_time;
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/cpp/player/player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ int Player::Start(MediaClip* clip, int video_count_duration) {
if (window_created_) {
auto message = buffer_pool_->GetBuffer<Message>();
message->what = kPlayerStart;
message->arg1 = 0;
message->obj = current_clip_;
PostMessage(message);
}
Expand Down Expand Up @@ -1064,6 +1065,7 @@ void Player::OnGLWindowCreate() {
if (started_) {
auto message = buffer_pool_->GetBuffer<Message>();
message->what = kPlayerStart;
message->arg1 = 0;
message->obj = current_clip_;
PostMessage(message);
}
Expand Down

0 comments on commit dc262ed

Please sign in to comment.