I need to play back a custom AVI file that contains a classic video stream, an audio stream but also a custom data stream.
The custom stream contains data that is visualized by some custom widgets; those widgets only need that each custom frame is written in a buffer at the proper time.
Our application is based on Qt, and already uses QMediaPlayer
/QVideoWidget
to play traditional videos, but the additional custom stream makes things more complicated, because AFAIK QMediaPlayer
only plays the video/audio and ignores everything else.
I would like to avoid to reinvent the entire qt-multimedia
, but I am not sure how to make the best out of the available Qt classes.
My ideas so far are:
Write a custom media player class that demuxes and decodes the video using
ffmpeg
, implements the timing, usesQAudioOutput
for playing the audio, produces a stream ofQVideoFrame
s to be played on the video and write the custom data to some buffer for visualization.The problem: In order to avoid writing the code to rescale/convert the video frames, I would like to reuse
QVideoWidget
, but it seems to work only with the "real"QMediaPlayer
.Demux the input file and feed
QMediaPlayer
with the AV streams. Demux the input withffmpeg
(possibly leaving the decoding to the Qt backend), have oneQIODevice
to retrieve only the video/audio streams from the input file and another one to retrieve the data stream. Play the video/audio withQMediaPlayer
.+-------+ | QFile | +---^---+ | inherits | +--------------------+ | MyAviDemuxer | | | | holds a queue of | | demuxed packets | +--------------------+ | | readDataPacket readVideoPacket | | +-------v--------+ +--------v-----------+ +-----------+ | MyCustomReader | | MyVideoAudioStream +--inherits--> QIODevice | +----------------+ +--------+-----------+ +-----------+ | setMedia | +-------v-------+ | QMediaPlayer | +---------------+
The problem: synchronize the timing of the data stream with
QMediaPlayer
, handle headers and metadata correctly.
I am slightly inclined to option 1, just because it gives me more control, but I am wondering if I missed an easier solution (even Windows-only).