Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Object Storage
    • All tutorials
    • Getting statistics on object queries with S3 Select
    • Getting website traffic statistics with S3 Select
    • Getting statistics on object queries using Yandex Query
    • Generating a resource-by-resource cost breakdown report using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to the file system of Yandex Data Processing hosts
    • Using Object Storage in Yandex Data Processing
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Mounting a bucket as a disk in Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
    • Using hybrid storage in Yandex Managed Service for ClickHouse®
    • Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer
    • Automatically copying objects from one bucket to another
    • Recognizing audio files in a bucket on a regular basis
    • Training a model in Yandex DataSphere on data from Object Storage
    • Connecting to Object Storage from VPC
    • Migrating data to Yandex Managed Service for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for Greenplum® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Uploading data from Yandex Managed Service for YDB using Yandex Data Transfer
    • Hosting a static Gatsby website in Object Storage
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Importing data from Yandex Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Importing data from Yandex Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Migrating data from Yandex Object Storage to Yandex Managed Service for MySQL® using Yandex Data Transfer
    • Migrating a database from Yandex Managed Service for MySQL® to Yandex Object Storage
    • Exporting Greenplum® data to a cold storage in Yandex Object Storage
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Migrating data from Elasticsearch to Yandex Managed Service for OpenSearch
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
    • Visualizing Yandex Query data
    • Publishing game updates
    • VM backups using Hystax Acura
    • Backing up to Object Storage with CloudBerry Desktop Backup
    • Backing up to Object Storage with Duplicati
    • Backing up to Object Storage with Bacula
    • Backing up to Yandex Object Storage with Veeam Backup
    • Backing up to Object Storage with Veritas Backup Exec
    • Managed Service for Kubernetes cluster backups in Object Storage
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Developing a skill for Alice and a website with authorization
    • Creating an interactive serverless application using WebSocket
    • Deploying a web application using the Java Servlet API
    • Developing a Telegram bot
    • Replicating logs to Object Storage using Fluent Bit
    • Replicating logs to Object Storage using Data Streams
    • Uploading audit logs to ArcSight SIEM
    • Exporting audit logs to SIEM Splunk systems
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data using Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Converting a video to a GIF in Python
    • Automating tasks using Managed Service for Apache Airflow™
    • Processing files with usage details in Yandex Cloud Billing
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Searching for Yandex Cloud events in Yandex Query
    • Searching for Yandex Cloud events in Object Storage
    • Creating an external table from a bucket table using a configuration file
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create resources
  • Create an API function
  • Create a converter function
  • Create a trigger
  • Test the application
  • Create a task
  • View the queue statistics
  • View the function logs
  • Get a link to a GIF file
  • How to delete the resources you created
  1. Tutorials
  2. Converting a video to a GIF in Python

Converting a video to a GIF in Python

Written by
Yandex Cloud
Updated at May 7, 2025
  • Get your cloud ready
    • Required paid resources
  • Create resources
  • Create an API function
  • Create a converter function
  • Create a trigger
  • Test the application
    • Create a task
    • View the queue statistics
    • View the function logs
    • Get a link to a GIF file
  • How to delete the resources you created

You will create a video converter using FFmpeg and Yandex Message Queue. This tutorial is intended for Linux and macOS users.

To create an application:

  1. Get your cloud ready.
  2. Create resources.
  3. Create an API function.
  4. Create a converter function.
  5. Create a trigger.
  6. Test the application.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The infrastructure support cost includes:

  • Fee for invoking functions (see Yandex Cloud Functions pricing).
  • Fee for querying the database (see Yandex Managed Service for YDB pricing).
  • Fee for storing data in a bucket (see Yandex Object Storage pricing).

Create resourcesCreate resources

  1. Download the archive with the files required to create a video converter.

  2. Create a service account named ffmpeg-sa and assign it the following roles:

    • ymq.reader
    • ymq.writer
    • lockbox.payloadViewer
    • storage.viewer
    • storage.uploader
    • ydb.admin
    • functions.functionInvoker
  3. Create a static key for the service account. Save the Key ID and Your secret key.

  4. Create a secret named ffmpeg-sa-secret in Yandex Lockbox. Under Version, specify:

    • ACCESS_KEY_ID as the key and Key ID from the previous step as the value.
    • SECRET_ACCESS_KEY as the key and Your secret key from the previous step as the value.

    Save the secret ID from the Information about secret section.

  5. Create a message queue named converter-queue in Yandex Message Queue. Save the queue URL from the General information section.

  6. Create a YDB database in Serverless mode. Save the Endpoint from the Document API endpoint section.

  7. Create a table in the database:

    • Name: tasks.
    • Table type: Document table.
    • Columns: One column named task_id of the String type. Set the Partition key attribute.
  8. Create a bucket with restricted access in Yandex Object Storage.

Create an API functionCreate an API function

The function implements an API which you can use to perform the following actions:

  • convert: Provide a video to convert. The function writes the task to the tasks table using the Document API.
  • get_task_status: Get the task status. The function checks whether the task has been completed and returns a link to a GIF file.
Management console
  1. Create a function named ffmpeg-api.

  2. Create a function version:

    1. Create a file named requirements.txt and specify this library in it:

      boto3
      
    2. Create a file named index.py and paste the contents of ffmpeg-api.py from the archive into it.

    3. Specify the following settings:

      • Runtime environment: python37
      • Entry point: index.handle_api
      • Timeout: 5
      • Service account: ffmpeg-sa
    4. Add these environment variables:

      • DOCAPI_ENDPOINT: Endpoint from the database configuration.
      • SECRET_ID: Yandex Lockbox secret ID.
      • YMQ_QUEUE_URL: URL of the Message Queue-enabled queue.

Create a converter functionCreate a converter function

A converter function is run by a trigger. It processes videos and registers the result in the tasks table.

Video conversion is based on the FFmpeg utility. The FFmpeg executable is larger than 70 MB. To upload it along with the function code, create a ZIP archive and upload it via Object Storage. Learn more about code upload formats.

Management console
  1. Create a function named ffmpeg-converter.

  2. Create an src.zip archive with the following files:

    • requirements.txt file:

      boto3
      requests
      
    • The index.py file with the contents of ffmpeg-converter.py from the archive.

    • The FFmpeg executable. Go to the FFmpeg official website, navigate to the Linux Static Builds section, download the archive with the 64-bit FFmpeg version, and make the file executable by running the chmod +x ffmpeg command.

  3. Upload src.zip to the bucket you created earlier.

  4. Create a function version:

    1. Specify the following settings:

      • Runtime environment: python37.
      • Method: Object Storage upload method.
      • Bucket: Name of the bucket you created earlier.
      • Object: src.zip.
      • Entry point: index.handle_process_event.
      • Timeout: 600.
      • Memory: 2048 MB.
      • Service account: ffmpeg-sa.
    2. Add these environment variables:

      • DOCAPI_ENDPOINT: Endpoint from the database configuration.
      • SECRET_ID: Yandex Lockbox secret ID.
      • YMQ_QUEUE_URL: URL of the Message Queue-enabled queue.
      • S3_BUCKET: Name of the bucket you created earlier.

Create a triggerCreate a trigger

A message queue is handled using a trigger for Message Queue. It invokes the converter function as messages arrive in converter-queue.

Management console
  1. In the management console, select the folder where you want to create a trigger.
  2. Select Cloud Functions.
  3. Navigate to the Triggers tab.
  4. Click Create trigger.
  5. Under Basic settings:
    • Enter a name for the trigger: ffmpeg-trigger.
    • In the Type field, select Message Queue.
  6. Under Message Queue message settings, select the message queue named converter-queue and the ffmpeg-sa service account with rights to read messages from it.
  7. Under Function settings:
    • Select the function for the trigger to invoke: ffmpeg-converter.
    • Specify the function version tag: $latest.
    • Specify the service account which will invoke the function: ffmpeg-sa.
  8. Click Create trigger.

Test the applicationTest the application

Create a taskCreate a task

Management console
  1. In the management console, select the folder containing the ffmpeg-api function.

  2. Select Cloud Functions.

  3. Select the ffmpeg-api function.

  4. Navigate to the Testing tab.

  5. In the Payload field, enter:

    {"action":"convert", "src_url":"<link_to_video>"}
    

    Where <link_to_video> is a link to an MP4 video file saved to Yandex Disk.

  6. Click Run test.

  7. You will see the task ID in the Function output field:

    { "task_id": "c4269ceb-8d3a-40fe-95f0-84cf********" }
    

View the queue statisticsView the queue statistics

After the task is created, the number of messages in the queue increases by one and a trigger fires. Make sure messages arrive in the queue and are handled. To do this, view the queue statistics.

Management console
  1. In the management console, select the folder housing converter-queue.
  2. Select Message Queue.
  3. Select the converter-queue queue.
  4. Under General information, you can see the number of enqueued messages and those being handled.
  5. Navigate to Monitoring. View the Overall queue stats charts.

View the function logsView the function logs

The trigger should invoke the converter function for each message in the queue. To make sure the function is invoked, check its logs.

Management console
  1. In the management console, select the folder containing the ffmpeg-converter function.
  2. Select Cloud Functions.
  3. Select the ffmpeg-converter function.
  4. Navigate to the Logs tab and specify the period over which you want to view them.

Get a link to a GIF fileGet a link to a GIF file

Management console
  1. In the management console, select the folder containing the ffmpeg-api function.

  2. Select Cloud Functions.

  3. Select the ffmpeg-api function.

  4. Navigate to the Testing tab.

  5. In the Payload field, enter the following request:

    {"action":"get_task_status", "task_id":"<job_ID>"}
    
  6. Click Run test.

  7. If video conversion to GIF has not been completed, the Function output field will return:

    {
        "ready": false
    }
    

    Otherwise, you will get a link to the GIF file:

    {
        "ready": true,
        "gif_url": "https://storage.yandexcloud.net/<bucket_name>/1b4db1a6-f2b2-4b1c-b662-37f7********.gif?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=qxLftbbZ91U695ysemyZ%2F202********ru-central1%2Fs3%2Faws4_request&X-Amz-Date=20210831T110351Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=f4a5fe7848274a09be5b221fbf8a9f6f2b385708cfa351861a4e69df********"
    }
    

How to delete the resources you createdHow to delete the resources you created

To shut down the infrastructure and stop paying for the resources you created:

  1. Delete converter-queue.
  2. Delete the database.
  3. Delete all objects from the bucket.
  4. Delete the bucket.
  5. Delete the ffmpeg-api and ffmpeg-converter functions.
  6. Delete ffmpeg-trigger.

Was the article helpful?

Previous
Recognizing text in image archives using Vision OCR
Next
Automating tasks using Managed Service for Apache Airflow™
© 2025 Direct Cursus Technology L.L.C.