[Libav-user] Getting a Frame question

M J assemblerx86 at yandex.com
Sat Sep 3 23:55:17 EEST 2016


Hi,

 I have seen a few examples such as transcoding.c, muxing.c, but I couldn't understand how to directly take a frame from a certain video stream (Of type AVStream) to another stream in another video file. av_read_frame reads the frame from the whole AVFormatContext, which I don't understand why it doesn't take AVStream as a parameter? Or does it take all the frames from all streams at the same elapsed time?  I have tried this code to read frame from a video file and write it to another (After initializing both AVFrameContext for input and output, and also writing the header to the output file):
*************************************************
AVFrame *rawFrame = av_frame_alloc();

AVPacket *pkts = av_packet_alloc();
av_init_packet(pkts);
AVPacket *pktr = av_packet_alloc();
av_init_packet(pktr);

while(av_read_frame(input_ctx, pkts) == 0)
{
        //decoding
        int ret1 = avcodec_send_packet(input_codecCtx, pkts);
        int ret2 = avcodec_receive_frame(input_codecCtx, rawFrame);

        //encoding
        avcodec_send_frame(output_codecCtx, rawFrame);
        avcodec_receive_packet(output_codecCtx, pktr);

        int ret = av_interleaved_write_frame(output_ctx, pktr);
}
*************************************************

 But it doesn't work, no frames are written into the output file, and ret1 and ret2 return error "invalid argument'.

Thanks.


More information about the Libav-user mailing list