88 if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
91 "Packet with invalid duration %" PRId64 " in stream %d\n",
101 switch (st->codecpar->codec_type) {
102 case AVMEDIA_TYPE_VIDEO:
103 if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) {
104 pkt->duration = av_rescale_q(1, av_inv_q(st->avg_frame_rate), st->time_base);
106 else if (st->time_base.num * 1000LL > st->time_base.den) {
110 case AVMEDIA_TYPE_AUDIO: {
111 int frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size);
112 if (frame_size && st->codecpar->sample_rate) {
113 pkt->duration = av_rescale_q(
114 frame_size, (AVRational){1, st->codecpar->sample_rate}, st->time_base);
174#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 29, 100)
175 const AVPacketSideData *src_matrix = av_packet_side_data_get(src->codecpar->coded_side_data,
176 src->codecpar->nb_coded_side_data,
177 AV_PKT_DATA_DISPLAYMATRIX);
178 if (src_matrix !=
nullptr) {
179 uint8_t *dst_matrix = (uint8_t *)av_memdup(src_matrix->data, src_matrix->size);
180 av_packet_side_data_add(&dst->codecpar->coded_side_data,
181 &dst->codecpar->nb_coded_side_data,
182 AV_PKT_DATA_DISPLAYMATRIX,
192#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 29, 100)
193 const AVPacketSideData *src_matrix = av_packet_side_data_get(
194 stream->codecpar->coded_side_data,
195 stream->codecpar->nb_coded_side_data,
196 AV_PKT_DATA_DISPLAYMATRIX);
197 if (src_matrix !=
nullptr) {
200 double theta = -av_display_rotation_get((
const int32_t *)src_matrix->data);