Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c76ec67

Browse files
committed
fix issue #17 : audio pts is wrong cause sample video playing slowly
1 parent bc60218 commit c76ec67

File tree

8 files changed

+11
-6
lines changed

8 files changed

+11
-6
lines changed

‎FFmpegTutorial/Classes/0x33/FFTPlayer0x33.m‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ - (void)readPacketsFunc
352352
_videoFrameQueue.averageDuration = (_videoDecoder.frameRate.num && _videoDecoder.frameRate.den ? av_q2d(_videoDecoder.frameRate) : 0);
353353

354354
_audioFrameQueue = [[FFTAudioFrameQueue alloc] init];
355+
_audioFrameQueue.streamTimeBase = av_q2d(_audioDecoder.stream->time_base);
355356

356357
mr_sync_main_queue(^{
357358
//audio queue 不能跨线程,不可以在子线程创建,主线程play。audio unit 可以

‎FFmpegTutorial/Classes/0x34/FFTPlayer0x34.m‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ - (void)readPacketsFunc
357357
_videoFrameQueue.averageDuration = (_videoDecoder.frameRate.num && _videoDecoder.frameRate.den ? av_q2d(_videoDecoder.frameRate) : 0);
358358

359359
_audioFrameQueue = [[FFTAudioFrameQueue alloc] init];
360+
_audioFrameQueue.streamTimeBase = av_q2d(_audioDecoder.stream->time_base);
361+
360362
_duration = 1.0 * formatCtx->duration / AV_TIME_BASE;
361363
[dumpDic setObject:@(_duration) forKey:kFFTPlayer0x34Duration];
362364

‎FFmpegTutorial/Classes/0x35/FFTPlayer0x35.m‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ - (void)readPacketsFunc
365365
_videoFrameQueue.averageDuration = (_videoDecoder.frameRate.num && _videoDecoder.frameRate.den ? av_q2d(_videoDecoder.frameRate) : 0);
366366

367367
_audioFrameQueue = [[FFTAudioFrameQueue alloc] init];
368+
_audioFrameQueue.streamTimeBase = av_q2d(_audioDecoder.stream->time_base);
369+
368370
_videoClk = [[FFTSyncClock alloc] init];
369371
_audioClk = [[FFTSyncClock alloc] init];
370372

‎FFmpegTutorial/Classes/0x36/FFTPlayer0x36.m‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ - (void)readPacketsFunc
350350
_videoFrameQueue.averageDuration = (_videoDecoder.frameRate.num && _videoDecoder.frameRate.den ? av_q2d(_videoDecoder.frameRate) : 0);
351351

352352
_audioFrameQueue = [[FFTAudioFrameQueue alloc] init];
353+
_audioFrameQueue.streamTimeBase = av_q2d(_audioDecoder.stream->time_base);
354+
353355
_videoClk = [[FFTSyncClock alloc] init];
354356
_videoClk.name = @"video";
355357
_audioClk = [[FFTSyncClock alloc] init];

‎FFmpegTutorial/Classes/common/FFTAudioFrameQueue.m‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ - (void)enQueue:(AVFrame *)frame
2323
FFFrameItem *item = [[FFFrameItem alloc] initWithAVFrame:frame];
2424

2525
if (frame->pts != AV_NOPTS_VALUE) {
26-
AVRational tb = (AVRational){1, frame->sample_rate};
27-
item.pts = frame->pts * av_q2d(tb);
26+
item.pts = frame->pts * self.streamTimeBase;
2827
}
2928

3029
item.duration = av_q2d((AVRational){frame->nb_samples, frame->sample_rate});

‎FFmpegTutorial/Classes/common/FFTFrameQueue.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct AVFrame AVFrame;
2424
@interface FFTFrameQueue : NSObject
2525

2626
@property (nonatomic, assign) BOOL eof;
27+
@property (nonatomic, assign) double streamTimeBase;
2728

2829
- (void)push:(FFFrameItem *)frame;
2930
- (void)pop;

‎FFmpegTutorial/Classes/common/FFTPlayerHeader.m‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ enum AVPixelFormat MRPixelFormat2AV (MRPixelFormat mrpf){
205205
int audio_buffer_size(AVFrame *frame)
206206
{
207207
const int fmt = frame->format;
208-
int chanels = av_sample_fmt_is_planar(fmt) ? 1 : 2;
209-
//self.frame->linesize[i] 比 data_size 要大,所以有杂音
210-
int data_size = av_samples_get_buffer_size(frame->linesize, chanels, frame->nb_samples, fmt, 1);
208+
int chanels = frame->ch_layout.nb_channels;
209+
int data_size = av_samples_get_buffer_size(NULL, chanels, frame->nb_samples, fmt, 1);
211210
return data_size;
212211
}

‎FFmpegTutorial/Classes/common/FFTVideoFrameQueue.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ NS_ASSUME_NONNULL_BEGIN
1111

1212
@interface FFTVideoFrameQueue : FFTFrameQueue
1313

14-
@property (nonatomic, assign) double streamTimeBase;
1514
//根据 fps 计算得出
1615
@property (nonatomic, assign) double averageDuration;
1716

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /