• CreateImportVideo
  • CreateImportVideo Class

    class ScreenPlay::CreateImportVideo

    This class imports (copies) and creates wallaper previews. More...

    Header: #include <CreateImportVideo>

    Public Functions

    CreateImportVideo(const QString &videoPath, const QString &exportPath, const QStringList &codecs, QObject *parent = nullptr)
    CreateImportVideo(QObject *parent = nullptr)
    float progress() const

    Public Slots

    bool createWallpaperGifPreview()
    bool createWallpaperImagePreview()
    bool createWallpaperImageThumbnailPreview()
    bool createWallpaperInfo()
    bool createWallpaperVideo(const QString &codec)
    bool createWallpaperVideoPreview()
    bool extractWallpaperAudio()
    void process()
    void setProgress(float progress)

    Signals

    void progressChanged(float progress)

    Detailed Description

    This lass only exsits as long as the user creates a wallpaper and gets destroyed if the creation was successful or not. The state get propagated via createWallpaperStateChanged(ImportVideoState state);

    Member Function Documentation

    CreateImportVideo::CreateImportVideo(const QString &videoPath, const QString &exportPath, const QStringList &codecs, QObject *parent = nullptr)

    Creates a CreateImportVideo object to be used in a different thread. A videoPath and a exportPath are needed for convertion.

    CreateImportVideo::CreateImportVideo(QObject *parent = nullptr)

    This constructor is only needed for calling qRegisterMetaType on CreateImportVideo to register the enums.

    qRegisterMetaType<CreateImportVideo::ImportVideoState>("CreateImportVideo::ImportVideoState");

    [slot] bool CreateImportVideo::createWallpaperGifPreview()

    Starts ffmpeg and tries to covert the given video to a 5 second preview gif.

    //[...]
    args.append("-filter_complex");
    args.append("[0:v] fps=12,scale=w=480:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1");
    args.append(m_exportPath + "/preview.gif");

    Returns false if :

    [slot] bool CreateImportVideo::createWallpaperImagePreview()

    .

    [slot] bool CreateImportVideo::createWallpaperImageThumbnailPreview()

    Starts ffmpeg and tries to covert the given video to a image preview. Returns false if :

    [slot] bool CreateImportVideo::createWallpaperInfo()

    Starts ffprobe and tries to parse the resulting json. Returns false if :

    [slot] bool CreateImportVideo::createWallpaperVideo(const QString &codec)

    Starts ffmpeg and tries to covert the given video to a webm video.

    //[...]
    args.append("-c:v");
    args.append("libvpx-vp8");
    args.append("-crf");
    args.append("30");
    args.append("-pix_fmt");
    args.append("yuv420p");
    args.append("-b:v");
    args.append("0");

    Returns false if :

    [slot] bool CreateImportVideo::createWallpaperVideoPreview()

    Starts ffmpeg and tries to covert the given video to a five second preview.

    //[...]
    args.append("-vf");
    // We allways want to have a 5 second clip via 24fps -> 120 frames
    // Divided by the number of frames we can skip (timeInSeconds * Framrate)
    // scale & crop parameter: https://unix.stackexchange.com/a/284731
    args.append("select='not(mod(n," + QString::number((m_length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400");
    // Disable audio
    args.append("-an");
    args.append(m_exportPath + "/preview.webm");

    Returns false if :

    [slot] bool CreateImportVideo::extractWallpaperAudio()

    Starts ffmpeg and tries to covert the given audio into a seperate mp3.

    //[...]
    args.append("mp3");
    args.append("-ab");
    args.append("192000");
    args.append("-vn");
    args.append(m_exportPath + "/audio.mp3");

    Returns false if :

    [slot] void CreateImportVideo::process()

    Processes the multiple steps of creating a wallpaper.

    1. createWallpaperInfo()
    2. createWallpaperImagePreview()
    3. createWallpaperVideoPreview()
    4. createWallpaperGifPreview()
    5. createWallpaperVideo() - skiped if already a webm
    6. extractWallpaperAudio() - skiped if no audio
    7. emit createWallpaperStateChanged(ImportVideoState::Finished);