PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Allow setting ticks_per_frame

Open gsakkis opened this issue 4 years ago • 5 comments

CodecContext.ticks_per_frame is a read-only property, hardcoded to 1 when adding a new stream:

>>> output = av.open("out.mp4", 'w')
>>> stream = output.add_stream('h264', 24)
>>> stream.ticks_per_frame
1
>>> stream.ticks_per_frame = 2
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
...
AttributeError: attribute 'ticks_per_frame' of 'av.codec.context.CodecContext' objects is not writable

It should be settable, most notably H.264/MPEG-2 set it to 2.

gsakkis avatar May 23 '21 10:05 gsakkis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Mar 26 '22 02:03 github-actions[bot]

We seem to have two contradictory requests here. PR #790 advocates changing the way this member is set, but not exposing it.

@rawler would making ticks_per_frame writable solve your issue too?

jlaine avatar Mar 26 '22 06:03 jlaine

Writeable would solve, but it would require a user of PyAV to be intimately familiar with these settings or one might get surprising results. libvpx-vp9, for example, seem to use this value in the bandwidth-calculations (how much time has passed between frames), so not explicitly setting ticks_per_frame might break bandwidth-control quite badly. (IIRC, this is how we discovered the need to set it)

rawler avatar Apr 04 '22 21:04 rawler

I'd argue that setting ticks_per_frame automatically qualifies the user as an "advanced" user. I've never once done this myself :)

Another thing that worries me is that I can't find any code in the FFmpeg CLI that sets "ticks_per_frame" outside the codecs and avformat_transfer_internal_stream_timing_info. Try grepping for "ticks_per_frame = ".

jlaine avatar Apr 04 '22 21:04 jlaine

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 03 '22 03:08 github-actions[bot]