Giter Site home page Giter Site logo

coreyauger / flv-streamer-2-file Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 15 KB

Project takes and FLV stream coming in from a "raw" source, and could be at any point in the "live" stream. It then saves the FLV to disk and corrects Metadata to allow for seek operations on stream close.

License: MIT License

C# 100.00%
flv stream c-sharp flv-stream metadata flv-metadata-injector

flv-streamer-2-file's Introduction

flv-streamer-2-file

Project takes and FLV stream coming in from a "raw" source, and could be at any point in the "live" stream.
It then saves the FLV to disk and corrects Metadata to allow for seek operations on stream close.

Is this an FLV Metadata injector? Yes. But this one has been written to address some specific needs. Also I think it could be more useful than a lot of the other ones that are out there. Here are some of the major differences:

  • Written entirely in C# (.net)
  • Avoids usage of “unsafe” code.
  • Handles arbitrary file sizes and streams.
  • Memory efficient.
  • Small code base
  • And of course is open source

Overview

This code was developed to accomplish a specific task, but can be adapted to do a number of things to an FLV file.

My goal was to take an FLV stream … and save that stream to disk while still being able to seek inside the file. This means that you can drop out of the stream at any time and the file will contain the portion of content up to that point. The file on disk will contain the total duration and thus be seekable (tested with VLC).

Here is the general idea. I store the FLV header and meta data. I make sure that there are “placeholder” values for the meta data I want. I then write this out to the head of the file we are saving. I then stream the tag data to disk. I also keep a count of audio and video packets… you could also choose to alter timestamps ect…

When the stream errors our or has reached the end. I close the file and then go back in to the head to alter placeholder values. In my case the “duration” or total time of the file in seconds will allow players to now seek in the file.

Usage

The solution consists of 2 projects:

  • FlvStream2File (class library)
  • ConsoleTest (example app)

Compile the FlvStream2File. This is the only project required to use in your application. To use the test app.. simply compile and in a console window you can run:

>ConsoleTest.exe “path to infile.flv” “path to outfile.flv”

This will read in the source FLV and produce an output FLV with the correct duration in the metadata (thus it will allow seek operations)

If you run in the debugger you will also get a lot of useful output via the “Debug.Write” (System.Diagnostics)

Here is an example of how to use the lib.

using(FlvStream2FileWriter stream2File = new FlvStream2FileWriter("out.flv"));
{
  // keep adding bytes to the file (choose a block size)
  while(bytedata){
    stream2File.Write(buffer);
  }

  // finish write and fix flv header.
  stream2File.FinallizeFile();
}

Refrences

Here are some of the features of the more full featured and closed source version of FLV Metadata injector http://www.buraks.com/flvmdi/

Here is some good information around FLV file format

Also you will need to know a little bit about “Action Message Format” (AMF).

Expanding on this

My needs were specific, but the code can be adapted very easily to handle any of the other functions that you see in closed source projects such as FLVMDI

Ideas, Questions, Comments?

Just message me and I will try to help.

Bitdeli Badge

flv-streamer-2-file's People

Contributors

bitdeli-chef avatar coreyauger avatar genteure avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flv-streamer-2-file's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.