Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Issues
  • #1021
Closed
Open
Issue created Aug 23, 2022 by Administrator@rootContributor

Make options changeable after codec or (de)muxer has been opened

Created by: Tjoppen

Overview

Currently, as best I can tell, it is only possible to set options once: when a codec or (de)muxer is opened. There are cases where one might want to change some option afterward. My use case is changing -crf in the libx264 encoder during encoding based on user preference and changing network conditions.

Existing FFmpeg API

The av_opt_set*() in libavutil/opt.h. av_opt_get*() are probably also prudent to implement.

Doxy link: https://ffmpeg.org/doxygen/trunk/group__avoptions.html

Expected PyAV API

The av_opt functions are very generic, so the easiest route would probably be to guarantee that all relevant classes have self.ptr exposed that is guaranteed to be passable to the av_opt functions. This could be hidden from the user so that they only have to pass a CodecContext, OutputContainer or InputContainer.

Example based on aiortc's h264.py:

from av.avutil import av_opt_set_int, av_opt_get_int

class H264Encoder(Encoder):
    # [...]
    def set_crf(self, crf: int)
        av_opt_set_int(self.codec, "crf", crf) # search_flags could be optional, default to 0

    def get_crf(self) -> int:
        return av_opt_get_int(self.codec, "crf")

Errors returned by av_opt_get_int() could be raised as Exceptions, which simplifies the get functions like above.

It would also be useful to expose AV_OPT_SEARCH_* and optionally allow setting them on the set and get calls.

Assignee
Assign to
Time tracking