C++ LibVLC Create Stream from Frames/Images - c++

I want to use LibVLC for creating a Video from Images. As for now I have no experience with LibVLC.
I already Implemented a test Project like here (A simple C program to play mp3 using libvlc).
Is there any Way to create an Instance of "libvlc_media_t" and put images to it instead of calling "libvlc_media_new_path" to load a Video from a File?
Or are there any other Possibilities?

Create a media list and media play list in addition to a media player:
media_list_ = libvlc_media_list_new(vlc_instance_);
media_list_player_ = libvlc_media_list_player_new(vlc_instance_);
libvlc_media_list_player_set_media_list(media_list_player_, media_list_);
libvlc_media_list_player_set_media_player(media_list_player_, media_player_);
You can add image files to a vlc play list in the same way as you can add a video.
libvlc_media_t* media = libvlc_media_new_path(vlc_instance_, "image file");
if (media) {
libvlc_media_list_lock(media_list_);
libvlc_media_list_add_media(media_list_, media)
libvlc_media_list_unlock(media_list_);
}
You can then cycle through the images by using the following:
libvlc_media_list_player_play_item_at_index(media_list_player_, index)

Related

How to check if VlcMedia contains a video?

I am developing a media player using vlc-qt I wanted to know how can I identify that my player contains a video or not.
For example
m_player=new VlcMediaPlayer(m_instance);
m_media= new VlcMedia("",m_instance);
m_player->open(m_media);
m_player->play()
As you can see here my m_media is initialized with no video url so how can I check whether my m_media contains any video or not.
I wanted to know this because so that in my player i will control play/stop button.
Solution
After opening the media use VlcMediaPlayer::video to retrieve the video object and check if it is valid, i.e. not a nullptr.
Example
Here is an example I wrote for you to demonstrate a possible implementation of the proposed solution:
m_player = new VlcMediaPlayer(m_instance);
m_media = new VlcMedia("", m_instance);
m_player->open(m_media);
if (m_player->video())
m_player->play();
According to VlcMedia source, the string you give to the class can be retrieved using the getter VlcMedia::currentLocation(). From that string, you can use QFile::exists() to check if the file path exists.

How to access the meta data of QMediaPlayer?

I want to access the metadata of the mp3 file and put it in the labels but the program doesn't read it.
I read http://doc.qt.io/qt-5/qmediametadata.html.
I wrote this code but it doesn't work properly (besides QFileInfo).
path = item->text(); //text is a path from QFileDialog::getOpenFileName
/*QMediaPlayer*/ sound.setMedia(QUrl::fromLocalFile(path));
QFileInfo info(path);
ui->label_3->setText(sound.metaData("Title").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(sound.metaData("AlbumTitle").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(info.baseName());
ui->label_5->setText(sound.metaData("Author").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound.metaData("AlbumArtist").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound.metaData("Composer").toString());
Library and multimedia are added.
Cause
It takes time for the media to be loaded after calling QMediaPlayer::setMedia, hence requesting the meta data right after the media has been set results in:
QVariant(Invalid)
Solution
I would suggest you to wait for the media to be loaded by connecting to the QMediaPlayer::mediaStatusChanged and reading the meta data once the status becomes QMediaPlayer::LoadedMedia.
Note: If you make sound a local variable, it would be destroyed when it goes out of scope. Better use auto *sound = new QMediaPlayer(this);.
Example
Here is an example I have prepared for you of how you could change your code in order to implement to proposed solution:
connect(sound, &QMediaPlayer::mediaStatusChanged, [this, sound, info](QMediaPlayer::MediaStatus status){
if (status == QMediaPlayer::LoadedMedia) {
ui->label_3->setText(sound->metaData("Title").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(sound->metaData("AlbumTitle").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(info.baseName());
ui->label_5->setText(sound->metaData("Author").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound->metaData("AlbumArtist").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound->metaData("Composer").toString());
}
});

itk OtsuMultipleThresholdsImageFilter does not process

I am trying to use ITK's OtsuMultipleThresholdsImageFilter filter in a project but I do not have output.
My aim is to make a simple interface between OpenCV and ITK.
To convert my data from OpenCV's Mat container to itk::Image I use ITK's bridge to OpenCV and I could check that the data are properly sent to ITK.
I am even able to display thanks to QuickView.
But When I setup the filter inspired by this example the object returned by the method GetThresholds() is empty.
Here is the code I wrote:
typedef itk::Image<uchar,2> image_type;
typedef itk::OtsuMultipleThresholdsImageFilter<image_type, image_type> filter_type;
image_type::Pointer img = itk::OpenCVImageBridge::CVMatToITKImage<image_type>(src);
image_type::SizeType size = img->GetLargestPossibleRegion().GetSize();
filter_type::Pointer filter = filter_type::New();
filter->SetInput(img);
filter->SetNumberOfHistogramBins(256);
filter->SetNumberOfThresholds(K);
filter_type::ThresholdVectorType tmp = filter->GetThresholds();
std::cout<<"CHECK: "<<tmp.size()<<std::endl;
src is OpenCV's Mat of CV_8U(C1) type.
A fundamental and basic concept to using ITK is that it is a pipeline architecture. You must connect the input's and output's then update the pipeline.
You have connected the pipeline but you have not executed it. You must call filter->Update().
Please read the ITK Software Guide to understand the fundamentals of ITK:
https://itk.org/ItkSoftwareGuide.pdf

Create a WebRTC VideoTrack with a “custom” Capturer using C++

Is there a way (or hack) to let me use a "custom" video capturer to create a VideoTrack and provide frames to it ?
The classic way to build a VideoTrack is :
Get a VideoCapturer Instance :
std::unique_ptr<cricket::VideoCapturer> capturer;
Create a VideoSource with a provided capturer :
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> videoSource = peer_connection_factory_->CreateVideoSource(std::move(capturer), NULL);
Create a VideoTrack using the VideoSource :
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track;
video_track = peer_connection_factory_->CreateVideoTrack(kVideoLabel, videoSource);
I was wondering if there is a way to override step one, instead of using the native one, using a custom capturer, so that i can provide the frames to the video track using a callback. That will let me use any video source (file, yuv stream...) and be very flexible.
Any advice on this one ?
This question is a C++ reference to : Create a WebRTC VideoTrack with a “custom” Capturer on Android with libjingle
I finally found a way to make my own native C++ Video Capture. Basically you have to override some functions from webrtc::I420BufferInterface and cricket::VideoCapturer.
If someone wants any further explanations please feel free to ask.

How to display indoor.shp file in TileMill

I make indoor map with JOSM (.osm format) then i sucessfully convert them in to shapefile(.shp format). I want to convert them in to MBTiles format in order to display andorid application by using TileMill. When i upload my shp file in TileMill project , i cant see my map. Is there a way to show it? Thank you.
Here is my .shp file link
Map {
background-color: #b8dee6;
}
#countries {
::outline {
line-color: #85c5d3;
line-width: 2;
line-join: round;
}
polygon-fill: #fff;
}
#polygon.poly {
line-color:#594;
line-width:0.5;
polygon-opacity:1;
polygon-fill:#ae8;
}
JOSM to shp to MBTiles... For an indoor map... It seems a little bit complicated.
I imagine that your map is made of lines and polygons?
I could suggest that you (re)build your indoor map from scratch as a KML file (with Google Earth, or ArcGIS, or even with Google Maps).
Then you will be able to load this KML directly on an Android device:
either with Google Earth for Android
or with OSMNavigator application (based on OSMBonusPack+osmdroid)
or by writing your own application using OSMBonusPack+osmdroid libs.