[Ffmpeg-devel] [PATCH] RTP/Get Duration of file (for seeking in stream)

Michael Niedermayer michaelni
Mon Nov 6 19:22:31 CET 2006


Hi

On Mon, Nov 06, 2006 at 11:39:27AM -0600, Ryan Martell wrote:
> Hi--
> 
> Attached is a patch to rtsp.c that will fill in the start and  
> duration of a movie (if known) from the sdp so that the seeking  
> function of rtsp will work.
> 
> Thanks!
> -Ryan

> Index: libavformat/rtsp.c
> ===================================================================
> --- libavformat/rtsp.c	(revision 6890)
> +++ libavformat/rtsp.c	(working copy)
> @@ -345,6 +345,28 @@
>      }
>  }
>  
> +static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end)
> +{
> +    char buf[256];
> +
> +    skip_spaces(&p);
> +    if (!stristart(p, "npt=", &p))
> +        return;
> +
> +    *start = AV_NOPTS_VALUE;
> +    *end = AV_NOPTS_VALUE;
> +
> +    get_word_sep(buf, sizeof(buf), "-", &p);
> +    *start = parse_date(buf, 1);
> +    if (*p == '-') {
> +        p++;
> +        get_word_sep(buf, sizeof(buf), "-", &p);
> +        *end = parse_date(buf, 1);
> +    }
> +//    av_log(NULL, AV_LOG_DEBUG, "Range Start: %lld\n", *start);
> +//    av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end);
> +}
> +
>  typedef struct SDPParseState {
>      /* SDP only */
>      struct in_addr default_ip;
> @@ -506,6 +528,13 @@
>                      }
>                  }
>              }
> +        } else if(strstart(p, "range:", &p)) {
> +            int64_t start, end;
> +
> +            // this is so that seeking on a streamed file can work.
> +            rtsp_parse_range_npt(p, &start, &end);
> +            s->start_time= start;
> +            s->duration= end - start;

duration should be under if(end != AV_NOPTS_VALUE) otherwise it could
end up with a weird value

and ideally rtsp_parse_range_npt() should be moved in a seperate patch&commit
but iam ok with it in the same patch too, its small and fairly readable

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is




More information about the ffmpeg-devel mailing list