[Ffmpeg-devel] dvr-ms seek help request

Steve Lhomme slhomme
Wed Apr 19 18:32:14 CEST 2006


John Donaghy wrote:
>> Could you post this code here ? I could give it a try and tell you the
>> results.
>>
> See attached. I'm not submitting it as a patch yet but you're welcome to try it.

Hi,

Sorry for taking so much time to try this patch. But I can confirm it 
works much better than the current code in CVS. I applied it for the 
next version of DrFFMPEG. As well as the other ASF patch submitted recently.

Thanks a lot and don't hesitate to propose improvements like that :)

Steve

> ------------------------------------------------------------------------
> 
> Index: asf.h
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/asf.h,v
> retrieving revision 1.70
> diff -u -r1.70 asf.h
> --- asf.h	20 Jan 2006 23:48:16 -0000	1.70
> +++ asf.h	23 Mar 2006 22:28:35 -0000
> @@ -98,6 +98,7 @@
>      ByteIOContext pb;
>      /* only for reading */
>      uint64_t data_offset; /* begining of the first data packet */
> +    uint64_t index_pos; /* begining of the simple index */
>  
>      ASFMainHeader hdr;
>  
> Index: asf.c
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/asf.c,v
> retrieving revision 1.95
> diff -u -r1.95 asf.c
> --- asf.c	2 Mar 2006 19:50:21 -0000	1.95
> +++ asf.c	23 Mar 2006 22:22:59 -0000
> 
> @@ -327,6 +327,7 @@
>              pos2 = url_ftell(pb);
>              url_fskip(pb, gsize - (pos2 - pos1 + 24));
>          } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
> +	        asf->index_pos = gsize + url_ftell(pb) - 24; 
>              break;
>          } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
>              int len1, len2, len3, len4, len5;
>  
> 
> -static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
> +static int asf_build_simple_index(AVFormatContext *s, int stream_index)
>  {
> +    GUID g;
>      ASFContext *asf = s->priv_data;
> +    int64_t gsize, itime;
> +    int64_t pos, current_pos, index_pts;
> +    int i;
> +    int pct,ict;
> +    int pktnum,pktct;
> +    
> +    current_pos = url_ftell(&s->pb);
> +    
> +    url_fseek(&s->pb, asf->index_pos, SEEK_SET);
> +    get_guid(&s->pb, &g);
> +    if (!memcmp(&g, &index_guid, sizeof(GUID))) {
> +        gsize = get_le64(&s->pb);	
> +        get_guid(&s->pb, &g);
> +        itime=get_le64(&s->pb);
> +        pct=get_le32(&s->pb);
> +        ict=get_le32(&s->pb);
> +        printf("itime:0x%Lx, pct:%d, ict:%d\n",itime,pct,ict);
> +    
> +        for (i=0;i<ict;i++){
> +            pktnum=get_le32(&s->pb);
> +            pktct=get_le16(&s->pb);
> +            printf("pktnum:%d, pktct:%d\n", pktnum, pktct);
> +	    
> +            pos=(int)s->data_offset + asf->packet_size*(pktnum);
> +            index_pts=itime/10000*i;    
> +	    
> +            av_add_index_entry(s->streams[stream_index], pos, index_pts, asf->packet_size, 0, AVINDEX_KEYFRAME);
> +        }	
> +    		    
> +    }
> +    url_fseek(&s->pb, current_pos, SEEK_SET);
> +}
>  
> -    if (asf->packet_size <= 0)
> -        return -1;
> -
> -    if(av_seek_frame_binary(s, stream_index, pts, flags)<0)
> +static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
> +{
> +    ASFContext *asf = s->priv_data;
> +    AVStream *st;
> +    int64_t index_pts;
> +    offset_t pos, key_pos; 
> +    AVPacket pkt;
> +    ASFStream *asf_st;
> +    int index;
> +	  
> +    if (!s->streams[stream_index]->index_entries) 
> +        asf_build_simple_index(s, stream_index);
> +    
> +    st = s->streams[stream_index];
> +    index= av_index_search_timestamp(st, pts, flags);
> +    if(index<0)
>          return -1;
>  
> +    /* find the position */
> +    pos = st->index_entries[index].pos;
> +    pts = st->index_entries[index].timestamp;
> +    
> +
> +// various attempts to find key frame have failed so far        
> +//    asf_reset_header(s);
> +//    url_fseek(&s->pb, pos, SEEK_SET);
> +//    key_pos = pos;
> +//     for(i=0;i<16;i++){  
> +// 	    pos = url_ftell(&s->pb);
> +// 	    if (av_read_frame(s, &pkt) < 0){
> +// 	        av_log(s, AV_LOG_INFO, "seek failed\n");
> +// 	        return -1;
> +// 	    }
> +// 	    asf_st = s->streams[stream_index]->priv_data;
> +// 	    pos += st->parser->frame_offset;
> +// 			
> +// 	    if (pkt.size > b) {
> +// 	        b = pkt.size;
> +// 	        key_pos = pos;
> +// 	    }
> +// 	          
> +// 	    av_free_packet(&pkt);
> +//     }
> +
> +
> +    
> +    /* do the seek */
> +    printf("SEEKTO: %Ld\n", pos);
>      asf_reset_header(s);
> +    url_fseek(&s->pb, pos, SEEK_SET);
> +    
>      return 0;
>  }
>  
> @@ -850,7 +936,6 @@
>      asf_read_packet,
>      asf_read_close,
>      asf_read_seek,
> -    asf_read_pts,
>  };
>  
>  #ifdef CONFIG_MUXERS
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel





More information about the ffmpeg-devel mailing list