<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Noticia Text";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Libav-user [mailto:libav-user-bounces@ffmpeg.org]
<b>On Behalf Of </b>Adev Dev<br>
<b>Sent:</b> Monday, July 6, 2015 11:29 AM<br>
<b>To:</b> This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.<br>
<b>Subject:</b> [SPAM] Re: [Libav-user] Adding AMR frames to audio stream of video file<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I added flush_encoder() function from transcode example but result is the same I would say. I am still doing something wrong. Sound is still about 4 times longer than expected (12 seconds) and voice signal is stretched in the range of these
 12 seconds. I have a filling that the problem is something trivial. Maybe I have to merge these frames manually? Encoder still <span style="font-family:"Noticia Text",serif;color:black;letter-spacing:.1pt">interprets</span> these frames with 320 bytes of data
 as frames with 1024 bytes like in AAC. Thank you for help. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 4 July 2015 at 15:07, Paul B Mahol <<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p><br>
Dana 4. 7. 2015. 13:06 osoba "Adev Dev" <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> napisala je:<br>
><br>
> I found something that could be the reason of the problem. When I print  frame->nb_samples of AMR sound it is 320. During encoding warning is generated "Trying to remove 704 more samples than there are in the queue". So I assume that AAC encoder expects that
 frame has 1024 samples.<br>
