Skip to content

Typical Usages

WangBin edited this page Jun 1, 2024 · 5 revisions

Live Recording Playback

If an mpegts/fmp4 file is in recording

setProperty("continue_at_end", "1") + setActiveTracks(MediaType::Audio, {})

Timeline Preview

    player.setActiveTracks(MediaType::Audio, {});
    player.setActiveTracks(MediaType::Subtitle, {});
    player.setProperty("continue_at_end", "1"); // TODO: remove
    player.setBufferRange(0);

Play Encoded Data While Encoding

create a socket pair, 1 fd is used to write encoded data, another is used for playback

player.setMedia("fd:");  // fd protocol only supports "fd:"
player.setProperty("avio.fd", to_string(fd_read)); // ffmpeg url protocol option

Custom IO

It can be built as a plugin. Requres abi headers. Unlike public api headers, Abi headers depends on c++ abi, so requires the same compiler and c++ library as mdk-sdk is built(clang + libc++ for apple, android and linux, msvc/clang-cl + vcrt for windows, no mingw). Steps:

  • Download mdk-abi-sdk from artifacts of github actions or sourceforge
  • Extract to existing mdk-sdk folder. A new dir mdk-sdk/include/abi is added.
  • Change mdk include path to mdk_sdk_dir/include/abi and rebuild the project. You can not mix abi headers and public headers in the same source file. This is QIODevice example.

Low Latency Live Stream

Reduce latency:

player.setProperty("avformat.fflags", "+nobuffer"); 
player.setProperty("avformat.fpsprobesize", "0"); 
player.setProperty("avformat.analyzeduration", “100000”); 
//player.setProperty("avformat.avioflags", "direct"); 

For rtsp, use tcp as transport layer protocol to get stable result

player.setProperty("avformat.rtsp_transport", "tcp");

For live streams, we can drop outdated data and show the latest frames only(e.g. pause a while and resume, play the latest frames)

player.setBufferRange(0, 1000, true); // play ASAP. and keep the latest 1s data

By default packets are dropped if until the 1st key-frame packet to ensure correctly initialize decoder, you can disable dropping via

player.setBufferRange("reader.starts_with_key", "0");

Use FFmpeg decoder if error occurs in other decoders.

Clone this wiki locally