Page 1 of 1

Stretching Video and Images

Posted: 03 Feb 2017 23:10
by SaundersB
I'm attempting to play video and images inside a Qt QFrame. I have to set the QFrame dimensions manually, and need to stretch the video to match the QFrame dimensions.

No matter what I do I can't seem to get the video to stretch to both the horizontal and vertical. I want to change the video and not the widget.

I've attempted calculating the aspect ratio and setting the input to transcode as an output with a set width and height.

Any other ideas or methods out there are greatly appreciated. Thank you.

Note: I've read just about every post on this topic and haven't found that I would be able to stretch video/images to match their parent frame.

Code: Select all

/* Create a new LibVLC media descriptor */ _m = libvlc_media_new_path(_vlcinstance, (const char *)(file.toUtf8())); libvlc_media_add_option(_m, ":transcode{vcodec=mp4v,width=400,height=200}"); libvlc_video_set_aspect_ratio(_mp, "9:3"); libvlc_media_player_set_media(_mp, _m); HWND windowID = reinterpret_cast<HWND>(this->winId()); /* Get our media instance to use our window */ libvlc_media_player_set_hwnd(_mp, windowID); libvlc_media_player_set_position(_mp, 0); /* Play */ libvlc_media_player_play(_mp);

Re: Stretching Video and Images

Posted: 04 Feb 2017 07:20
by RĂ©mi Denis-Courmont
As far as I recall, there currently exists no options inr LibVLC to ignore the P.A.R. and stretch the video rectangle in both dimensions.

Re: Stretching Video and Images

Posted: 04 Feb 2017 09:36
by kodela
Try using the Monitor pixel aspect ratio option.
This allows the ratio of the width to the height to be adjusted.
The "Zoom video" option allows you to adjust the ratio of the size of the display to the size of the video.

Example:
A video with resolution 1280 x 720

Monitor pixel aspect ratio: 0.8
Zoom video: 1
Display: 1600 x 720

Monitor pixel aspect ratio: 0.8
Zoom video: 0.8
Display: 1280 x 576

Re: Stretching Video and Images

Posted: 13 Feb 2017 16:59
by SaundersB
Thank you for your help.

I ended up calculating the aspect ratio dynamically.

Code: Select all

int gcd = greatest_common_divisor(window_width, window_height); int new_width = window_width / gcd; int new_height = window_height / gcd; std::string ratio = convert_int_to_string(new_width) + ":" + convert_int_to_string(new_height); const char * final_ratio = ratio.c_str(); libvlc_video_set_aspect_ratio(_mp, final_ratio); std::string convert_int_to_string(int number) { std::ostringstream ss; ss << number; return ss.str(); }
Hope this helps anybody else out there looking to do the same!