Qt audio y video desarrollo lectura y control de 14 mpv

I. Introducción

Use mpv para leer la información del archivo y establecer el progreso actual de la reproducción, el volumen, el silencio, etc., que son los mismos que las funciones encapsuladas por vlc en ese momento, excepto que vlc se procesa llamando a la interfaz de función y mpv se procesa leyendo y configurando atributos , Vlc admite temporizadores o métodos de función en subprocesos para leer el estado, y también admite devoluciones de llamada de eventos para obtener los cambios de estado correspondientes. Por supuesto, mpv también lo admite, y es más conveniente. ¿Cómo saber la carga de trabajo principal o el tiempo invertido? Los atributos y sus respectivos significados funcionales se enumeran en el sitio web oficial (http://mpv.io/manual/master/#options, http://mpv.io/manual/master/#list-of-input- comandos, http://mpv.io/manual/master/#properties), pero todos están en inglés, la mayoría de los programadores no deberían tener dificultad, pero el botón derecho del mouse se puede traducir al chino, jaja, creo que mucha gente He hecho esto. Muchos navegadores admiten la traducción del menú contextual de forma predeterminada. Es muy conveniente. Cuando consulto muchos documentos en inglés, utilizo muchos de ellos, incluidos los documentos oficiales de Qt y las páginas de informes BUG, ​​pero Se recomienda utilizar descripciones en inglés tanto como sea posible cuando se busquen problemas, para que la búsqueda pueda ser más precisa.

Algunos atributos de uso común:

  1. Video original ancho alto ancho alto
  2. Ancho y alto del video después de hacer zoom dwidth dheight
  3. Guarde el archivo de video: el registro de transmisión está vacío, significa detener la grabación
  4. Relación de aspecto de video aspecto de video
  5. Pausar reproducción pausar sí significa pausar no significa continuar
  6. Duración del archivo de video
  7. Silenciar sí significa silenciar no significa no silenciar
  8. Valor de volumen int 0-100
  9. Obtener el tiempo de progreso de la reproducción-pos
  10. Establecer búsqueda de progreso de reproducción
  11. Ayuda de pista de audio actual
  12. Lista de pistas / recuento
  13. Captura de pantalla a archivo

2. Características

  1. Transmisión de video de reproducción en tiempo real multiproceso + video local, etc.
  2. Soporta windows + linux + mac.
  3. Imágenes de pantalla multiproceso, no atascadas en la interfaz principal.
  4. Vuelva a conectar la cámara web automáticamente.
  5. Puede establecer si guardar en archivo y nombre de archivo.
  6. Puede arrastrar archivos directamente al control mpvwidget para reproducirlos.
  7. Admite transmisiones de video comunes como h265 video stream + rtmp.
  8. Puede pausar y reanudar la reproducción.
  9. Admite el almacenamiento de archivos de video individuales y el almacenamiento de tiempo de archivos de video.
  10. Personalice la barra flotante superior, envíe una notificación de señal de clic y establezca si desea habilitarla.
  11. Puede establecer el relleno de estiramiento de la pantalla o el relleno de igual proporción.
  12. Puede tomar capturas de pantalla (imágenes originales) y capturas de pantalla de videos.
  13. El archivo de video almacena archivos MP4.
  14. Admite decodificación rígida como qsv, dxva2, d3d11va, etc.

Tres, representaciones

Inserte la descripción de la imagen aquí

Cuatro sitios relacionados

  1. Sitio nacional: https://gitee.com/feiyangqingyun/QWidgetDemo
  2. Sitio internacional: https://github.com/feiyangqingyun/QWidgetDemo
  3. Página de inicio personal: https://blog.csdn.net/feiyangqingyun
  4. Página de inicio de Zhihu: https://www.zhihu.com/people/feiyangqingyun/
  5. Dirección de experiencia: https://blog.csdn.net/feiyangqingyun/article/details/97565652

Cinco, el código central

void MpvThread::readMediaInfo()
{
    if (mpvPlayer != NULL) {
        QVariant width = getValue("width");
        QVariant height = getValue("height");
        videoWidth = width.toInt();
        videoHeight = height.toInt();
        qDebug() << TIMEMS << url << "videoWidth:" << videoWidth << "videoHeight:" << videoHeight;
    }
}

void MpvThread::readPlayInfo()
{
    //定义长度变量用于存储文件时长
    uint length = getLength();
    //定义变量存储声音大小,默认值1
    int volume = getVolume();
    //定义变量存储是否静音
    bool mute = getMute();

    //发送文件时长信号
    emit fileLengthReceive(length);
    //发送当前音量值信号
    emit fileVolumeReceive(volume, mute);

    //改变标志位启动读取播放进度
    if (!callbackevent) {
        isReadPosition = true;
    }
}

void MpvThread::readPosition()
{
    //获取播放进度位置
    int position = getPosition();
    //获取是否播放结束
    bool isPlay = (position != 0);
    if (position > 0 && !isRtsp) {
        emit filePositionReceive(position, isPlay);
    }

    //本地文件播放结束
    if (!isPlay && !isRtsp && suffix != "dshow") {
        this->stop();
    }
}

void MpvThread::setSize()
{
    if (mpvPlayer != NULL) {
        double width = playWidget->width();
        double height = playWidget->height();
        setValue("video-aspect", width / height);
    }
}

bool MpvThread::getIsPlaying()
{
    //在视频流模式下,不是暂停状态,当前的位置和上一次的位置一致则表示断了
    //进度为0表示没有播放成功也需要重新加载
    bool isPlay = this->isRunning();
    if (isPlay && isRtsp && !getValue("pause").toBool()) {
        int position = getPosition();
        if (position == 0 || this->position == position) {
            isPlay = false;
        }

        this->position = position;
    }

    return isPlay;
}

uint MpvThread::getLength()
{
    uint length = 0;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("duration");
        length = value.toDouble() * 1000;
    }

    return length;
}

uint MpvThread::getPosition()
{
    uint positon = 0;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("time-pos");
        positon = value.toDouble() * 1000;
    }

    return positon;
}

void MpvThread::setPosition(int position)
{
    if (mpvPlayer != NULL && !isRtsp) {
        command(QVariantList() << "seek" << position / 1000 << "absolute");
    }
}

bool MpvThread::getMute()
{
    bool ok = false;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("mute");
        ok = !value.toBool();
    }

    return ok;
}

void MpvThread::setMute(bool mute)
{
    if (mpvPlayer != NULL) {
        setValue("mute", mute ? "yes" : "no");
    }
}

int MpvThread::getVolume()
{
    int volume = 0;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("volume");
        volume = value.toInt();
    }

    return volume;
}

void MpvThread::setVolume(int volume)
{
    if (mpvPlayer != NULL) {
        setValue("volume", volume);
    }
}

int MpvThread::getTrack()
{
    int track = 0;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("aid");
        track = value.toInt();
    }

    return track;
}

int MpvThread::getTrackCount()
{
    int trackCount = 0;
    if (mpvPlayer != NULL) {
        QVariant value = getValue("track-list/count");
        trackCount = value.toInt();
    }

    return trackCount;
}

void MpvThread::setTrack(int track)
{
    if (mpvPlayer != NULL) {
        setValue("aid", track);
    }
}

Supongo que te gusta

Origin blog.csdn.net/feiyangqingyun/article/details/108128093
Recomendado
Clasificación