Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3378 มุมมอง

I want to use the video preview widget in odoo 16.

I can't import video inside odoo.tools

Here is the code snippet by Bhavin Patel.


from odoo import models, 

fields, api from odoo.tools import video

class VideoExample(models.Model): 

_name = 'video.example' 

name = fields.Char(string='Name') 

video = fields.Binary(string='Video', attachment=True) 

video_preview = fields.Binary(string='Video Preview', compute='_compute_video_preview') 

@api.depends('video') 

def _compute_video_preview(self): 

for rec in self: 

rec.video_preview = video.Video.from_binary(rec.video).preview_image() if rec.video else None

อวตาร
ละทิ้ง

our code seems to be correct. It defines a new model VideoExample with three fields: name (a Char field), video (a Binary field for the video file), and video_preview (a computed Binary field for the preview image).

The video_preview field is computed based on the video field using a custom method _compute_video_preview, which generates the preview image for the video using the odoo.tools.video module.

The odoo.tools.video.Video.from_binary method is used to create a new Video object from the binary data of the video field. Then, the preview_image method is called on the Video object to generate the preview image, which is returned as a binary data and assigned to the video_preview field.

The if rec.video else None expression at the end of the line ensures that the video_preview field is set to None if there is no video file present. This is a good practice to avoid potential errors and unexpected behavior.

Overall, this code should work correctly to generate video preview images for the VideoExample model based on the uploaded video files.

คำตอบที่ดีที่สุด

In Odoo 16, you can use the video preview widget to display a preview image of a video file, along with a play button that allows the user to play the video. Here's how you can use the video preview widget in your custom module:

  1. Add a new field to your model that represents the video file:
Python:

In this example, we're adding a new Binary field for the video file, as well as a Char field for the filename and a computed Binary field for the video preview image. The video_preview field is computed based on the video_file field using a custom method _compute_video_preview, which generates the preview image for the video.

  1. Add a new view for your model that includes the video_preview field and uses the video preview widget:
    XML:

In this example, we're adding a new view for the form of the MyModel model that includes a tag with two tags. The first tag is for the video_preview field, and uses the video_preview widget to display the preview image and play button for the video. We're also passing an options dictionary that includes the filename field (video_filename) to use for the video. The second tag is for the video_file field, and includes the filename attribute to use for the filename.

  1. Implement the _generate_video_preview method to generate the preview image for the video. You can use a third-party library such as ffmpeg or moviepy to extract a frame from the video and save it as an image. Here's an example implementation using ffmpeg:
python:

In this example, we're using ffmpeg

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Video Preview Widget in Odoo 12? แก้ไขแล้ว
3
เม.ย. 23
6245
2
เม.ย. 23
3432
1
เม.ย. 24
1877
1
พ.ค. 24
1413
0
พ.ย. 23
667