Valkka  1.6.1
OpenSource Video Management
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FileFrameFilter Class Reference

Pipe stream into a matroska (mkv) file. More...

#include <fileframefilter.h>

Inheritance diagram for FileFrameFilter:
Inheritance graph
[legend]
Collaboration diagram for FileFrameFilter:
Collaboration graph
[legend]

Public Member Functions

 FileFrameFilter (const char *name, FrameFilter *next=NULL)
 Default constructor. More...
 
 ~FileFrameFilter ()
 Default destructor.
 
void activate (const char *fname, long int zerotime=0)
 Request streaming to disk asap (when config frames have arrived) // <pyapi>
 
void deActivate ()
 Stop streaming to disk // <pyapi>
 
- Public Member Functions inherited from FrameFilter
 FrameFilter (const char *name, FrameFilter *next=NULL)
 Default constructor. More...
 
virtual ~FrameFilter ()
 Virtual destructor // <pyapi>
 
virtual void run (Frame *frame)
 Calls this->go(Frame* frame) and then calls the this->next->run(Frame* frame) (if this->next != NULL)
 
void setVoid ()
 nullifies the next framefilter in the chain -> cuts the framefilter chain
 

Protected Member Functions

void go (Frame *frame)
 Does the actual filtering/modification to the Frame. Define in subclass.
 
void initFile ()
 Open file, reserve codec_contexes, streams, write preamble, set initialized=true if success.
 
void closeFile ()
 Close file, dealloc codec_contexes, streams.
 
void deActivate_ ()
 
void writeHeader ()
 

Protected Attributes

bool active
 Writing to file has been requested (but not necessarily achieved..)
 
bool ready
 Got enough setup frames.
 
bool initialized
 File was opened ok : codec_contexes, streams and av_format_context reserved (should be freed at some point)
 
long int mstimestamp0
 Time of activation (i.e. when the recording started)
 
long int zerotime
 Start time set explicitly by the user.
 
bool zerotimeset
 
std::string filename
 
AVRational timebase
 
std::vector< AVCodecContext * > codec_contexes
 
std::vector< AVStream * > streams
 
AVFormatContext * av_format_context
 
AVPacket * avpkt
 
std::mutex mutex
 Mutex protecting the "active" boolean.
 
std::condition_variable condition
 Condition variable for the mutex.
 
std::vector< SetupFramesetupframes
 deep copies of the arrived setup frames
 
BasicFrame internal_frame
 copy of the arrived frame and payload
 

Additional Inherited Members

- Public Attributes inherited from FrameFilter
std::string name
 
FrameFilternext
 The next frame filter in the chain to be applied.
 

Detailed Description

Pipe stream into a matroska (mkv) file.

This FrameFilter should be connected to the live stream at all times: it observes the setup frames (FrameTypes::setup) and saves them internally.

When the FileFrameFilter::activate method is called, it configures the files accordingly, and starts streaming into disk.

Notes about FFmpeg muxing & file output:

AVCodecContext : defines the codec AVFormatContext : defines the (de)muxing & has pointers to AVIOContext (in the ->pb member) AVIOContext : defines the input / output file AVStream : raw payload (video track, audio track)

avformat_alloc_output_context2(AVFormatContext* av_format_context, NULL, "matroska", NULL);

avio_open(AVIOContext* av_format_context->pb, filename.c_str(), AVIO_FLAG_WRITE);

AVStream* av_stream = avformat_new_stream(AVFormatContext* av_format_context, AVCodec* av_codec_context->codec);

Actual writing like this:

av_interleaved_write_frame(AVFormatContext* av_format_context, avpkt);

For an actual muxer implementation, see for example libavformat/movenc.c : ff_mov_write_packet => avio_write(pb, reformatted_data, size); (i.e. it uses the AVIOContext) ==> https://ffmpeg.org/doxygen/2.8/aviobuf_8c_source.html#l00178

AVIOContext is C-style "class" that can be re-defined: https://ffmpeg.org/doxygen/2.8/structAVIOContext.html

A custom AVIOContext can be created with "avio_alloc_context"

Constructor & Destructor Documentation

◆ FileFrameFilter()

FileFrameFilter::FileFrameFilter ( const char *  name,
FrameFilter next = NULL 
)

Default constructor.

Parameters
namename
nextnext framefilter to be applied in the filterchain

The documentation for this class was generated from the following files: