GithubHelp home page GithubHelp logo

gautam8404 / ffmpeg-py Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 8 KB

Simple FFmpeg bindings for python

Home Page: https://pypi.org/project/ffmpeg-py/

License: MIT License

Python 100.00%
ffmpeg ffmpeg-wrapper python-ffmpeg

ffmpeg-py's Introduction

Simple FFmpeg binding for python, mainly created for personal use. But i do plant to modify it for professional use.

Installation using pip

pip install ffmpeg-py

Example:

from FFmpeg.ffmpeg import FFmpeg
import subprocess

ffmpeg = FFmpeg()
ff = (
    ffmpeg
    .OverwriteOutput()
    .addInput("video1.webm")
    .addInput("./logo.png")
    .addInput("video2.webm")
    .videoCodec("libx264")
    .audioCodec("aac")
    .videoFramerate(30)
    .videoResolution(resString="1920x1080")
    .scale2refFilter(2, 0, "oh*mdar:ih*0.2", "camera", "video")  # resize camera to 20% of screen height
    .overlayFilter("video", "1", "W-w-10", "H-h-10", "v")  # overlay logo on bottom right
    .overlayFilter("v", "camera", "10", "10")  # overlay camera on top left
    .output("output.mp4")  # output file
)
code, stdout, stderr = ff.execute(stderr=subprocess.STDOUT, shell=False)
print(code, stdout, stderr)

INFO

  • FFmpeg.ffmpeg.FFmpeg() - Main class, contains logic for executing command using subprocess
  • FFmpeg.ffmpegCommandBuilder.FFmpegCommandBuilder() - Class for building ffmpeg command, contains all methods for ffmpeg filters, codecs and other options

ffmpeg-py's People

Contributors

gautam8404 avatar

Stargazers

 avatar

Watchers

 avatar

ffmpeg-py's Issues

Error initializing complex filters during add audio to video

objective
add audio to video
when using ffmpeg on shell it work like this
ffmpeg -y -i 'mountains.mp4' -i 'sheep.mp3' -codec:v 'libx264' -codec:a 'aac' -map '0:v:0' -map '1:a:0' -shortest 'add_audio.mp4'
but no luck when using ffmpeg-py

steps

!wget -c https://cdn.creatomate.com/demo/mountains.mp4
!wget -c http://www.jsayles.com/music/sheep.mp3

code

import subprocess
from FFmpeg.ffmpeg import FFmpeg
output = 'audio.mp4'
ff = (
    FFmpeg()
    .OverwriteOutput()
    .addInput('mountains.mp4')
    .addInput('sheep.mp3')
    .complexFilter("-codec:v 'libx264' -codec:a 'aac' -map '0:v:0' -map '1:a:0' -shortest")
    .output(output)
)
ff.execute(stderr = subprocess.STDOUT, shell = False)

result

starting ffmpeg with command: ffmpeg -y -i mountains.mp4 -i sheep.mp3 -filter_complex -codec:v 'libx264' -codec:a 'aac' -map '0:v:0' -map '1:a:0' -shortest audio.mp4
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mountains.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:08.50, start: 0.083000, bitrate: 932 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 681 kb/s, 24.12 fps, 24 tbr, 24k tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
[mp3 @ 0x592d4d2bd6c0] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from 'sheep.mp3':
  Metadata:
    title           : sheep
  Duration: 00:03:52.83, start: 0.000000, bitrate: 320 kb/s
  Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
[AVFilterGraph @ 0x592d4d2a19c0] No such filter: '-codec:v libx264 -codec:a aac -map 0:v:0 -map 1:a:0 -shortest'
Error initializing complex filters.
Invalid argument
(1, '', None)

best regards

Invalid frame size set on videoResolution(resString = '')

code

# hd = 1280×720
# hd = 1920×1080 # only this is work
# 4K = 3840×2160
# 8K = 7680×4320

ffmpeg = FFmpeg()
ff = (
    ffmpeg
    .OverwriteOutput()
    .addInput("mountains.mp4")
    .videoCodec("libx264") # libx265 (smallest), libx264 (biggest)
    .audioCodec("copy") # aac (smallest), libmp3lame, ac3, libtwolame (biggest), copy (faster because not reencoding)
    .videoFramerate(60)
    .videoResolution(resString = "3840×2160")
    .output('libx264-copy.mp4')
)
code, stdout, stderr = ff.execute(stderr = subprocess.STDOUT, shell = False)
print(code, stdout, stderr)

result

starting ffmpeg with command: ffmpeg -y -i mountains.mp4 -vcodec libx265 -acodec aac -r 60 -s 1280×720 libx264.mp4
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mountains.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:08.50, start: 0.083000, bitrate: 932 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 681 kb/s, 24.12 fps, 24 tbr, 24k tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Invalid frame size: 1280×720.
1  None

best regards

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.