Andrey, I finally managed to solve the issue! Thanks a lot :)  <div><br></div><div>Here, I briefly report what I did (the complete code can be found in the attached source file).<div><br></div><div><div>    if (avcodec_copy_context(outputStream->codec, g_inputCodecContext))</div>
<div>      {</div><div>        printf("Codec context copy error! Exit!\n");</div><div>        exit(1);</div><div>      }</div><div><br></div><div>    outputStream->pts = (AVFrac) {</div><div>                                  g_copyStream->pts.val,</div>
<div>                                  (int64_t) g_inputCodecContext->time_base.num,</div><div>                                  (int64_t) g_inputCodecContext->time_base.den</div><div>                                 };</div>
<div><br></div><div>    outputStream->codec->time_base = g_copyStream->time_base;</div><div>    outputStream->sample_aspect_ratio = g_copyStream->sample_aspect_ratio;</div><div>    outputStream->codec->sample_aspect_ratio = outputStream->sample_aspect_ratio;</div>
<div>    outputStream->codec->codec_tag = 0;</div><div><br></div><div>First I copy the AVCodecContext from the source to the destination; then, I setup the various fields required to have coherent information between the stream and the codec.</div>
<div>Finally, I put codec_tag = 0 to avoid a segmentation fault, maybe due to a wrong setup in the original coded file (it seems that the original coded file has a codec_tag which is not compatible with the codec itself, i.e., h264).</div>
<div><br></div><div>Again, thanks a lot!</div><div>Best regards,</div><div><br></div><div>Alessandro</div><div><br></div><div class="gmail_quote">Il giorno 01 marzo 2012 16:51, ALESSANDRO PAGANELLI <span dir="ltr"><<a href="mailto:83670@studenti.unimore.it">83670@studenti.unimore.it</a>></span> ha scritto:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Again, thank you Andrey for your help. <div>I'll try to search through your code to find a useful clue for my issues!</div>
<div><br></div><div>Best regards,</div><div>Alessandro<br><br><div class="gmail_quote">Il giorno 01 marzo 2012 16:47, Andrey Utkin <span dir="ltr"><<a href="mailto:andrey.krieger.utkin@gmail.com" target="_blank">andrey.krieger.utkin@gmail.com</a>></span> ha scritto:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2012/3/1 ALESSANDRO PAGANELLI <<a href="mailto:83670@studenti.unimore.it" target="_blank">83670@studenti.unimore.it</a>>:<br>

<div>> I tried to use avformat_find_stream_info() (I did not use it before) but the<br>
> program still fails, this time due to segmentation fault because<br>
> g_inputFormatContext->streams[i]->info is NULL.<br>
> Maybe I did something wrong when i produced the original mp4 file with VLC.<br>
<br>
</div>Fail you got may be caused by wrong invocation of the function, but it<br>
is right way to go. I encourage you to use this function. The same<br>
about avcodec_copy_context() - it is right to use it, but not to copy<br>
everything manually, as you do now.<br>
<br>
You can take my remux app as an example. But watch out - it is not<br>
general-purposed, but just for exact use case.<br>
<a href="https://github.com/krieger-od/imgs2video/blob/master/cat.c" target="_blank">https://github.com/krieger-od/imgs2video/blob/master/cat.c</a><br>
<br>
Also there's very simple skeleton of remultiplexing:<br>
<a href="https://gist.github.com/1950618" target="_blank">https://gist.github.com/1950618</a><br>
<div><div><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>
</div></div></blockquote></div></div></div><br><br clear="all"><div class="im"><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>
</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">alessandro.paganelli@unimore.it</a><br>
</div></div>