Coder Social home page Coder Social logo

azure-batch-python-ffmpeg's Introduction

Azure Batch Using Python and FFmpeg

Open in Visual Studio Code

Hi!, This project demonstrates how to run custom python script with any pip dependencies. In this project, I've simply used the FFmpeg.

I've decied to write proper README, because there are very less resources on this particular example.

Prerequisites

Make sure you have properly configured the Azure Batch Account and also ran the startup script when creating the Batch pool.

Below is the example that how to write the startup script

/bin/bash -c "apt-get update && apt-get install -y python3-pip && python3 -m pip install azure-storage-blob==12.3.1 numpy==1.18.1 && apt-get install -y ffmpeg x264

Make sure you append && with every new command, to get proper installation process.

Setup

Make sure you have latest python version installed or atleast LTS one. Run this command to install all the dependencies,

pip install -r requirements.txt

Working with main file

Main Python logic is stored in file called task.py Here's the snapshot of that file

import ffmpeg
import subprocess
import sys
import logging

logging.basicConfig(level = logging.INFO)

def flip():
	logging.info('Processing Started')
	stream = ffmpeg.input('FileURL with http')
	stream = ffmpeg.vflip(stream)
	stream = ffmpeg.output(stream, 'output.mp4')
	logging.info(sys.argv[1])
	ffmpeg.run(stream)
	logging.info('Finished')

flip()

change the File URL which is actually downloadable, if not then code will fail.

To run this file,

python task.py testparam

config.py

This file holds all the confidential variables or settings of Azure batch which are used to connect using pip package.

So, Basic config.py will look like this,

_BATCH_ACCOUNT_NAME = ''  # Your batch account name
_BATCH_ACCOUNT_KEY = ''  # Your batch account key
_BATCH_ACCOUNT_URL = ''  # Your batch account URL
_STORAGE_ACCOUNT_NAME = ''  # Your storage account name
_STORAGE_ACCOUNT_KEY = ''  # Your storage account key
_POOL_ID = 'PythonQuickstartPool'  # Your Pool ID
_POOL_NODE_COUNT = 2  # Pool node count
_POOL_VM_SIZE = 'STANDARD_A1_v2'  # VM Type/Size
_JOB_ID = 'PythonQuickstartJob'  # Job ID
_STANDARD_OUT_FILE_NAME = 'stdout.txt'  # Standard Output fil

Running task with the Azure Batch

ffmpeg-sample.py contains the API calls made with the Azure Batch PiP package.

Walkthrough of the file

Go to :144

task_resource_files_urls = [
    'https://raw.githubusercontent.com/meet86/azure-batch-python-ffmpeg/main/task.py'
]

Here, List out all the files that are dependecies or the main program file. Because, these files will be uploaded to the azure batch job.

command =  "/bin/bash -c \"python3 task.py testparam\""

This command will be feeded into the Job method to run the task.

References

https://github.com/Azure-Samples/batch-python-quickstart/

azure-batch-python-ffmpeg's People

Contributors

ivaltryek avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.