0

So I'm trying to download a very specific time span of an online video. How can I achieve this? I'm guessing I would have to first get the byte-range between both my "From" TimeSpan and my "To" TimeSpan, but how could I achieve this (the file is .mp4) ?

To download the specific range I could use this:

var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip });
var request = new HttpRequestMessage { RequestUri = new Uri("http://myvideourl/v.mp4") };
request.Headers.Range = new RangeHeaderValue(0, 1000);
using (Stream contentStream = await(await client.SendAsync(request)).Content.ReadAsStreamAsync(), 
       stream = new FileStream("v.mp4", FileMode.Create, FileAccess.Write, FileShare.None))
{
    await contentStream.CopyToAsync(stream);
}

But how do I then transform the Stream into a .mp4? And especially, how do I determine the range I need?

user2950509
  • 1,018
  • 2
  • 14
  • 37
  • Mp4 is not a raw video - its a container for compressed video, you cannot just download the byte array and get back to normal video. So in order to extract the "From"-"To" Timespan you need to download the whole video and then extract the fragment using ffmpeg or MediaFoundation API.I you are using UWP runtime - you should look to Windows.Media.Transcoding namespace – VitaliyK May 15 '16 at 20:58
  • Isn't it even possible to get the raw frames? This might sound naive, but if the MediaElement can display each frame of the video, can't I somehow save each frame? It's to make a gif, so all I would need is screenshots from the video taken every 41.7ms. It's not impossible, right? – user2950509 May 15 '16 at 21:03
  • MediaElement still decoding the whole video before processing - there's lot's of data in the video header that is necessary for decoding. Only after processing this header you could extract frames. Mp4 stream is quite a complicated container - you cannot make any suggestions of where the each frame is in byte stream without the video metadata. – VitaliyK May 15 '16 at 21:04

0 Answers0