Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions examples/numpy/generate_video_with_pts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import colorsys
from fractions import Fraction
from math import lcm

import numpy as np

import av

(width, height) = (640, 360)
total_frames = 20
fps = 30

container = av.open("generate_video_with_pts.mp4", mode="w")
fps = Fraction(30, 1)

# MP4 stores a nonzero starting offset in an edit list using the movie timescale,
# which defaults to 1000. Choose a timescale that can represent frame-aligned
# offsets exactly; otherwise, a starting PTS such as 1 at 30 fps is rounded.
movie_timescale = lcm(1000, fps.numerator)
container = av.open(
"generate_video_with_pts.mp4",
mode="w",
container_options={"movie_timescale": str(movie_timescale)},
)

stream = container.add_stream("mpeg4", rate=fps) # alibi frame rate
stream.width = width
Expand Down
Loading