Fix stream copy & transcoding one stream at the same time.

Fixes issue1660.

Originally committed as revision 21042 to svn://svn.ffmpeg.org/ffmpeg/trunk
release/0.6
Michael Niedermayer 15 years ago
parent 9f907d853f
commit 036c1382a7
  1. 32
      ffmpeg.c

@ -1299,8 +1299,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
//while we have more to decode or while the decoder did output something on EOF //while we have more to decode or while the decoder did output something on EOF
while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) { while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) {
uint8_t *data_buf; uint8_t *data_buf, *decoded_data_buf;
int data_size; int data_size, decoded_data_size;
handle_eof: handle_eof:
ist->pts= ist->next_pts; ist->pts= ist->next_pts;
@ -1309,8 +1309,10 @@ static int output_packet(AVInputStream *ist, int ist_index,
fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index); fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
/* decode the packet if needed */ /* decode the packet if needed */
data_buf = NULL; /* fail safe */ decoded_data_buf = NULL; /* fail safe */
data_size = 0; decoded_data_size= 0;
data_buf = avpkt.data;
data_size = avpkt.size;
subtitle_to_free = NULL; subtitle_to_free = NULL;
if (ist->decoding_needed) { if (ist->decoding_needed) {
switch(ist->st->codec->codec_type) { switch(ist->st->codec->codec_type) {
@ -1320,27 +1322,28 @@ static int output_packet(AVInputStream *ist, int ist_index,
av_free(samples); av_free(samples);
samples= av_malloc(samples_size); samples= av_malloc(samples_size);
} }
data_size= samples_size; decoded_data_size= samples_size;
/* XXX: could avoid copy if PCM 16 bits with same /* XXX: could avoid copy if PCM 16 bits with same
endianness as CPU */ endianness as CPU */
ret = avcodec_decode_audio3(ist->st->codec, samples, &data_size, ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size,
&avpkt); &avpkt);
if (ret < 0) if (ret < 0)
goto fail_decode; goto fail_decode;
avpkt.data += ret; avpkt.data += ret;
avpkt.size -= ret; avpkt.size -= ret;
data_size = ret;
/* Some bug in mpeg audio decoder gives */ /* Some bug in mpeg audio decoder gives */
/* data_size < 0, it seems they are overflows */ /* decoded_data_size < 0, it seems they are overflows */
if (data_size <= 0) { if (decoded_data_size <= 0) {
/* no audio frame */ /* no audio frame */
continue; continue;
} }
data_buf = (uint8_t *)samples; decoded_data_buf = (uint8_t *)samples;
ist->next_pts += ((int64_t)AV_TIME_BASE/bps * data_size) / ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) /
(ist->st->codec->sample_rate * ist->st->codec->channels); (ist->st->codec->sample_rate * ist->st->codec->channels);
break;} break;}
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2; decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
/* XXX: allocate picture correctly */ /* XXX: allocate picture correctly */
avcodec_get_frame_defaults(&picture); avcodec_get_frame_defaults(&picture);
@ -1390,8 +1393,6 @@ static int output_packet(AVInputStream *ist, int ist_index,
} }
break; break;
} }
data_buf = avpkt.data;
data_size = avpkt.size;
ret = avpkt.size; ret = avpkt.size;
avpkt.size = 0; avpkt.size = 0;
} }
@ -1407,7 +1408,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
if (audio_volume != 256) { if (audio_volume != 256) {
short *volp; short *volp;
volp = samples; volp = samples;
for(i=0;i<(data_size / sizeof(short));i++) { for(i=0;i<(decoded_data_size / sizeof(short));i++) {
int v = ((*volp) * audio_volume + 128) >> 8; int v = ((*volp) * audio_volume + 128) >> 8;
if (v < -32768) v = -32768; if (v < -32768) v = -32768;
if (v > 32767) v = 32767; if (v > 32767) v = 32767;
@ -1438,9 +1439,10 @@ static int output_packet(AVInputStream *ist, int ist_index,
//ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE; //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE;
if (ost->encoding_needed) { if (ost->encoding_needed) {
assert(ist->decoding_needed);
switch(ost->st->codec->codec_type) { switch(ost->st->codec->codec_type) {
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
do_audio_out(os, ost, ist, data_buf, data_size); do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
break; break;
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
do_video_out(os, ost, ist, &picture, &frame_size); do_video_out(os, ost, ist, &picture, &frame_size);

Loading…
Cancel
Save