[Libav-user] Simple packet-by-packet copy does not work for h264+mp4

ALESSANDRO PAGANELLI 83670 at studenti.unimore.it
Fri Mar 2 10:00:55 CET 2012


Andrey, I finally managed to solve the issue! Thanks a lot :)

Here, I briefly report what I did (the complete code can be found in the
attached source file).

    if (avcodec_copy_context(outputStream->codec, g_inputCodecContext))
      {
        printf("Codec context copy error! Exit!\n");
        exit(1);
      }

    outputStream->pts = (AVFrac) {
                                  g_copyStream->pts.val,
                                  (int64_t)
g_inputCodecContext->time_base.num,
                                  (int64_t)
g_inputCodecContext->time_base.den
                                 };

    outputStream->codec->time_base = g_copyStream->time_base;
    outputStream->sample_aspect_ratio = g_copyStream->sample_aspect_ratio;
    outputStream->codec->sample_aspect_ratio =
outputStream->sample_aspect_ratio;
    outputStream->codec->codec_tag = 0;

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.
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).

Again, thanks a lot!
Best regards,

Alessandro

Il giorno 01 marzo 2012 16:51, ALESSANDRO PAGANELLI <
83670 at studenti.unimore.it> ha scritto:

> Again, thank you Andrey for your help.
> I'll try to search through your code to find a useful clue for my issues!
>
> Best regards,
> Alessandro
>
> Il giorno 01 marzo 2012 16:47, Andrey Utkin <
> andrey.krieger.utkin at gmail.com> ha scritto:
>
> 2012/3/1 ALESSANDRO PAGANELLI <83670 at studenti.unimore.it>:
>> > 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.
>> > Maybe I did something wrong when i produced the original mp4 file with
>> VLC.
>>
>> Fail you got may be caused by wrong invocation of the function, but it
>> is right way to go. I encourage you to use this function. The same
>> about avcodec_copy_context() - it is right to use it, but not to copy
>> everything manually, as you do now.
>>
>> You can take my remux app as an example. But watch out - it is not
>> general-purposed, but just for exact use case.
>> https://github.com/krieger-od/imgs2video/blob/master/cat.c
>>
>> Also there's very simple skeleton of remultiplexing:
>> https://gist.github.com/1950618
>>
>> --
>> Andrey Utkin
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
>
>
> --
> ______________________________________________
>
> Ing. Alessandro Paganelli, Ph. D. Student, 25th Cycle
>
> Department of Information Engineering
> University of Modena and Reggio Emilia
> via Vignolese 905, 41125 Modena (MO), ITALY
>
> E-mail: alessandro.paganelli at unimore.it
>



-- 
______________________________________________

Ing. Alessandro Paganelli, Ph. D. Student, 25th Cycle

Department of Information Engineering
University of Modena and Reggio Emilia
via Vignolese 905, 41125 Modena (MO), ITALY

E-mail: alessandro.paganelli at unimore.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120302/d6d35da5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-264-recovery-ml.c
Type: text/x-csrc
Size: 6511 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120302/d6d35da5/attachment.bin>


More information about the Libav-user mailing list