On 01/03/2012 01:43 PM, Anton Khirnov wrote:
>
> On Sat, 31 Dec 2011 14:51:44 -0500, Justin Ruggles <[email protected]>
> wrote:
>> ---
>> avconv.c | 190
>> ++++++++++++++++++++++++++++++--------------------------------
>> 1 files changed, 91 insertions(+), 99 deletions(-)
>>
>> diff --git a/avconv.c b/avconv.c
>> index 2a45c8e..376101f 100644
>> --- a/avconv.c
>> +++ b/avconv.c
>> @@ -136,8 +136,7 @@ static float dts_delta_threshold = 10;
>> static int print_stats = 1;
>>
>> static uint8_t *audio_buf;
>> -static uint8_t *audio_out;
>> -static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
>> +static unsigned int allocated_audio_buf_size;
>>
>> #define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
>>
>> @@ -688,8 +687,7 @@ void exit_program(int ret)
>>
>> uninit_opts();
>> av_free(audio_buf);
>> - av_free(audio_out);
>> - allocated_audio_buf_size = allocated_audio_out_size = 0;
>> + allocated_audio_buf_size = 0;
>>
>> #if CONFIG_AVFILTER
>> avfilter_uninit();
>> @@ -887,18 +885,70 @@ static void generate_silence(uint8_t* buf, enum
>> AVSampleFormat sample_fmt, size_
>> memset(buf, fill_char, size);
>> }
>>
>> +static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
>> + const uint8_t *buf, int buf_size)
>> +{
>> + AVCodecContext *enc = ost->st->codec;
>> + AVFrame frame;
>
> AVFrame should be allocated properly.
indeed. i'll fix that.
>
>> + AVPacket pkt;
>> + int ret;
>> +
>> + av_init_packet(&pkt);
>> + pkt.data = NULL;
>> + pkt.size = 0;
>> +
>> + if (buf) {
>> + avcodec_get_frame_defaults(&frame);
>> + frame.nb_samples = buf_size /
>> + (enc->channels *
>> av_get_bytes_per_sample(enc->sample_fmt));
>> + if ((ret = avcodec_fill_audio_frame(&frame, enc->channels,
>> enc->sample_fmt,
>> + buf, buf_size, 1)) < 0) {
>> + av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
>> + exit_program(1);
>> + }
>> + frame.pts = ost->sync_opts;
>> + }
>> +
>> + if (avcodec_encode_audio2(enc, &pkt, buf ? &frame : NULL) < 0) {
>> + av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
>> + exit_program(1);
>> + }
>> +
>> + pkt.stream_index = ost->index;
>> + if (pkt.pts != AV_NOPTS_VALUE)
>> + pkt.pts = av_rescale_q(pkt.pts, enc->time_base,
>> ost->st->time_base);
>> + if (pkt.duration > 0)
>> + pkt.duration = av_rescale_q(pkt.duration, enc->time_base,
>> ost->st->time_base);
>> +
>> + /* FIXME: remove this once all encoders that support
>> + CODEC_CAP_SMALL_LAST_FRAME use encode2() */
>> + if (buf && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME &&
>> + frame.nb_samples < enc->frame_size) {
>> + pkt.duration = av_rescale_q(frame.nb_samples,
>> + (AVRational){ 1, enc->sample_rate },
>> + ost->st->time_base);
>> + }
>> +
>> + write_frame(s, &pkt, enc, ost->bitstream_filters);
>
> Shouldn't you test for pkt.size > 0 here?
that's questionable. current code sends 0-size packets to write_frame(),
so i didn't change it here.
-Justin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel