Andrey, thank you for your valuable suggestions. <div><br><div>I tried to use avformat_find_stream_info() (I did not use it before) but the program still fails, this time due to segmentation fault because g_inputFormatContext->streams[i]->info is NULL.</div>
<div>Maybe I did something wrong when i produced the original mp4 file with VLC.</div><div><br></div><div>The way I setup both the stream and the codec is the following:</div><div><br></div><div><div> outputStream->r_frame_rate = g_copyStream->r_frame_rate;</div>
<div> outputStream->first_dts = g_copyStream->first_dts;</div><div> outputStream->time_base = g_copyStream->time_base;</div><div><br></div><div> outputStream->pts = g_copyStream->pts;</div><div>
<br></div><div> outputStream->pts_wrap_bits = g_copyStream->pts_wrap_bits;</div><div> outputStream->start_time = g_copyStream->start_time;</div><div> outputStream->sample_aspect_ratio = g_copyStream->sample_aspect_ratio;</div>
<div> outputStream->avg_frame_rate = g_copyStream->avg_frame_rate;</div><div><br></div><div> /* Codec context copy */</div><div> outputStream->codec->codec_type = g_inputCodecContext->codec_type;</div>
<div> outputStream->codec->codec_id = g_inputCodecContext->codec_id;</div><div> outputStream->codec->coder_type = g_inputCodecContext->coder_type;</div><div> outputStream->codec->flags = g_inputCodecContext->flags;</div>
<div> outputStream->codec->me_cmp = g_inputCodecContext->me_cmp;</div><div> outputStream->codec->partitions = g_inputCodecContext->partitions;</div><div> outputStream->codec->me_method = g_inputCodecContext->me_method;</div>
<div> outputStream->codec->me_subpel_quality = g_inputCodecContext->me_subpel_quality;</div><div> outputStream->codec->me_range = g_inputCodecContext->me_range;</div><div><br></div><div> outputStream->codec->bit_rate = g_inputCodecContext->bit_rate;</div>
<div> outputStream->codec->width = g_inputCodecContext->width;</div><div> outputStream->codec->height = g_inputCodecContext->height;</div><div> outputStream->codec->has_b_frames = g_inputCodecContext->has_b_frames;</div>
<div> outputStream->codec->sample_aspect_ratio = outputStream->sample_aspect_ratio; // WARNING</div><div> outputStream->codec->level = g_inputCodecContext->level;</div><div><br></div><div> outputStream->codec->time_base.num = g_inputCodecContext->time_base.num;</div>
<div> outputStream->codec->time_base.den = g_inputCodecContext->time_base.den;</div><div><br></div><div> outputStream->codec->gop_size = g_inputCodecContext->gop_size;</div><div> outputStream->codec->keyint_min = g_inputCodecContext->keyint_min;</div>
<div> outputStream->codec->scenechange_threshold = g_inputCodecContext->scenechange_threshold;</div><div> outputStream->codec->i_quant_factor = g_inputCodecContext->i_quant_factor;</div><div> outputStream->codec->b_frame_strategy = g_inputCodecContext->b_frame_strategy;</div>
<div> outputStream->codec->qcompress = g_inputCodecContext->qcompress;</div><div> outputStream->codec->qmin = g_inputCodecContext->qmin;</div><div> outputStream->codec->qmax = g_inputCodecContext->qmax;</div>
<div> outputStream->codec->max_qdiff = g_inputCodecContext->max_qdiff;</div><div> outputStream->codec->max_b_frames = g_inputCodecContext->max_b_frames;</div><div> outputStream->codec->refs = g_inputCodecContext->refs;</div>
<div> outputStream->codec->directpred = g_inputCodecContext->directpred;</div><div> outputStream->codec->trellis = g_inputCodecContext->trellis;</div><div> outputStream->codec->flags2 = g_inputCodecContext->flags2;</div>
<div> outputStream->codec->weighted_p_pred = g_inputCodecContext->weighted_p_pred;</div><div><br></div><div> outputStream->codec->crf = g_inputCodecContext->crf;</div><div> outputStream->codec->pix_fmt = g_inputCodecContext->pix_fmt;</div>
<div> outputStream->codec->thread_count = g_inputCodecContext->thread_count;</div><div><br></div><div>I suppose that everything regarding the AVCodecContext can be greatly simplified by means of avcodec_copy_context(), but a new issue arise, since now the output file is 0 byte :(</div>
<div>Maybe the reason regards the outputStream settings...</div><div><br></div><div>Alessandro</div><br><div class="gmail_quote">Il giorno 01 marzo 2012 13:34, Andrey Utkin <span dir="ltr"><<a href="mailto:andrey.krieger.utkin@gmail.com" target="_blank">andrey.krieger.utkin@gmail.com</a>></span> ha scritto:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You didn't show how do you initialize contexts.<br>
You probably miss avformat_find_stream_info() call, or/and somewhat<br>
wrongly or incompletely copy file and codecs contexts settings (look<br>
at avcodec_copy_context())<br>
<span><font color="#888888"><br>
--<br>
Andrey Utkin<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>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>______________________________________________<br><br>Ing. Alessandro Paganelli, Ph. D. Student, 25th Cycle<br><br>Department of Information Engineering<br>
University of Modena and Reggio Emilia<br>via Vignolese 905, 41125 Modena (MO), ITALY<br><br>E-mail: <a href="mailto:alessandro.paganelli@unimore.it" target="_blank">alessandro.paganelli@unimore.it</a><br>
</div></div>