Skip Navigation

[Resolved] Updating transcoded video filenpath reference

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user is using a 3rd party plugin to optimize uploaded videos. He he would like to display the optimized videos, not the original.

Solution:
This needs a custom shortcode that will get the URL of the converted video from the database. Check this reply https://toolset.com/forums/topic/updating-transcoded-video-filenpath-reference/#post-1972307

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 13 replies, has 2 voices.

Last updated by JamesS2731 3 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1968627

Tell us what you are trying to do? Update the filepath of a video thats been uploaded with a CRED form to a Video Post and then automatically converted to mp4 by the Transcoder plugin - hidden link

As an example, the filepath of the uploaded file is:
hidden link

This is what's stored in the video upload field of the video post, and called using:

<video class="video-thumb-2" autoplay muted playsinline>
<source src="[types field='video-upload' output='raw'][/types]">
</video>

The transcoded filepath is:
hidden link

I've found some relevant rt_media fields that I've added to the Hidden Custom Fields section:

_rt_media_thumbnails
_rt_media_transcoded_files
_rt_media_video_thumbnail
_rt_transcoding_job_id

Theres also an RT Media shortcake that will display a given video using the media id - [rt_media attachment_id= xx] - but that doesnt really help.

Is there any documentation that you are following? Not really. I cant find any existing references fo this.

Is there a similar example that we can see? No.

What is the link to your site? hidden link

Any thoughts or ideas most appreciated as always.

Kind regards
James

#1969529

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

Have you tried to use the plugin's shortcode and pass the ID to it using a Toolset shortcode. Check this:

<video class="video-thumb-2" autoplay muted playsinline>
  <source src="[rt_media attachment_id='[wpv-post-id]']">
</video>
#1969803

Hi Jamal,

Many thanks for your quick response. That sounded like a good plan. I just tried it and it doesnt appear to work.

The output in I got in the page source was:

<video class="video-thumb-2" autoplay="" muted="" playsinline="">
<source src="[rt_media attachment_id='360']">
</video>

This just produced a blank white space, I'm presuming because he shortcode didn't compile. IN addition, looking at the attachment number in the media centre, the actual mp4 is 361 not 360 which is odd.

I'll keep trying and let you know if I get any results, but any other thoughts or ideas would be most welcomed.

Best regards
James

#1969835

Hi Jamal,

Just another thought on this. What I'm really trying to achieve is updating the file path in the post itself to show the new url (i.e. the mp4 rather than the mov). if I look in the media library, I can only see the new version. So, if I was to edit the post, I'd see the new mp4 url in the 'video upload' field box'.

Best regards
James

#1970447

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Thank you for your feedback James. I wonder if it would be possible to get access to your website and check it further? If yes, your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

There should be a way to replace the field value with the converted video URL instead of the original, but I'll need to know how the conversion is done. I suspect that it is performed asynchronously, and not synchronously when the post is first created. If it is performed asynchronously, we'll need to know if the plugin offers some hooks so we can run our code and replace the URL.

Or maybe I can find a way to get and display the converted URL while keeping the original URL in the field. Let me see the website, and let me know what content template are you working on and I'll see what I can find.

#1970937

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

From what I gathered so far, I could not find any of the plugin's meta keys in any Video post. Check this private page hidden link

I am using a custom shortcode to display all the meta fields for each post. The custom shortcode is defined here hidden link

Can you point me to a video that has been converted?

#1971379

Hi Jamal,

Many thanks for your continued assistance.

Yep, sure. Looking at our toolset-support-test, you'll see the top 2 mov files (snowy tipi and snowy back garden). These have both been imported and converted and can be seen in the media library as:

hidden link

hidden link

The original mov files aren't in the library but I can see them in the /uploads folder.

Does that help?

Best regards
James

#1972307

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello James, I was able to get the converted video to play. Check this screenshot hidden link

Toolset does not store the ID of the video on the custom field, it stores the URL. So I created a shortcode to get the ID from the URL. The shortcode is added here hidden link

function media_info_func( $atts ) {
  
    // Attributes
    $atts = shortcode_atts(
        array(
            'field' => '',
        ),
        $atts
    );
  
    global $post, $wpdb;
      
    $field = $atts['field'];
    $info = $atts['info'];
    
    $media_url = get_post_meta( $post->ID, $field );
      
    $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $media_url )); 
    $attachment_id = $attachment[0]; 
      
    return $attachment_id;
}
add_shortcode( 'types-media-id', 'media_info_func' );

Then we can get the custom fields using Toolset shortcode by passing the ID in the item attribute:

_rt_media_thumbnails:               [wpv-post-field name="_rt_media_thumbnails" item="[types-media-id field='wpcf-video-upload']"]

_rt_media_transcoded_files:    [wpv-post-field name="_rt_media_transcoded_files" item="[types-media-id field='wpcf-video-upload']"]

_rt_media_video_thumbnail:   [wpv-post-field name="_rt_media_video_thumbnail" item="[types-media-id field='wpcf-video-upload']"]<br>
_rt_transcoding_job_id:              [wpv-post-field name="_rt_transcoding_job_id" item="[types-media-id field='wpcf-video-upload']"]<br>

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

It turns out that the custom field for the converted file only holds a relative path in the uploads folder. So the final code becomes:

<video class="single-video" autoplay controls>
     <source src="<em><u>hidden link</u></em> name="_rt_media_transcoded_files" item="[types-image-id]"]">
</video>

I hope this helps. Let me know if you have any questions.

#1972337

Hi Jamal, That's perfect! Many thanks for all of your help with this. Very much appreciated.

Kind regards
James

#1972381
Screenshot 2021-03-02 at 15.20.02.png
Screenshot 2021-03-02 at 15.19.45.png
Screenshot 2021-03-02 at 15.19.36.png

Hi Jamal,

Many apologies for reopening the ticket. I just checked the video page and I cant get the video to display. It appears to be the source line:

<source src="hidden link name="_rt_media_transcoded_files" item="[types-image-id]"]">

I can see a red = and " (see screenshots). I've tried playing around with it, but the only way I can get the code to complete is to remove the dynamic section.

I'll keep trying but if you spot the issue in the meantime, I'd love to know.

Best regards
James

#1975173

Hi Jamal,

I've looked through everything now, but cant find a way to get this to display. I can see the video UI but no video. Is there anything else I should be adding, etc?

Best regards
James

#1975471

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello James, that was my mistake, I have renamed the shortcode to 'types-media-id' instead of 'types-image-id'.
And the shortcode needs to take a field argument:

[types-media-id field='wpcf-video-upload']

This will return the ID of the video, then we need to pass it to the Toolset shortcode in the item attribute:

[wpv-post-field name="_rt_media_transcoded_files" item="[types-media-id field='wpcf-video-upload']"]

Does it make sense?

#1975493

Hi Jamal,

Excellent! Thats working now. Yes, I understand.

Many thanks again for all of your support with this.

Best regards
James

#1976525

Hi Jamal,

Many apologies for reopening the ticket, again.

After testing last night I’ve noticed that, whilst the video now works, I’m getting the same video on each page. Would this be down to the I’d being passed? Sorry!

Kind regards
James

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.