/*
* qt获取视频的每一帧
*/
#include <QtCore/QCoreApplication>
#include <Windows.h>
#include "vlc/vlc.h"
#include <qmutex>
#include <qimage>
#pragma comment(lib,"libvlc.lib")
#pragma comment(lib,"libvlccore.lib")
QMutex g_mutex;
int IMG_WIDTH = 512;
int IMG_HEIGHT = 280;
int frameNum = 0;
//opaque为libvlc_video_set_callbacks回调最后一个参数传递的指针
static void* lock(void* opaque, void** planes)
{
char* buffer = (char*)opaque;
g_mutex.lock();
*planes = buffer; /*tell VLC to put decoded data to this buffer*/
return 0; /* picture identifier, not needed here */
}
/*##get the argb picture AND save to file*/
static void unlock(void* opaque, void* picture, void* const* planes)
{
char* buffer = (char*)opaque;
QImage image((unsigned char*)buffer, IMG_WIDTH, IMG_HEIGHT, QImage::Format_ARGB32);
QString filePath;
filePath.sprintf("d:/img%d.jpg", frameNum);
frameNum++;
image.save(filePath);
g_mutex.unlock();
}
static void display(void* opaque, void* picture)
{
(void)opaque;
}
int main(int argc, char *argv[])
{
libvlc_instance_t* inst;
libvlc_media_player_t* mp;
libvlc_media_t* m;
libvlc_time_t length;
int wait_time = 5000;
/* Load the VLC engine */
inst = libvlc_new(NULL, NULL);
m = libvlc_media_new_path(inst, "cuc_ieschool.flv");
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m);
char* buffer = (char*)malloc(640 * 480 * 4);
libvlc_video_set_callbacks(mp, lock, unlock, display, buffer);
libvlc_video_set_format(mp, "RGBA", IMG_WIDTH, IMG_HEIGHT, IMG_WIDTH * 4);
libvlc_media_player_play(mp);
_sleep(wait_time);
length = libvlc_media_player_get_length(mp);
IMG_WIDTH = libvlc_video_get_width(mp);
IMG_HEIGHT = libvlc_video_get_height(mp);
printf("Stream Duration: %ds\n", length / 1000);
printf("Resolution: %d x %d\n", IMG_WIDTH, IMG_HEIGHT);
//Let it play
_sleep(length - wait_time);
// Stop playing
libvlc_media_player_stop(mp);
// Free the media_player
libvlc_media_player_release(mp);
libvlc_release(inst);
free(buffer);
}
vlc-qt gets every frame of the video
Guess you like
Origin blog.csdn.net/qq_44519484/article/details/113755622
Recommended
Ranking