@@ -168,6 +168,29 @@ func (frame *Frame) Float32(plane int) []float32 {
168168 return ctx .Float32 (plane )
169169}
170170
171+ // Set plane data from float32 slice
172+ func (frame * Frame ) SetFloat32 (plane int , data []float32 ) error {
173+ if frame .Type () != media .AUDIO {
174+ return errors .New ("frame is not an audio frame" )
175+ }
176+
177+ // If the number of samples is not the same, the re-allocate the frame
178+ ctx := (* ff .AVFrame )(frame )
179+ if len (data ) != frame .NumSamples () {
180+ ctx .SetNumSamples (len (data ))
181+ if err := ff .AVUtil_frame_get_buffer (ctx , false ); err != nil {
182+ ff .AVUtil_frame_unref (ctx )
183+ return err
184+ }
185+ }
186+
187+ // Copy data
188+ copy (ctx .Float32 (plane ), data )
189+
190+ // Return success
191+ return nil
192+ }
193+
171194// Return plane data as a byte slice
172195func (frame * Frame ) Bytes (plane int ) []byte {
173196 return (* ff .AVFrame )(frame ).Bytes (plane )
@@ -261,6 +284,17 @@ func (frame *Frame) Ts() float64 {
261284 return ff .AVUtil_rational_q2d (tb ) * float64 (pts )
262285}
263286
287+ // Set timestamp in seconds
288+ func (frame * Frame ) SetTs (secs float64 ) {
289+ ctx := (* ff .AVFrame )(frame )
290+ tb := ctx .TimeBase ()
291+ if secs == TS_UNDEFINED || tb .Num () == 0 || tb .Den () == 0 {
292+ frame .SetPts (ff .AV_NOPTS_VALUE )
293+ return
294+ }
295+ ctx .SetPts (int64 (secs / ff .AVUtil_rational_q2d (tb )))
296+ }
297+
264298///////////////////////////////////////////////////////////////////////////////
265299// PUBLIC METHODS
266300
0 commit comments