CreateImportVideo Class
class ScreenPlay::CreateImportVideoThis class imports (copies) and creates wallaper previews. More...
Header: | #include <CreateImportVideo> |
Public Functions
CreateImportVideo(const QString &videoPath, const QString &exportPath, const QString &codec, const int quality, QObject *parent = nullptr) | |
CreateImportVideo(QObject *parent = nullptr) | |
float | progress() const |
Public Slots
bool | createWallpaperGifPreview() |
bool | createWallpaperImagePreview() |
bool | createWallpaperImageThumbnailPreview() |
bool | createWallpaperInfo() |
bool | createWallpaperVideo() |
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 QString &codec, const int quality, 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 :
- Cannot convert the video
- Generally broken.
[slot]
bool CreateImportVideo::createWallpaperImagePreview()
.
[slot]
bool CreateImportVideo::createWallpaperImageThumbnailPreview()
Starts ffmpeg and tries to covert the given video to a image preview. Returns false
if :
- Cannot convert the video
- Generally broken.
[slot]
bool CreateImportVideo::createWallpaperInfo()
Starts ffprobe and tries to parse the resulting json. If the video is a container that not contains the video length like webm or mkv we need to count the frames ourself. We then call analyzeWebmReadFrames or analyzeVideo to parse the output. Returns false
if :
- Parsing the output json of ffprobe fails.
- Has no video.
- Cannot parse number of frames.
- Is a wrong file format or generally broken.
[slot]
bool CreateImportVideo::createWallpaperVideo()
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 :
- Cannot convert the video
- Generally broken.
[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 :
- Cannot convert the video
- Generally broken.
[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 :
- Cannot convert the audio
- Generally broken.
[slot]
void CreateImportVideo::process()
Processes the multiple steps of creating a wallpaper.
- createWallpaperInfo()
- createWallpaperImagePreview()
- createWallpaperVideoPreview()
- createWallpaperGifPreview()
- createWallpaperVideo() - skiped if already a webm
- extractWallpaperAudio() - skiped if no audio
- emit createWallpaperStateChanged(ImportVideoState::Finished);