Skip to content

FFMpeg Custom Class (FFCC)

Robert Russell edited this page Jun 18, 2019 · 4 revisions

Constructors

Open File

public Ffcc(string filename, AVMediaType mediatype = AVMediaType.AVMEDIA_TYPE_AUDIO, FfccMode mode = FfccMode.STATE_MACH, int loopstart = -1)

Arguments

  • string filename
  • AVMediaType mediatype
    • Default: AVMediaType.AVMEDIA_TYPE_AUDIO
    • Alt: AVMediaType.AVMEDIA_TYPE_VIDEO
  • FfccMode mode
    • Default: FfccMode.STATE_MACH
      • Means it only processes a part of the file then waits for a request for more. Can be Audio or Video
    • Alt: FfccMode.PROCESS_ALL
      • Means it reads the entire file into memory. Can be used with Audio only.
  • int loopstart
    • Default: -1
      • Sets loop start point for ogg files it is detected automatically. -1 means no loop or autodetect for ogg. Example: 0 means loop from start of sound.

Read From Memory for adpcm audio.

public Ffcc(Buffer_Data buffer_Data, byte[] headerData, string datafilename, int loopstart = -1)
Because the bufferdata won't exist after this is ran FfccMode.PROCESS_ALL is forced for this constructor. So the entire sound is processed and the extra bits are disposed of at one time. AVMediaType.AVMEDIA_TYPE_AUDIO is forced because this only works with audio right now.

Arguments

  • Buffer_Data buffer_Data
    • byte[] data in a struct with other important adpcm sound data.
  • byte[] headerData
    • adpcm Header Data
  • string datafilename
    • Filename of that contains the data. I don't think this is required.
  • int loopstart
    • Default: -1
      • Sets loop start point. -1 means no loop. Example: 0 means loop from start of sound.

PAK file playback TBD

If we were to create code to read videos from PAK files we'd need to add a new constructor. Would require the buffer data to stay live in memory so that we can use FfccMod.STATE_MACH. Because we only grab video a frame at a time.

Properties

  • Ahead
    • If true ahead of ExpectedFrame
  • Behind
    • If true behind of ExpectedFrame
  • Current
    • If true CurrentFrameNum equals ExpectedFrame
  • FrameSkip
    • If true and Behind skip frames till Current or Ahead.
  • SoundEffect
    • Monogame sound effect
  • SoundEffectInstance
    • Monogame class that manipulates SoundEffect
  • timer
    • Tracks time audio has played so video can sync to the time.
  • MediaType
    • AVMediaType.AVMEDIA_TYPE_VIDEO or AVMediaType.AVMEDIA_TYPE_AUDIO
  • LOOPSTART
    • Loop point where audio will loop. If set to -1 loop should be disabled.
  • FPS
    • Frames per second of video
  • FileOpened
    • If true file opened successfully
  • isDisposed
    • If true Dispose() was called.
  • DataFileName
    • Filename containing the data.

Methods

  • Dispose()
    • Unload all objects and variables from memory.
  • Next()
    • Requests next frame or to fill audio buffer. <0 on error
  • Pause() WIP
    • I could get this to work with video but audio would keep playing after I paused it. The plan was when you pause the game, the video or music, would halt. And when you resume it would continue without a hitch. In the future maybe I could just allow pausing only when video has stopped. You can end a video early and pause. Since it's easier to stop music and resume it. Though it might need some tweaks.
  • Play(volume, pitch, pan)
    • Start playing audio or video
  • PlayInTask(volume, pitch, pan)
    • Start playing audio in a task. This was made to prevent audio processing from slowing down the main thread, video. Task being a simple thread that's easy to stop. Also it's harder to recover from audio playback skips or delays. Related Issue
  • Stop()
    • Stop playback and Dispose()
  • Texture2D()
    • Get current frame as a Texture.

Structures

Buffer_Data

  • Contains needed data for reading the adpcm audio from ram. Might be able to be repurposed for video this just hasn't been tested.