Originally committed as revision 8340 to svn://svn.ffmpeg.org/ffmpeg/trunk
Limin Wang authored on 2007/03/12 23:35:36... | ... |
@@ -1100,165 +1100,165 @@ static int output_packet(AVInputStream *ist, int ist_index, |
1100 | 1100 |
goto fail_decode; |
1101 | 1101 |
} |
1102 | 1102 |
} else { |
1103 |
- switch(ist->st->codec->codec_type) { |
|
1104 |
- case CODEC_TYPE_AUDIO: |
|
1105 |
- ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / |
|
1106 |
- (ist->st->codec->sample_rate * ist->st->codec->channels); |
|
1107 |
- break; |
|
1108 |
- case CODEC_TYPE_VIDEO: |
|
1109 |
- if (ist->st->codec->time_base.num != 0) { |
|
1110 |
- ist->next_pts += ((int64_t)AV_TIME_BASE * |
|
1111 |
- ist->st->codec->time_base.num) / |
|
1112 |
- ist->st->codec->time_base.den; |
|
1113 |
- } |
|
1114 |
- break; |
|
1103 |
+ switch(ist->st->codec->codec_type) { |
|
1104 |
+ case CODEC_TYPE_AUDIO: |
|
1105 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / |
|
1106 |
+ (ist->st->codec->sample_rate * ist->st->codec->channels); |
|
1107 |
+ break; |
|
1108 |
+ case CODEC_TYPE_VIDEO: |
|
1109 |
+ if (ist->st->codec->time_base.num != 0) { |
|
1110 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE * |
|
1111 |
+ ist->st->codec->time_base.num) / |
|
1112 |
+ ist->st->codec->time_base.den; |
|
1115 | 1113 |
} |
1116 |
- data_buf = ptr; |
|
1117 |
- data_size = len; |
|
1118 |
- ret = len; |
|
1119 |
- len = 0; |
|
1120 |
- } |
|
1121 |
- |
|
1122 |
- buffer_to_free = NULL; |
|
1123 |
- if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) { |
|
1124 |
- pre_process_video_frame(ist, (AVPicture *)&picture, |
|
1125 |
- &buffer_to_free); |
|
1114 |
+ break; |
|
1126 | 1115 |
} |
1127 |
- |
|
1128 |
- // preprocess audio (volume) |
|
1129 |
- if (ist->st->codec->codec_type == CODEC_TYPE_AUDIO) { |
|
1130 |
- if (audio_volume != 256) { |
|
1131 |
- short *volp; |
|
1132 |
- volp = samples; |
|
1133 |
- for(i=0;i<(data_size / sizeof(short));i++) { |
|
1134 |
- int v = ((*volp) * audio_volume + 128) >> 8; |
|
1135 |
- if (v < -32768) v = -32768; |
|
1136 |
- if (v > 32767) v = 32767; |
|
1137 |
- *volp++ = v; |
|
1138 |
- } |
|
1116 |
+ data_buf = ptr; |
|
1117 |
+ data_size = len; |
|
1118 |
+ ret = len; |
|
1119 |
+ len = 0; |
|
1120 |
+ } |
|
1121 |
+ |
|
1122 |
+ buffer_to_free = NULL; |
|
1123 |
+ if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) { |
|
1124 |
+ pre_process_video_frame(ist, (AVPicture *)&picture, |
|
1125 |
+ &buffer_to_free); |
|
1126 |
+ } |
|
1127 |
+ |
|
1128 |
+ // preprocess audio (volume) |
|
1129 |
+ if (ist->st->codec->codec_type == CODEC_TYPE_AUDIO) { |
|
1130 |
+ if (audio_volume != 256) { |
|
1131 |
+ short *volp; |
|
1132 |
+ volp = samples; |
|
1133 |
+ for(i=0;i<(data_size / sizeof(short));i++) { |
|
1134 |
+ int v = ((*volp) * audio_volume + 128) >> 8; |
|
1135 |
+ if (v < -32768) v = -32768; |
|
1136 |
+ if (v > 32767) v = 32767; |
|
1137 |
+ *volp++ = v; |
|
1139 | 1138 |
} |
1140 | 1139 |
} |
1140 |
+ } |
|
1141 | 1141 |
|
1142 |
- /* frame rate emulation */ |
|
1143 |
- if (ist->st->codec->rate_emu) { |
|
1144 |
- int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec->time_base.num, 1000000, ist->st->codec->time_base.den); |
|
1145 |
- int64_t now = av_gettime() - ist->start; |
|
1146 |
- if (pts > now) |
|
1147 |
- usleep(pts - now); |
|
1142 |
+ /* frame rate emulation */ |
|
1143 |
+ if (ist->st->codec->rate_emu) { |
|
1144 |
+ int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec->time_base.num, 1000000, ist->st->codec->time_base.den); |
|
1145 |
+ int64_t now = av_gettime() - ist->start; |
|
1146 |
+ if (pts > now) |
|
1147 |
+ usleep(pts - now); |
|
1148 | 1148 |
|
1149 |
- ist->frame++; |
|
1150 |
- } |
|
1149 |
+ ist->frame++; |
|
1150 |
+ } |
|
1151 | 1151 |
|
1152 | 1152 |
#if 0 |
1153 |
- /* mpeg PTS deordering : if it is a P or I frame, the PTS |
|
1154 |
- is the one of the next displayed one */ |
|
1155 |
- /* XXX: add mpeg4 too ? */ |
|
1156 |
- if (ist->st->codec->codec_id == CODEC_ID_MPEG1VIDEO) { |
|
1157 |
- if (ist->st->codec->pict_type != B_TYPE) { |
|
1158 |
- int64_t tmp; |
|
1159 |
- tmp = ist->last_ip_pts; |
|
1160 |
- ist->last_ip_pts = ist->frac_pts.val; |
|
1161 |
- ist->frac_pts.val = tmp; |
|
1162 |
- } |
|
1153 |
+ /* mpeg PTS deordering : if it is a P or I frame, the PTS |
|
1154 |
+ is the one of the next displayed one */ |
|
1155 |
+ /* XXX: add mpeg4 too ? */ |
|
1156 |
+ if (ist->st->codec->codec_id == CODEC_ID_MPEG1VIDEO) { |
|
1157 |
+ if (ist->st->codec->pict_type != B_TYPE) { |
|
1158 |
+ int64_t tmp; |
|
1159 |
+ tmp = ist->last_ip_pts; |
|
1160 |
+ ist->last_ip_pts = ist->frac_pts.val; |
|
1161 |
+ ist->frac_pts.val = tmp; |
|
1163 | 1162 |
} |
1163 |
+ } |
|
1164 | 1164 |
#endif |
1165 |
- /* if output time reached then transcode raw format, |
|
1166 |
- encode packets and output them */ |
|
1167 |
- if (start_time == 0 || ist->pts >= start_time) |
|
1168 |
- for(i=0;i<nb_ostreams;i++) { |
|
1169 |
- int frame_size; |
|
1165 |
+ /* if output time reached then transcode raw format, |
|
1166 |
+ encode packets and output them */ |
|
1167 |
+ if (start_time == 0 || ist->pts >= start_time) |
|
1168 |
+ for(i=0;i<nb_ostreams;i++) { |
|
1169 |
+ int frame_size; |
|
1170 | 1170 |
|
1171 |
- ost = ost_table[i]; |
|
1172 |
- if (ost->source_index == ist_index) { |
|
1173 |
- os = output_files[ost->file_index]; |
|
1171 |
+ ost = ost_table[i]; |
|
1172 |
+ if (ost->source_index == ist_index) { |
|
1173 |
+ os = output_files[ost->file_index]; |
|
1174 | 1174 |
|
1175 | 1175 |
#if 0 |
1176 |
- printf("%d: got pts=%0.3f %0.3f\n", i, |
|
1177 |
- (double)pkt->pts / AV_TIME_BASE, |
|
1178 |
- ((double)ist->pts / AV_TIME_BASE) - |
|
1179 |
- ((double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den)); |
|
1176 |
+ printf("%d: got pts=%0.3f %0.3f\n", i, |
|
1177 |
+ (double)pkt->pts / AV_TIME_BASE, |
|
1178 |
+ ((double)ist->pts / AV_TIME_BASE) - |
|
1179 |
+ ((double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den)); |
|
1180 | 1180 |
#endif |
1181 |
- /* set the input output pts pairs */ |
|
1182 |
- //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE; |
|
1183 |
- |
|
1184 |
- if (ost->encoding_needed) { |
|
1185 |
- switch(ost->st->codec->codec_type) { |
|
1186 |
- case CODEC_TYPE_AUDIO: |
|
1187 |
- do_audio_out(os, ost, ist, data_buf, data_size); |
|
1188 |
- break; |
|
1189 |
- case CODEC_TYPE_VIDEO: |
|
1190 |
- do_video_out(os, ost, ist, &picture, &frame_size); |
|
1191 |
- video_size += frame_size; |
|
1192 |
- if (do_vstats && frame_size) |
|
1193 |
- do_video_stats(os, ost, frame_size); |
|
1194 |
- break; |
|
1195 |
- case CODEC_TYPE_SUBTITLE: |
|
1196 |
- do_subtitle_out(os, ost, ist, &subtitle, |
|
1197 |
- pkt->pts); |
|
1198 |
- break; |
|
1199 |
- default: |
|
1200 |
- av_abort(); |
|
1201 |
- } |
|
1202 |
- } else { |
|
1203 |
- AVFrame avframe; //FIXME/XXX remove this |
|
1204 |
- AVPacket opkt; |
|
1205 |
- av_init_packet(&opkt); |
|
1206 |
- |
|
1207 |
- /* no reencoding needed : output the packet directly */ |
|
1208 |
- /* force the input stream PTS */ |
|
1209 |
- |
|
1210 |
- avcodec_get_frame_defaults(&avframe); |
|
1211 |
- ost->st->codec->coded_frame= &avframe; |
|
1212 |
- avframe.key_frame = pkt->flags & PKT_FLAG_KEY; |
|
1213 |
- |
|
1214 |
- if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO) |
|
1215 |
- audio_size += data_size; |
|
1216 |
- else if (ost->st->codec->codec_type == CODEC_TYPE_VIDEO) { |
|
1217 |
- video_size += data_size; |
|
1218 |
- ost->sync_opts++; |
|
1219 |
- } |
|
1181 |
+ /* set the input output pts pairs */ |
|
1182 |
+ //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE; |
|
1220 | 1183 |
|
1221 |
- opkt.stream_index= ost->index; |
|
1222 |
- if(pkt->pts != AV_NOPTS_VALUE) |
|
1223 |
- opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); |
|
1224 |
- else |
|
1225 |
- opkt.pts= AV_NOPTS_VALUE; |
|
1226 |
- |
|
1227 |
- { |
|
1228 |
- int64_t dts; |
|
1229 |
- if (pkt->dts == AV_NOPTS_VALUE) |
|
1230 |
- dts = ist->next_pts; |
|
1231 |
- else |
|
1232 |
- dts= av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); |
|
1233 |
- opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); |
|
1234 |
- } |
|
1235 |
- opkt.flags= pkt->flags; |
|
1184 |
+ if (ost->encoding_needed) { |
|
1185 |
+ switch(ost->st->codec->codec_type) { |
|
1186 |
+ case CODEC_TYPE_AUDIO: |
|
1187 |
+ do_audio_out(os, ost, ist, data_buf, data_size); |
|
1188 |
+ break; |
|
1189 |
+ case CODEC_TYPE_VIDEO: |
|
1190 |
+ do_video_out(os, ost, ist, &picture, &frame_size); |
|
1191 |
+ video_size += frame_size; |
|
1192 |
+ if (do_vstats && frame_size) |
|
1193 |
+ do_video_stats(os, ost, frame_size); |
|
1194 |
+ break; |
|
1195 |
+ case CODEC_TYPE_SUBTITLE: |
|
1196 |
+ do_subtitle_out(os, ost, ist, &subtitle, |
|
1197 |
+ pkt->pts); |
|
1198 |
+ break; |
|
1199 |
+ default: |
|
1200 |
+ av_abort(); |
|
1201 |
+ } |
|
1202 |
+ } else { |
|
1203 |
+ AVFrame avframe; //FIXME/XXX remove this |
|
1204 |
+ AVPacket opkt; |
|
1205 |
+ av_init_packet(&opkt); |
|
1206 |
+ |
|
1207 |
+ /* no reencoding needed : output the packet directly */ |
|
1208 |
+ /* force the input stream PTS */ |
|
1209 |
+ |
|
1210 |
+ avcodec_get_frame_defaults(&avframe); |
|
1211 |
+ ost->st->codec->coded_frame= &avframe; |
|
1212 |
+ avframe.key_frame = pkt->flags & PKT_FLAG_KEY; |
|
1213 |
+ |
|
1214 |
+ if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO) |
|
1215 |
+ audio_size += data_size; |
|
1216 |
+ else if (ost->st->codec->codec_type == CODEC_TYPE_VIDEO) { |
|
1217 |
+ video_size += data_size; |
|
1218 |
+ ost->sync_opts++; |
|
1219 |
+ } |
|
1236 | 1220 |
|
1237 |
- //FIXME remove the following 2 lines they shall be replaced by the bitstream filters |
|
1238 |
- if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY)) |
|
1239 |
- opkt.destruct= av_destruct_packet; |
|
1221 |
+ opkt.stream_index= ost->index; |
|
1222 |
+ if(pkt->pts != AV_NOPTS_VALUE) |
|
1223 |
+ opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); |
|
1224 |
+ else |
|
1225 |
+ opkt.pts= AV_NOPTS_VALUE; |
|
1240 | 1226 |
|
1241 |
- write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][pkt->stream_index]); |
|
1242 |
- ost->st->codec->frame_number++; |
|
1243 |
- ost->frame_number++; |
|
1244 |
- av_free_packet(&opkt); |
|
1227 |
+ { |
|
1228 |
+ int64_t dts; |
|
1229 |
+ if (pkt->dts == AV_NOPTS_VALUE) |
|
1230 |
+ dts = ist->next_pts; |
|
1231 |
+ else |
|
1232 |
+ dts= av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); |
|
1233 |
+ opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); |
|
1245 | 1234 |
} |
1235 |
+ opkt.flags= pkt->flags; |
|
1236 |
+ |
|
1237 |
+ //FIXME remove the following 2 lines they shall be replaced by the bitstream filters |
|
1238 |
+ if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY)) |
|
1239 |
+ opkt.destruct= av_destruct_packet; |
|
1240 |
+ |
|
1241 |
+ write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][pkt->stream_index]); |
|
1242 |
+ ost->st->codec->frame_number++; |
|
1243 |
+ ost->frame_number++; |
|
1244 |
+ av_free_packet(&opkt); |
|
1246 | 1245 |
} |
1247 | 1246 |
} |
1248 |
- av_free(buffer_to_free); |
|
1249 |
- /* XXX: allocate the subtitles in the codec ? */ |
|
1250 |
- if (subtitle_to_free) { |
|
1251 |
- if (subtitle_to_free->rects != NULL) { |
|
1252 |
- for (i = 0; i < subtitle_to_free->num_rects; i++) { |
|
1253 |
- av_free(subtitle_to_free->rects[i].bitmap); |
|
1254 |
- av_free(subtitle_to_free->rects[i].rgba_palette); |
|
1255 |
- } |
|
1256 |
- av_freep(&subtitle_to_free->rects); |
|
1247 |
+ } |
|
1248 |
+ av_free(buffer_to_free); |
|
1249 |
+ /* XXX: allocate the subtitles in the codec ? */ |
|
1250 |
+ if (subtitle_to_free) { |
|
1251 |
+ if (subtitle_to_free->rects != NULL) { |
|
1252 |
+ for (i = 0; i < subtitle_to_free->num_rects; i++) { |
|
1253 |
+ av_free(subtitle_to_free->rects[i].bitmap); |
|
1254 |
+ av_free(subtitle_to_free->rects[i].rgba_palette); |
|
1257 | 1255 |
} |
1258 |
- subtitle_to_free->num_rects = 0; |
|
1259 |
- subtitle_to_free = NULL; |
|
1256 |
+ av_freep(&subtitle_to_free->rects); |
|
1260 | 1257 |
} |
1258 |
+ subtitle_to_free->num_rects = 0; |
|
1259 |
+ subtitle_to_free = NULL; |
|
1261 | 1260 |
} |
1261 |
+ } |
|
1262 | 1262 |
discard_packet: |
1263 | 1263 |
if (pkt == NULL) { |
1264 | 1264 |
/* EOF handling */ |