Screenshot

Last update:2024-04-03 10:41:13

The screenshot allows you to capture high-resolution, full-frame images from your videos. It can be utilized for video covers, thumbnails, and content moderation.
At CDNetworks, we provide support for taking screenshots from a variety of video formats and codecs, including:

  • Supported formats: MP4, FLV, M3U8, TS, MKV, MOV, WMV, AVI, VP8, VP9, RealVideo, Windows Media Video, and more.
  • Supported codecs: H.265, H.264, H.263, MPEG, and more.

The outputs are compatible with a variety of image formats, such as JPG, PNG, and GIF. Additionally, both JPG and PNG formats support CSS sprites.

How to Use

Structure your fops in the request body as follows:

<op>/<Format>
    /offset/<value>
    /offsets/<value>
    /interval/<value>
    /vframeN/<value>
    /t/<value>
    /sprite/<value>
    /mode/<value>
    /w/<value>
    /h/<value>
    /autofill/<value>
    /rotate/<value>
    /isZip/<value>
    |saveas/<Urlsafe_Base64_Encode(bucket:filekey)>

Video Screenshot Parameters

Parameter Required Description
op Yes Operation type. For screenshot, it should be set to vframe.
format Yes Target format for output, such as jpg, png and gif, etc.
offset No The specific time within the video at which a screenshot is to be captured. It’s measured in seconds and supports precision up to three decimal places.
offsets No Specify the timings for multiple screenshots, separated by colons, in ascending order. For instance, 0:30:60:120 will take four screenshots at 30, 60, 120, and 240 seconds.
interval No Defines the intervals at which the screenshot is to be taken regularly, measured in seconds.
vframeN No The total count of screenshots to be taken at regular intervals throughout the video.
t No The parameter sets the duration of the GIF image in seconds. If not specified, the default duration will be set to 5 seconds.
sprite No To generate a CSS sprite and designate a pattern, for instance, 4x5, it means that the screenshots will be compiled into a singular image that consists of 4 rows and 5 columns. This parameter should be used together with the interval parameter.
mode No This parameter controls how the screenshot aspect ratio is scaled to avoid distorting the original image. See the section Mode Parameters for details on each scaling mode.
w No The width of the screenshot, measured in pixels (px), has a value range of 1-1920.
h No The height of the screenshot, measured in pixels (px), has a value range of 1-1080.
autofill No This parameter works together with the w and h parameters. When assigned a value of 1, it resizes the screenshot to align with the dimensions defined by w and h, preserving the original video aspect ratio. Any additional space will be colored black.
Conversely, when given a value of 0 (the default setting), the screenshot undergoes a forceful resizing to meet the stated resolution, which can lead to video distortion.
It’s important to note that the autofill and mode parameters cannot be used simultaneously.
rotate No Adjust the screenshot’s orientation by a particular angle. The available values are 90, 180, 270, or auto.
isZip No This parameter determines if multiple screenshots should be compiled into a zip file.
1 - Package into a zip file.
0 - No such packaging.
If the screenshots need to be compiled into a zip file, the output should be named as *.zip, like a.zip for instance. Every screenshot within the compressed package will carry a name stemming from the zip file name, followed by a unique serial number. Examples include a_00001.jpg, a_00002.jpg, and so on.
saveas No This parameter defines the output location and filename as a URL-safe Base64-encoded string with the pseudocode Urlsafe_Base64_Encode(bucket:savedfilename).

Mode Parameters

Parameter Description
/mode/1 The screenshots are to be proportionally scaled and centrally cropped. If only the width or height parameter is specified, it signifies that the image will be proportionally scaled based on the minimum value either in width or height.
/mode/2 Screenshots should be proportionally scaled, without cropping, within the given maximum width and height. If only one dimension is specified, the other adjusts proportionally.
/mode/3 Screenshots are proportionally scaled and uncropped, adhering to the maximum width and height parameters. If only width or height is specified, the other dimension adjusts accordingly.

Request Example

This example targets the test.mp4 video file under the test-mp4-encrypt bucket. It captures a frame at the 5th second as a screenshot, saves it in jpg format, and stores it under the test-mp4-encrypt bucket with the name test.jpg.
Pseudocode format for the request:

curl -v -X POST 
–d "bucket=Urlsafe_Base64_Encode(test-mp4-encrypt)&key=Urlsafe_Base64_Encode(test.mp4)&fops=Urlsafe_Base64_Encode(vframe/jpg/offset/5|saveas/Urlsafe_Base64_Encode(test-mp4-encrypt:test.jpg))&force=1&separate=1"
–H "Authorization:AccessKey:EncodeSign" 
--url "http://mgrDomain/fops"

Actual request format:

-curl -v -X POST 
-d "bucket=dGVzdC1tcDQtZW5jcnlwdA==&key=dGVzdC5tcDQ=&fops=dmZyYW1lL2pwZy9vZmZzZXQvNXxzYXZlYXMvZEdWemRDMXRjRFF0Wlc1amNubHdkRHAwWlhOMExtcHdadzBL&force=1&separate=1"
-H "Authorization:AccessKey:EncodeSign" 
--url "http://mgrDomain/fops"
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!