><br>
> Encoded AAC sound is about 4 times longer than it should be. When I skipped 3 framers per 4 frames length is correct but sound is crappy still.<br>
><br>
> AAC sound recorded with the same params (sampling rate: 16000, bitrate 23600) has 1024 samples in frame. Looks that AMR sound has about 4 times more frames but each frame has about 4 times less samples(320).<br>
><br>
> I assume  that AAC encoder should handle that situation if it is configured correctly. Is there anybody who knows what is wrong in codec configuration??? Thank you for help.<br>
><span style="color:#1F497D"><o:p></o:p></span></p>
<p>Try feeding encoder with nulls.<br>
Read documentation about codec_cap_delay.<o:p></o:p></p>
<div>
<div>
<p>><br>
><br>
><br>
><br>
> On 3 July 2015 at 13:03, Adev Dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> wrote:<br>
>><br>
>> ​​Hi all!<br>
>><br>
>> I prepared android project which makes encoding from AMR to AAC to better show the problem. It takes AMR file from resources and reencode it to "/storage/emulated/0/OutSound.aac". <br>
>><br>
>> In MainActivity INPUT_AUDIO_NAME constant specifes input file. When set to amr.m4a strange problem described in this thread occurs. After changing to aac.m4a rencoding is working.<br>
>><br>
>> I hope somebody is able to check this project and find the reason. I used older FFMPEG library because I do not know why project is not linking with latest version. Project is available under link:<br>
>><br>
>> <a href="https://drive.google.com/folderview?id=0B7SEEPspZQx1fnZCZGlIVF9fbGVEYmh3UGpnMmxPNVFseUlOZ2xLa010Nk1fZVJLSXlRc2c&usp=sharing" target="_blank">
https://drive.google.com/folderview?id=0B7SEEPspZQx1fnZCZGlIVF9fbGVEYmh3UGpnMmxPNVFseUlOZ2xLa010Nk1fZVJLSXlRc2c&usp=sharing</a><br>
>><br>
>> Thank you for help.<br>
>><br>
>><br>
>> On 2 July 2015 at 20:43, Adev Dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> wrote:<br>
>>><br>
>>> I have just updated FFMPEG to latest version 2.7.1. Unfortunately problem still occurs. No progress at all. <br>
>>> In console I see now warnings:<br>
>>> "AVFrame.format is not set" and "AVFrame.width or height is not set".<br>
>>><br>
>>> Any ideas what is wrong? Thanks for help!<br>
>>><br>
>>><br>
>>><br>
>>> On 2 July 2015 at 12:55, Adev Dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> wrote:<br>
>>>><br>
>>>> Sure, please download from GD:<br>
>>>><br>
>>>> <a href="https://drive.google.com/folderview?id=0B7SEEPspZQx1fnZCZGlIVF9fbGVEYmh3UGpnMmxPNVFseUlOZ2xLa010Nk1fZVJLSXlRc2c&usp=sharing" target="_blank">
https://drive.google.com/folderview?id=0B7SEEPspZQx1fnZCZGlIVF9fbGVEYmh3UGpnMmxPNVFseUlOZ2xLa010Nk1fZVJLSXlRc2c&usp=sharing</a><br>
>>>><br>
>>>> Please also check latest result on youtube: <a href="https://www.youtube.com/watch?v=w0BAyE14xLw" target="_blank">https://www.youtube.com/watch?v=w0BAyE14xLw</a><br>
>>>><br>
>>>> Thanks!<br>
>>>><br>
>>>> On 2 July 2015 at 12:29, Paul B Mahol <<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>> On 7/2/15, Adev Dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> wrote:<br>
>>>>> > AMR file which is recorded in Android is correct. It can be played both on<br>
>>>>> > Android and on MAC. After decoding it, reencoding to AAC and adding to<br>
>>>>> > video file it is damaged. This video which I uploaded to YouTube has sound<br>
>>>>> > encoded in AAC (reencoded from AMR file).<br>
>>>>> ><br>
>>>>> > This is really strange because when I record audio file using AAC codec I<br>
>>>>> > am doing the same steps and it is ok. First decode AAC frame from audio<br>
>>>>> > file, then encode it and add to audio stream of video file. Maybe some<br>
>>>>> > other params in codec, or audio stream is not set, or set to wrong value??<br>
>>>>> ><br>
>>>>><br>
>>>>> Could you upload and give a link to AMR file?<br>
>>>>><br>
>>>>> ><br>
>>>>> ><br>
>>>>> ><br>
>>>>> ><br>
>>>>> ><br>
>>>>> > On 2 July 2015 at 12:12, Paul B Mahol <<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>> wrote:<br>
>>>>> ><br>
>>>>> >> On 7/2/15, adev dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> wrote:<br>
>>>>> >> > I was not clear enough. Sound is not bad quality. It is damaged. Please<br>
>>>>> >> > have a look on video file which I uploaded to YouTube:<br>
>>>>> >> ><br>
>>>>> >> > <a href="https://www.youtube.com/watch?v=1UcGQwvtr9s" target="_blank">
https://www.youtube.com/watch?v=1UcGQwvtr9s</a><br>
>>>>> >> ><br>
>>>>> >> > Video length is 4 seconds. Adding this sound makes it longer to 17<br>
>>>>> >> seconds.<br>
>>>>> >> > Looks like some parameters are wrong. Yes, AMR is recorded in mono so<br>
>>>>> >> > sample format converting is not needed. Thanks for help.<br>
>>>>> >><br>
>>>>> >> And sound is damaged when listening straight from recording?<br>
>>>>> >><br>
>>>>> >> ><br>
>>>>> >> ><br>
>>>>> >> > On 2 July 2015 at 10:14, Paul B Mahol <<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>> wrote:<br>
>>>>> >> ><br>
>>>>> >> >><br>
>>>>> >> >> Dana 2. 7. 2015. 07:58 osoba "adev dev" <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>><br>
>>>>> >> >> napisala je:<br>
>>>>> >> >><br>
>>>>> >> >> ><br>
>>>>> >> >> > Hi,<br>
>>>>> >> >> > thanks for answer.<br>
>>>>> >> >> ><br>
>>>>> >> >> > I cannot increase sound bitrate. I am using Android MediaRecorder<br>
>>>>> >> >> > and<br>
>>>>> >> >> AMR codec for recording audio. AMR is needed because I am doing Chrome<br>
>>>>> >> >> version where AAC codec is not working. This AMR codec at least in<br>
>>>>> >> >> Android<br>
>>>>> >> >> can only record with maximum bitrate 23600. It is not much but sound<br>
>>>>> >> >> should<br>
>>>>> >> >> be good. Now my result is that sound is totally crappy. There are<br>
>>>>> >> strange<br>
>>>>> >> >> pulses and if I record speech it is impossible to recognise words.<br>
>>>>> >> >> ><br>
>>>>> >> >> > I wonder what else could be the problem. When I am adding AAC files<br>
>>>>> >> >> > to<br>
>>>>> >> >> output video it is working correctly. Decoding AMR files and encoding<br>
>>>>> >> >> them<br>
>>>>> >> >> again to AAC is not working. For the first glance it looks that AMR<br>
>>>>> >> >> decoding is not working correctly. Or the frame is in format (not<br>
>>>>> >> planar)<br>
>>>>> >> >> and this makes problem. What do you think?<br>
>>>>> >> >> ><br>
>>>>> >> >> > This is how I read frames and decode them:<br>
>>>>> >> >> ><br>
>>>>> >> >> > static void encodeSoundNext(JNIEnv * env, jobject this) {<br>
>>>>> >> >> ><br>
>>>>> >> >> > if (input_context == NULL)<br>
>>>>> >> >> > return;<br>
>>>>> >> >> ><br>
>>>>> >> >> > int samples_size;<br>
>>>>> >> >> ><br>
>>>>> >> >> > frameRead = 0;<br>
>>>>> >> >> > char index = 0;<br>
>>>>> >> >> ><br>
>>>>> >> >> > AVFrame *decoded_frame = NULL;<br>
>>>>> >> >> ><br>
>>>>> >> >> > int input_audio_stream_index = get_stream_index(input_context,<br>
>>>>> >> >> AVMEDIA_TYPE_AUDIO);<br>
>>>>> >> >> ><br>
>>>>> >> >> > while (frameRead >= 0) {<br>
>>>>> >> >> ><br>
>>>>> >> >> > AVPacket in_packet;<br>
>>>>> >> >> ><br>
>>>>> >> >> > index++;<br>
>>>>> >> >> ><br>
>>>>> >> >> > frameRead = av_read_frame(input_context, &in_packet);<br>
>>>>> >> >> > if (frameRead < 0) {<br>
>>>>> >> >> > trackCompressionFinished = 1;<br>
>>>>> >> >> > avformat_close_input(&input_context);<br>
>>>>> >> >> ><br>
>>>>> >> >> > } else {<br>
>>>>> >> >> ><br>
>>>>> >> >> > if (decoded_frame == NULL) {<br>
>>>>> >> >> > if (!(decoded_frame = avcodec_alloc_frame())) {<br>
>>>>> >> >> > LOGE("out of memory");<br>
>>>>> >> >> > exit(1);<br>
>>>>> >> >> > }<br>
>>>>> >> >> > } else {<br>
>>>>> >> >> > avcodec_get_frame_defaults(decoded_frame);<br>
>>>>> >> >> > }<br>
>>>>> >> >> > int got_frame_ptr;<br>
>>>>> >> >> > samplesBytes = avcodec_decode_audio4(in_audio_st->codec,<br>
>>>>> >> >> > decoded_frame, &got_frame_ptr, &in_packet);<br>
>>>>> >> >> > if (samplesBytes < 0) {<br>
>>>>> >> >> > LOGE("Error occurred during decoding.");<br>
>>>>> >> >> > exit(1);<br>
>>>>> >> >> > break;<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> > write_audio_frame(oc, audio_st, decoded_frame);<br>
>>>>> >> >> > av_free_packet(&in_packet);<br>
>>>>> >> >> ><br>
>>>>> >> >> > }<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> > if (decoded_frame != NULL) {<br>
>>>>> >> >> > av_free(decoded_frame);<br>
>>>>> >> >> > decoded_frame = NULL;<br>
>>>>> >> >> > }<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > This is how I am encoding sound to AAC:<br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > static void write_audio_frame(AVFormatContext *oc, AVStream *st,<br>
>>>>> >> >> > const AVFrame *frame_to_encode) {<br>
>>>>> >> >> > AVCodecContext *c;<br>
>>>>> >> >> > AVPacket pkt;<br>
>>>>> >> >> > int got_packet_ptr = 0;<br>
>>>>> >> >> ><br>
>>>>> >> >> > av_init_packet(&pkt);<br>
>>>>> >> >> > c = st->codec;<br>
>>>>> >> >> > pkt.size = 0;<br>
>>>>> >> >> > pkt.data = NULL;<br>
>>>>> >> >> > int ret = avcodec_encode_audio2(c, &pkt, frame_to_encode,<br>
>>>>> >> >> &got_packet_ptr);<br>
>>>>> >> >> > if (ret < 0) {<br>
>>>>> >> >> > exit(1);<br>
>>>>> >> >> > }<br>
>>>>> >> >> > if (got_packet_ptr == 1) {<br>
>>>>> >> >> > if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) {<br>
>>>>> >> >> > pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base,<br>
>>>>> >> >> > st->time_base);<br>
>>>>> >> >> > }<br>
>>>>> >> >> > pkt.flags |= AV_PKT_FLAG_KEY;<br>
>>>>> >> >> > pkt.stream_index = st->index;<br>
>>>>> >> >> > // write the compressed frame in the media file<br>
>>>>> >> >> > if (av_interleaved_write_frame(oc, &pkt) != 0) {<br>
>>>>> >> >> > LOGE("Error while writing audio frame.");<br>
>>>>> >> >> > exit(1);<br>
>>>>> >> >> > }<br>
>>>>> >> >> > }<br>
>>>>> >> >> > av_free_packet(&pkt);<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > Audio stream is added to video file in this way:<br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > static AVStream *add_audio_stream(AVFormatContext *oc, enum<br>
>>>>> >> >> > AVCodecID<br>
>>>>> >> >> codec_id) {<br>
>>>>> >> >> ><br>
>>>>> >> >> > AVCodecContext *c;<br>
>>>>> >> >> > AVStream *st;<br>
>>>>> >> >> ><br>
>>>>> >> >> > st = avformat_new_stream(oc, NULL);<br>
>>>>> >> >> ><br>
>>>>> >> >> > c = st->codec;<br>
>>>>> >> >> > if (!st) {<br>
>>>>> >> >> > LOGE("Could not alloc stream.");<br>
>>>>> >> >> > return NULL;<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> > // AAC is expirimental in FFMPEG2.1<br>
>>>>> >> >> > c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;<br>
>>>>> >> >> ><br>
>>>>> >> >> > c->codec_id = codec_id;<br>
>>>>> >> >> > c->codec_type = AVMEDIA_TYPE_AUDIO;<br>
>>>>> >> >> > c->bit_rate = 23600; // bitrate of the compressed sound (must be<br>
>>>>> >> higher<br>
>>>>> >> >> for stereo)<br>
>>>>> >> >> ><br>
>>>>> >> >> > c->sample_rate = 16000;<br>
>>>>> >> >> > c->channels = 1;<br>
>>>>> >> >> > c->sample_fmt = AV_SAMPLE_FMT_FLT;<br>
>>>>> >> >> ><br>
>>>>> >> >> > if (oc->oformat->flags & AVFMT_GLOBALHEADER){<br>
>>>>> >> >> > c->flags |= CODEC_FLAG_GLOBAL_HEADER;<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> > return st;<br>
>>>>> >> >> > }<br>
>>>>> >> >> ><br>
>>>>> >> >> > What I noticed so far is that when I am decoding AAC files and<br>
>>>>> >> encoding<br>
>>>>> >> >> them again to audio stream in video files AAC frames has format<br>
>>>>> >> >> AV_SAMPLE_FMT_FLTP. AMR frames are in AV_SAMPLE_FMT_FLT format. Do you<br>
>>>>> >> >> think I have to convert some how from AV_SAMPLE_FMT_FLT to<br>
>>>>> >> >> AV_SAMPLE_FMT_FLTP?? Thanks for all hints.<br>
>>>>> >> >> ><br>
>>>>> >> >><br>
>>>>> >> >> For mono, single channel, conversion is not needed. If recording is of<br>
>>>>> >> >> bad<br>
>>>>> >> >> quality encoding you can only use some other amr encoder.<br>
>>>>> >> >><br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > On 1 July 2015 at 20:57, Talgorn Franc,ois-Xavier <<br>
>>>>> >> >> <a href="mailto:fxtalgorn-at-yahoo.fr@ffmpeg.org" target="_blank">fxtalgorn-at-yahoo.fr@ffmpeg.org</a>> wrote:<br>
>>>>> >> >> >><br>
>>>>> >> >> >> Hi,<br>
>>>>> >> >> >><br>
>>>>> >> >> >> I don't know about AMR codec but bitrate definitely impacts on<br>
>>>>> >> >> >> final<br>
>>>>> >> >> quality.<br>
>>>>> >> >> >> Try to increase bitrate value: I had same poor quality problems<br>
>>>>> >> >> >> with<br>
>>>>> >> >> MPEG4 encoding until I set the bitrate to width * height * 4.<br>
>>>>> >> >> >> Keep in mind that poor quality might comes from a wide bunch of<br>
>>>>> >> >> parameters used to initialize the codec.<br>
>>>>> >> >> >> As for example, this is how I initialize an MPEG4 codec (A]), for<br>
>>>>> >> >> clarity, in_ctx is initialized via the code in (B])<br>
>>>>> >> >> >><br>
>>>>> >> >> >> Concerning the delay issue: I also faced such a problem. I solved<br>
>>>>> >> >> >> it<br>
>>>>> >> >> using av_packet_rescale_ts() which relies on time_base, instead of<br>
>>>>> >> >> setting<br>
>>>>> >> >> timestamps myself manually.<br>
>>>>> >> >> >><br>
>>>>> >> >> >> I hope this comments will help put you on the road to success :-)<br>
>>>>> >> >> >><br>
>>>>> >> >> >> Good luck.<br>
>>>>> >> >> >><br>
>>>>> >> >> >> A]<br>
>>>>> >> >> >>     //codec found, now we param it<br>
>>>>> >> >> >>     o_codec_ctx->codec_id=AV_CODEC_ID_MPEG4;<br>
>>>>> >> >> >>     o_codec_ctx->bit_rate=in_ctx->picture_width *<br>
>>>>> >> >> in_ctx->picture_height * 4;<br>
>>>>> >> >> >><br>
>>>>> >> >><br>
>>>>> >> o_codec_ctx->width=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->width;<br>
>>>>> >> >> >><br>
>>>>> >> >><br>
>>>>> >> o_codec_ctx->height=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->height;<br>
>>>>> >> >> >>     o_codec_ctx->time_base =<br>
>>>>> >> >> in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->time_base;<br>
>>>>> >> >> >>     o_codec_ctx->ticks_per_frame =<br>
>>>>> >> >><br>
>>>>> >> in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->ticks_per_frame;<br>
>>>>> >> >> >>     o_codec_ctx->sample_aspect_ratio =<br>
>>>>> >> >><br>
>>>>> >> in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->sample_aspect_ratio;<br>
>>>>> >> >> >><br>
>>>>> >> >><br>
>>>>> >> o_codec_ctx->gop_size=in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->gop_size;<br>
>>>>> >> >> >>     o_codec_ctx->pix_fmt=AV_PIX_FMT_YUV420P;<br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >> B]<br>
>>>>> >> >> >>  // register all formats and codecs<br>
>>>>> >> >> >>     av_register_all();<br>
>>>>> >> >> >>     avcodec_register_all();<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     // open input file, and allocate format context<br>
>>>>> >> >> >>     if (avformat_open_input(&in_fmt_ctx, filename, NULL, NULL) < 0)<br>
>>>>> >> >> >>     {<br>
>>>>> >> >> >>         fprintf(stderr, "Could not open source file %s\n",<br>
>>>>> >> >> >> filename);<br>
>>>>> >> >> >>         exit(1);<br>
>>>>> >> >> >>     }<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     // retrieve stream information<br>
>>>>> >> >> >>     if (avformat_find_stream_info(in_fmt_ctx, NULL) < 0)<br>
>>>>> >> >> >>     {<br>
>>>>> >> >> >>         fprintf(stderr, "Could not find stream information\n");<br>
>>>>> >> >> >>         exit(1);<br>
>>>>> >> >> >>     }<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     if (open_codec_context(&video_stream_idx, in_fmt_ctx,<br>
>>>>> >> >> AVMEDIA_TYPE_VIDEO, filename) >= 0)<br>
>>>>> >> >> >>     {<br>
>>>>> >> >> >>         video_stream = in_fmt_ctx->streams[video_stream_idx];<br>
>>>>> >> >> >>         video_dec_ctx = video_stream->codec;<br>
>>>>> >> >> >>     }<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     if (open_codec_context(&audio_stream_idx, in_fmt_ctx,<br>
>>>>> >> >> AVMEDIA_TYPE_AUDIO, filename) >= 0) {<br>
>>>>> >> >> >>         audio_stream = in_fmt_ctx->streams[audio_stream_idx];<br>
>>>>> >> >> >>         audio_dec_ctx = audio_stream->codec;<br>
>>>>> >> >> >>     }<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     if (!video_stream) {<br>
>>>>> >> >> >>         fprintf(stderr, "Could not find video stream in the input,<br>
>>>>> >> >> aborting\n");<br>
>>>>> >> >> >>         avformat_close_input(&in_fmt_ctx);<br>
>>>>> >> >> >>         exit(0);<br>
>>>>> >> >> >>     }<br>
>>>>> >> >> >><br>
>>>>> >> >> >>     in_video_ctx->format_ctx=in_fmt_ctx;<br>
>>>>> >> >> >>     in_video_ctx->filename=filename;<br>
>>>>> >> >> >>     in_video_ctx->codec_name=(char *)<br>
>>>>> >> >> in_fmt_ctx->streams[video_stream_idx]->codec->codec->long_name;<br>
>>>>> >> >> >>     in_video_ctx->video_stream_idx=video_stream_idx;<br>
>>>>> >> >> >>     in_video_ctx->audio_stream_idx=audio_stream_idx;<br>
>>>>> >> >> >><br>
>>>>> >> >><br>
>>>>> >> in_video_ctx->picture_width=in_fmt_ctx->streams[video_stream_idx]->codec->width;<br>
>>>>> >> >> >><br>
>>>>> >> >><br>
>>>>> >> in_video_ctx->picture_height=in_fmt_ctx->streams[video_stream_idx]->codec->height;<br>
>>>>> >> >> >>     in_video_ctx->nb_streams=in_fmt_ctx->nb_streams;<br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >> Le 1 juil. 2015 `a 10:40, adev dev <<a href="mailto:androiddevmar11@gmail.com" target="_blank">androiddevmar11@gmail.com</a>> a<br>
>>>>> >> ecrit<br>
>>>>> >> >> >> :<br>
>>>>> >> >> >><br>
>>>>> >> >> >>> I am compressing movies from bitmaps and audio files. With AAC<br>
>>>>> >> >> >>> files<br>
>>>>> >> >> it is working correctly. But when I have AMR_WB files sound is<br>
>>>>> >> corrupted.<br>
>>>>> >> >> I<br>
>>>>> >> >> can recognise correct words in video file but it is delayed and with<br>
>>>>> >> very<br>
>>>>> >> >> bad quality.<br>
>>>>> >> >> >>><br>
>>>>> >> >> >>> My AMR files are recorded with parameters:<br>
>>>>> >> >> >>> - sampling rate: 16000,<br>
>>>>> >> >> >>> - bitrate: 23000.<br>
>>>>> >> >> >>><br>
>>>>> >> >> >>> I am setting this parameters in audio stream which is added to<br>
>>>>> >> video.<br>
>>>>> >> >> Sample format is set to AV_SAMPLE_FMT_FLT. When using other formats<br>
>>>>> >> >> app<br>
>>>>> >> >> crashes with "Unsupported sample format".<br>
>>>>> >> >> >>><br>
>>>>> >> >> >>> What needs to be done to correctly add AMR stream to video file?<br>
>>>>> >> >> >>> Do<br>
>>>>> >> I<br>
>>>>> >> >> have to reencode it to AAC and add as AAC audio stream?? Thank you for<br>
>>>>> >> >> all<br>
>>>>> >> >> hints.<br>
>>>>> >> >> >>> _______________________________________________<br>
>>>>> >> >> >>> Libav-user mailing list<br>
>>>>> >> >> >>> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> >> >> >>> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">
http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >><br>
>>>>> >> >> >> _______________________________________________<br>
>>>>> >> >> >> Libav-user mailing list<br>
>>>>> >> >> >> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> >> >> >> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">
http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>>> >> >> >><br>
>>>>> >> >> ><br>
>>>>> >> >> ><br>
>>>>> >> >> > _______________________________________________<br>
>>>>> >> >> > Libav-user mailing list<br>
>>>>> >> >> > <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> >> >> > <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">
http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>>> >> >> ><br>
>>>>> >> >><br>
>>>>> >> >> _______________________________________________<br>
>>>>> >> >> Libav-user mailing list<br>
>>>>> >> >> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> >> >> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">
http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>>> >> >><br>
>>>>> >> >><br>
>>>>> >> ><br>
>>>>> >> _______________________________________________<br>
>>>>> >> Libav-user mailing list<br>
>>>>> >> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> >> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">
http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>>> >><br>
>>>>> ><br>
>>>>> _______________________________________________<br>
>>>>> Libav-user mailing list<br>
>>>>> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>>>>> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>>>><br>
>>>><br>
>>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Libav-user mailing list<br>
> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">If the number of samples the decoder outputs differs from number of samples the encoder expects ( specified in AVCodecContext->frame_size ) you are supposed to
 cache the samples up until you have at least “AVCodecContext->frame_size” samples, from experience the encoder will pad your input sample array up to it’s desired size, and that is the noise you are hearing in output.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<pre><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Have a look at </span>AVAudioFifo<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p></o:p></span></pre>
<pre><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></pre>
<pre><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Regards,</span><o:p></o:p></pre>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
</div>
</div>
</body>
</html>