Hi,

I don't know about AMR codec but bitrate definitely impacts on final quality.
Try to increase bitrate value: I had same poor quality problems with MPEG4 
encoding until I set the bitrate to width * height * 4.
Keep in mind that poor quality might comes from a wide bunch of parameters used 
to initialize the codec.
As for example, this is how I initialize an MPEG4 codec (A]), for clarity, 
in_ctx is initialized via the code in (B])

Concerning the delay issue: I also faced such a problem. I solved it using 
av_packet_rescale_ts() which relies on time_base, instead of setting timestamps 
myself manually.

I hope this comments will help put you on the road to success :-)

Good luck.

A]
    //codec found, now we param it
    o_codec_ctx->codec_id=AV_CODEC_ID_MPEG4;
    o_codec_ctx->bit_rate=in_ctx->picture_width * in_ctx->picture_height * 4;
    
o_codec_ctx->width=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->width;
    
o_codec_ctx->height=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->height;
    o_codec_ctx->time_base = 
in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->time_base;
    o_codec_ctx->ticks_per_frame = 
in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->ticks_per_frame;
    o_codec_ctx->sample_aspect_ratio = 
in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->sample_aspect_ratio;
    
o_codec_ctx->gop_size=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->gop_size;
    o_codec_ctx->pix_fmt=AV_PIX_FMT_YUV420P;



B]
 // register all formats and codecs
    av_register_all();
    avcodec_register_all();

    // open input file, and allocate format context
    if (avformat_open_input(&in_fmt_ctx, filename, NULL, NULL) < 0)
    {
        fprintf(stderr, "Could not open source file %s\n", filename);
        exit(1);
    }

    // retrieve stream information 
    if (avformat_find_stream_info(in_fmt_ctx, NULL) < 0)
    {
        fprintf(stderr, "Could not find stream information\n");
        exit(1);
    }

    if (open_codec_context(&video_stream_idx, in_fmt_ctx, AVMEDIA_TYPE_VIDEO, 
filename) >= 0)
    {
        video_stream = in_fmt_ctx->streams[video_stream_idx];
        video_dec_ctx = video_stream->codec;
    }

    if (open_codec_context(&audio_stream_idx, in_fmt_ctx, AVMEDIA_TYPE_AUDIO, 
filename) >= 0) {
        audio_stream = in_fmt_ctx->streams[audio_stream_idx];
        audio_dec_ctx = audio_stream->codec;
    }

    if (!video_stream) {
        fprintf(stderr, "Could not find video stream in the input, aborting\n");
        avformat_close_input(&in_fmt_ctx);
        exit(0);
    }

    in_video_ctx->format_ctx=in_fmt_ctx;
    in_video_ctx->filename=filename;
    in_video_ctx->codec_name=(char *) 
in_fmt_ctx->streams[video_stream_idx]->codec->codec->long_name;
    in_video_ctx->video_stream_idx=video_stream_idx;
    in_video_ctx->audio_stream_idx=audio_stream_idx;
    
in_video_ctx->picture_width=in_fmt_ctx->streams[video_stream_idx]->codec->width;
    
in_video_ctx->picture_height=in_fmt_ctx->streams[video_stream_idx]->codec->height;
    in_video_ctx->nb_streams=in_fmt_ctx->nb_streams;



 
Le 1 juil. 2015 à 10:40, adev dev <[email protected]> a écrit :

> I am compressing movies from bitmaps and audio files. With AAC files it is 
> working correctly. But when I have AMR_WB files sound is corrupted. I can 
> recognise correct words in video file but it is delayed and with very bad 
> quality.
> 
> My AMR files are recorded with parameters:
> - sampling rate: 16000,
> - bitrate: 23000.
> 
> I am setting this parameters in audio stream which is added to video. Sample 
> format is set to AV_SAMPLE_FMT_FLT. When using other formats app crashes with 
> "Unsupported sample format". 
> 
> What needs to be done to correctly add AMR stream to video file? Do I have to 
> reencode it to AAC and add as AAC audio stream?? Thank you for all hints.
> _______________________________________________
> Libav-user mailing list
> [email protected]
> http://ffmpeg.org/mailman/listinfo/libav-user

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to