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

ALESSANDRO PAGANELLI 83670 at studenti.unimore.it
Thu Mar 1 15:59:35 CET 2012


Andrey, thank you for your valuable suggestions.

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.

The way I setup both the stream and the codec is the following:

    outputStream->r_frame_rate = g_copyStream->r_frame_rate;
    outputStream->first_dts = g_copyStream->first_dts;
    outputStream->time_base = g_copyStream->time_base;

    outputStream->pts = g_copyStream->pts;

    outputStream->pts_wrap_bits = g_copyStream->pts_wrap_bits;
    outputStream->start_time = g_copyStream->start_time;
    outputStream->sample_aspect_ratio = g_copyStream->sample_aspect_ratio;
    outputStream->avg_frame_rate = g_copyStream->avg_frame_rate;

    /* Codec context copy */
    outputStream->codec->codec_type = g_inputCodecContext->codec_type;
    outputStream->codec->codec_id = g_inputCodecContext->codec_id;
    outputStream->codec->coder_type = g_inputCodecContext->coder_type;
    outputStream->codec->flags = g_inputCodecContext->flags;
    outputStream->codec->me_cmp = g_inputCodecContext->me_cmp;
    outputStream->codec->partitions = g_inputCodecContext->partitions;
    outputStream->codec->me_method = g_inputCodecContext->me_method;
    outputStream->codec->me_subpel_quality =
g_inputCodecContext->me_subpel_quality;
    outputStream->codec->me_range = g_inputCodecContext->me_range;

    outputStream->codec->bit_rate = g_inputCodecContext->bit_rate;
    outputStream->codec->width = g_inputCodecContext->width;
    outputStream->codec->height = g_inputCodecContext->height;
    outputStream->codec->has_b_frames = g_inputCodecContext->has_b_frames;
    outputStream->codec->sample_aspect_ratio =
outputStream->sample_aspect_ratio; // WARNING
    outputStream->codec->level = g_inputCodecContext->level;

    outputStream->codec->time_base.num = g_inputCodecContext->time_base.num;
    outputStream->codec->time_base.den = g_inputCodecContext->time_base.den;

    outputStream->codec->gop_size = g_inputCodecContext->gop_size;
    outputStream->codec->keyint_min = g_inputCodecContext->keyint_min;
    outputStream->codec->scenechange_threshold =
g_inputCodecContext->scenechange_threshold;
    outputStream->codec->i_quant_factor =
g_inputCodecContext->i_quant_factor;
    outputStream->codec->b_frame_strategy =
g_inputCodecContext->b_frame_strategy;
    outputStream->codec->qcompress = g_inputCodecContext->qcompress;
    outputStream->codec->qmin = g_inputCodecContext->qmin;
    outputStream->codec->qmax = g_inputCodecContext->qmax;
    outputStream->codec->max_qdiff = g_inputCodecContext->max_qdiff;
    outputStream->codec->max_b_frames = g_inputCodecContext->max_b_frames;
    outputStream->codec->refs = g_inputCodecContext->refs;
    outputStream->codec->directpred = g_inputCodecContext->directpred;
    outputStream->codec->trellis = g_inputCodecContext->trellis;
    outputStream->codec->flags2 = g_inputCodecContext->flags2;
    outputStream->codec->weighted_p_pred =
g_inputCodecContext->weighted_p_pred;

    outputStream->codec->crf = g_inputCodecContext->crf;
    outputStream->codec->pix_fmt = g_inputCodecContext->pix_fmt;
    outputStream->codec->thread_count = g_inputCodecContext->thread_count;

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 :(
Maybe the reason regards the outputStream settings...

Alessandro

Il giorno 01 marzo 2012 13:34, Andrey Utkin
<andrey.krieger.utkin at gmail.com>ha scritto:

> You didn't show how do you initialize contexts.
> You probably miss avformat_find_stream_info() call, or/and somewhat
> wrongly or incompletely copy file and codecs contexts settings (look
> at avcodec_copy_context())
>
> --
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120301/df2f88ec/attachment.html>


More information about the Libav-user mailing list