[Libav-user] Getting a Frame question

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


 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();
AVPacket *pktr = av_packet_alloc();

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

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


More information about the Libav-user mailing list