format_video_sync = video_sync_method;
if (format_video_sync < 0)
- format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? 2 : 1;
+ format_video_sync = (s->oformat->flags & AVFMT_NOTIMESTAMPS) ? 0 :
+ (s->oformat->flags & AVFMT_VARIABLE_FPS) ? 2 : 1;
if (format_video_sync) {
double vdelta = sync_ipts - ost->sync_opts;
pkt);
if (ret < 0)
return ret;
- pkt->data += ret;
- pkt->size -= ret;
*got_output = decoded_data_size > 0;
/* Some bug in mpeg audio decoder gives */
/* decoded_data_size < 0, it seems they are overflows */
if (!*got_output) {
/* no audio frame */
- return 0;
+ return ret;
}
decoded_data_buf = (uint8_t *)samples;
do_audio_out(output_files[ost->file_index].ctx, ost, ist,
decoded_data_buf, decoded_data_size);
}
- return 0;
+ return ret;
}
static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts)
if (!*got_output) {
/* no picture yet */
av_freep(&decoded_frame);
- return 0;
+ return ret;
}
ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts,
decoded_frame->pkt_dts);
if (ret < 0)
return ret;
if (!*got_output)
- return 0;
-
- pkt->size = 0;
+ return ret;
rate_emu_sleep(ist);
}
avsubtitle_free(&subtitle);
- return 0;
+ return ret;
}
/* pkt = NULL means EOF (needed to flush decoder buffers) */
-static int output_packet(InputStream *ist, int ist_index,
+static int output_packet(InputStream *ist,
OutputStream *ost_table, int nb_ostreams,
const AVPacket *pkt)
{
- OutputStream *ost;
- int ret = 0, i;
+ int i;
int got_output;
int64_t pkt_pts = AV_NOPTS_VALUE;
-
AVPacket avpkt;
- if(ist->next_pts == AV_NOPTS_VALUE)
- ist->next_pts= ist->pts;
+ if (ist->next_pts == AV_NOPTS_VALUE)
+ ist->next_pts = ist->pts;
if (pkt == NULL) {
/* EOF handling */
//while we have more to decode or while the decoder did output something on EOF
while (ist->decoding_needed && (avpkt.size > 0 || (!pkt && got_output))) {
+ int ret = 0;
handle_eof:
- ist->pts= ist->next_pts;
- if(avpkt.size && avpkt.size != pkt->size)
+ ist->pts = ist->next_pts;
+
+ if (avpkt.size && avpkt.size != pkt->size) {
av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
"Multiple frames in a packet from stream %d\n", pkt->stream_index);
- ist->showed_multi_packet_warning=1;
+ ist->showed_multi_packet_warning = 1;
+ }
switch(ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
if (ret < 0)
return ret;
+ // touch data and size only if not EOF
+ if (pkt) {
+ avpkt.data += ret;
+ avpkt.size -= ret;
+ }
if (!got_output) {
- if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
- continue;
- goto discard_packet;
+ continue;
}
}
- discard_packet:
/* handle stream copy */
if (!ist->decoding_needed) {
}
}
for (i = 0; pkt && i < nb_ostreams; i++) {
- ost = &ost_table[i];
+ OutputStream *ost = &ost_table[i];
if (!check_output_constraints(ist, ost) || ost->encoding_needed)
continue;
}
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
- if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) {
+ if (output_packet(ist, output_streams, nb_output_streams, &pkt) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d\n",
ist->file_index, ist->st->index);
for (i = 0; i < nb_input_streams; i++) {
ist = &input_streams[i];
if (ist->decoding_needed) {
- output_packet(ist, i, output_streams, nb_output_streams, NULL);
+ output_packet(ist, output_streams, nb_output_streams, NULL);
}
}
flush_encoders(output_streams, nb_output_streams);