You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	af_aresample: Fix timestamp of first padded PCM audio packet
Problem: ffmpeg generated video file which had two audio packets with the same timestamp: last original audio packet and first padded audio packet. Timestamp of first added audio packet by 'apad' fitler had the same value as last original audio packet. The problem was in 'aresample' fitler, which used next pts instead of current one. As long as 'apad' and 'aresample' filters have separate mechanisms of timestamp calculation, they got the same values. Command line: ffmpeg -i <input_filename> -shortest -apad 512 -af asetnsamples=n=512 -b:a 1058400 -ac 1 -ar 44100 -async 0 -acodec pcm_s16le -sn -f matroska -y <output_file> Fix: Call swr_next_pts() function before swr_convert() Tested: FATE tests passed. Fix has been tested in our Transcoder regression framework on ~10k test videos. It's about ~500k transcodes. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
		
				
					committed by
					
						 Michael Niedermayer
						Michael Niedermayer
					
				
			
			
				
	
			
			
			
						parent
						
							995f450b44
						
					
				
				
					commit
					86b3435fc0
				
			| @@ -230,10 +230,15 @@ static int request_frame(AVFilterLink *outlink) | |||||||
|     if (ret == AVERROR_EOF) { |     if (ret == AVERROR_EOF) { | ||||||
|         AVFrame *outsamplesref; |         AVFrame *outsamplesref; | ||||||
|         int n_out = 4096; |         int n_out = 4096; | ||||||
|  |         int64_t pts; | ||||||
|  |  | ||||||
|         outsamplesref = ff_get_audio_buffer(outlink, n_out); |         outsamplesref = ff_get_audio_buffer(outlink, n_out); | ||||||
|         if (!outsamplesref) |         if (!outsamplesref) | ||||||
|             return AVERROR(ENOMEM); |             return AVERROR(ENOMEM); | ||||||
|  |  | ||||||
|  |         pts = swr_next_pts(aresample->swr, INT64_MIN); | ||||||
|  |         pts = ROUNDED_DIV(pts, inlink->sample_rate); | ||||||
|  |  | ||||||
|         n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, 0, 0); |         n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, 0, 0); | ||||||
|         if (n_out <= 0) { |         if (n_out <= 0) { | ||||||
|             av_frame_free(&outsamplesref); |             av_frame_free(&outsamplesref); | ||||||
| @@ -242,14 +247,8 @@ static int request_frame(AVFilterLink *outlink) | |||||||
|  |  | ||||||
|         outsamplesref->sample_rate = outlink->sample_rate; |         outsamplesref->sample_rate = outlink->sample_rate; | ||||||
|         outsamplesref->nb_samples  = n_out; |         outsamplesref->nb_samples  = n_out; | ||||||
| #if 0 |  | ||||||
|         outsamplesref->pts = aresample->next_pts; |         outsamplesref->pts = pts; | ||||||
|         if(aresample->next_pts != AV_NOPTS_VALUE) |  | ||||||
|             aresample->next_pts += av_rescale_q(n_out, (AVRational){1 ,outlink->sample_rate}, outlink->time_base); |  | ||||||
| #else |  | ||||||
|         outsamplesref->pts = swr_next_pts(aresample->swr, INT64_MIN); |  | ||||||
|         outsamplesref->pts = ROUNDED_DIV(outsamplesref->pts, inlink->sample_rate); |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|         return ff_filter_frame(outlink, outsamplesref); |         return ff_filter_frame(outlink, outsamplesref); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user