estimate_timings_from_pts: Try to get the duration for all streams
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
		
							parent
							
								
									424599c7cc
								
							
						
					
					
						commit
						68cea1bc8e
					
				@ -2469,7 +2469,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 | 
				
			|||||||
    AVPacket pkt1, *pkt = &pkt1;
 | 
					    AVPacket pkt1, *pkt = &pkt1;
 | 
				
			||||||
    AVStream *st;
 | 
					    AVStream *st;
 | 
				
			||||||
    int read_size, i, ret;
 | 
					    int read_size, i, ret;
 | 
				
			||||||
    int64_t end_time;
 | 
					    int all_duration_valid = 0;
 | 
				
			||||||
    int64_t filesize, offset, duration;
 | 
					    int64_t filesize, offset, duration;
 | 
				
			||||||
    int retry = 0;
 | 
					    int retry = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2493,7 +2493,6 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 | 
				
			|||||||
    /* estimate the end time (duration) */
 | 
					    /* estimate the end time (duration) */
 | 
				
			||||||
    /* XXX: may need to support wrapping */
 | 
					    /* XXX: may need to support wrapping */
 | 
				
			||||||
    filesize = ic->pb ? avio_size(ic->pb) : 0;
 | 
					    filesize = ic->pb ? avio_size(ic->pb) : 0;
 | 
				
			||||||
    end_time = AV_NOPTS_VALUE;
 | 
					 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        offset = filesize - (DURATION_MAX_READ_SIZE << retry);
 | 
					        offset = filesize - (DURATION_MAX_READ_SIZE << retry);
 | 
				
			||||||
        if (offset < 0)
 | 
					        if (offset < 0)
 | 
				
			||||||
@ -2515,7 +2514,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 | 
				
			|||||||
            if (pkt->pts != AV_NOPTS_VALUE &&
 | 
					            if (pkt->pts != AV_NOPTS_VALUE &&
 | 
				
			||||||
                (st->start_time != AV_NOPTS_VALUE ||
 | 
					                (st->start_time != AV_NOPTS_VALUE ||
 | 
				
			||||||
                 st->first_dts  != AV_NOPTS_VALUE)) {
 | 
					                 st->first_dts  != AV_NOPTS_VALUE)) {
 | 
				
			||||||
                duration = end_time = pkt->pts + pkt->duration;
 | 
					                duration = pkt->pts + pkt->duration;
 | 
				
			||||||
                if (st->start_time != AV_NOPTS_VALUE)
 | 
					                if (st->start_time != AV_NOPTS_VALUE)
 | 
				
			||||||
                    duration -= st->start_time;
 | 
					                    duration -= st->start_time;
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
@ -2529,7 +2528,19 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            av_free_packet(pkt);
 | 
					            av_free_packet(pkt);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } while (end_time == AV_NOPTS_VALUE &&
 | 
					
 | 
				
			||||||
 | 
					        /* check if all audio/video streams have valid duration */
 | 
				
			||||||
 | 
					        all_duration_valid = 1;
 | 
				
			||||||
 | 
					        for (i = 0; i < ic->nb_streams; i++) {
 | 
				
			||||||
 | 
					            st = ic->streams[i];
 | 
				
			||||||
 | 
					            switch (st->codec->codec_type) {
 | 
				
			||||||
 | 
					                case AVMEDIA_TYPE_VIDEO:
 | 
				
			||||||
 | 
					                case AVMEDIA_TYPE_AUDIO:
 | 
				
			||||||
 | 
					                    if (st->duration == AV_NOPTS_VALUE)
 | 
				
			||||||
 | 
					                        all_duration_valid = 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } while (!all_duration_valid &&
 | 
				
			||||||
             offset &&
 | 
					             offset &&
 | 
				
			||||||
             ++retry <= DURATION_MAX_RETRY);
 | 
					             ++retry <= DURATION_MAX_RETRY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user