@@ -485,7 +485,7 @@ pub struct Packet {
485
485
/// this timestamp is relative to the end of the encoder delay.
486
486
///
487
487
/// This timestamp is in `TimeBase` units.
488
- pub pts : u64 ,
488
+ pub pts : i64 ,
489
489
/// The decoding timestamp (DTS) of the packet. Primarily used for video packets and is typically different
490
490
/// from the PTS. Can be negative. For audio packets, the DTS is always equal to the PTS
491
491
///
@@ -511,7 +511,7 @@ impl Packet {
511
511
pub fn new_from_slice ( track_id : u32 , pts : u64 , dur : u64 , buf : & [ u8 ] ) -> Self {
512
512
Packet {
513
513
track_id,
514
- pts,
514
+ pts : pts as i64 ,
515
515
dts : pts as i64 ,
516
516
dur,
517
517
trim_start : 0 ,
@@ -522,13 +522,13 @@ impl Packet {
522
522
523
523
/// Create a new `Packet` from a boxed slice.
524
524
pub fn new_from_boxed_slice ( track_id : u32 , pts : u64 , dur : u64 , data : Box < [ u8 ] > ) -> Self {
525
- Packet { track_id, pts, dts : pts as i64 , dur, trim_start : 0 , trim_end : 0 , data }
525
+ Packet { track_id, pts : pts as i64 , dts : pts as i64 , dur, trim_start : 0 , trim_end : 0 , data }
526
526
}
527
527
528
528
/// Create a new `Packet` from a boxed slice.
529
529
pub fn new_from_boxed_slice_v (
530
530
track_id : u32 ,
531
- pts : u64 ,
531
+ pts : i64 ,
532
532
dts : i64 ,
533
533
dur : u64 ,
534
534
data : Box < [ u8 ] > ,
@@ -545,7 +545,15 @@ impl Packet {
545
545
trim_end : u32 ,
546
546
buf : & [ u8 ] ,
547
547
) -> Self {
548
- Packet { track_id, pts, dts : pts as i64 , dur, trim_start, trim_end, data : Box :: from ( buf) }
548
+ Packet {
549
+ track_id,
550
+ pts : pts as i64 ,
551
+ dts : pts as i64 ,
552
+ dur,
553
+ trim_start,
554
+ trim_end,
555
+ data : Box :: from ( buf) ,
556
+ }
549
557
}
550
558
551
559
/// Create a new `Packet` with trimming information from a boxed slice.
@@ -557,7 +565,7 @@ impl Packet {
557
565
trim_end : u32 ,
558
566
data : Box < [ u8 ] > ,
559
567
) -> Self {
560
- Packet { track_id, pts, dts : pts as i64 , dur, trim_start, trim_end, data }
568
+ Packet { track_id, pts : pts as i64 , dts : pts as i64 , dur, trim_start, trim_end, data }
561
569
}
562
570
563
571
/// The track identifier of the track this packet belongs to.
@@ -569,7 +577,7 @@ impl Packet {
569
577
///
570
578
/// For audio packets, when gapless support is enabled,
571
579
/// this timestamp is relative to the end of the encoder delay.
572
- pub fn pts ( & self ) -> u64 {
580
+ pub fn pts ( & self ) -> i64 {
573
581
self . pts
574
582
}
575
583
@@ -752,21 +760,21 @@ pub mod util {
752
760
/// Given a `Packet`, the encoder delay in frames, and the number of non-delay or padding
753
761
/// frames, adjust the packet's timestamp and duration, and populate the trim information.
754
762
pub fn trim_packet ( packet : & mut Packet , delay : u32 , num_frames : Option < u64 > ) {
755
- packet. trim_start = if packet. pts < u64 :: from ( delay) {
756
- let trim = ( u64 :: from ( delay) - packet. pts ) . min ( packet. dur ) ;
763
+ packet. trim_start = if packet. pts < i64 :: from ( delay) {
764
+ let trim = ( delay as u64 - packet. pts as u64 ) . min ( packet. dur ) ;
757
765
packet. pts = 0 ;
758
766
packet. dts = 0 ;
759
767
packet. dur -= trim;
760
768
trim as u32
761
769
}
762
770
else {
763
- packet. pts -= u64 :: from ( delay) ;
771
+ packet. pts -= i64 :: from ( delay) ;
764
772
0
765
773
} ;
766
774
767
775
if let Some ( num_frames) = num_frames {
768
- packet. trim_end = if packet. pts + packet. dur > num_frames {
769
- let trim = ( packet. pts + packet. dur - num_frames) . min ( packet. dur ) ;
776
+ packet. trim_end = if packet. pts as u64 + packet. dur > num_frames {
777
+ let trim = ( packet. pts as u64 + packet. dur - num_frames) . min ( packet. dur ) ;
770
778
packet. dur -= trim;
771
779
trim as u32
772
780
}
0 commit comments