File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import colorsys
44from fractions import Fraction
5+ from math import lcm
56
67import numpy as np
78
89import av
910
1011(width , height ) = (640 , 360 )
1112total_frames = 20
12- fps = 30
13-
14- container = av .open ("generate_video_with_pts.mp4" , mode = "w" )
13+ fps = Fraction (30 , 1 )
14+
15+ # MP4 stores a nonzero starting offset in an edit list using the movie timescale,
16+ # which defaults to 1000. Choose a timescale that can represent frame-aligned
17+ # offsets exactly; otherwise, a starting PTS such as 1 at 30 fps is rounded.
18+ movie_timescale = lcm (1000 , fps .numerator )
19+ container = av .open (
20+ "generate_video_with_pts.mp4" ,
21+ mode = "w" ,
22+ container_options = {"movie_timescale" : str (movie_timescale )},
23+ )
1524
1625stream = container .add_stream ("mpeg4" , rate = fps ) # alibi frame rate
1726stream .width = width
You can’t perform that action at this time.
0 commit comments