Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- av_register_all();
- AVFormatContext *ps = avformat_alloc_context();
- AVFormatContext *ps2 = avformat_alloc_context();
- AVOutputFormat *oF = av_guess_format("mp4", NULL, "video/mp4");
- avformat_alloc_output_context2(&ps2, oF, NULL, "vid2.mp4");
- if(avformat_open_input(&ps, "vid.mp4", NULL, NULL) != 0)
- {
- printf("Failed to open input file.\n");
- return -1;
- }
- avio_open(&ps2->pb, "vid2.mp4", AVIO_FLAG_WRITE);
- avformat_find_stream_info(ps, NULL);
- // AVStream *iStream;
- //AVStream *oStream;
- AVCodecContext *pC, *p2C;
- //AVCodec *encoder;
- AVStream *oStream = NULL;
- AVStream *iStream = NULL;
- AVCodec *encoder = NULL;
- for(unsigned int i = 0; i < ps->nb_streams; i++)
- {
- oStream = avformat_new_stream(ps2, NULL);
- iStream = ps->streams[i];
- pC = iStream->codec;
- avcodec_parameters_copy(oStream->codecpar, iStream->codecpar);
- if(pC->codec_type == AVMEDIA_TYPE_VIDEO || pC->codec_type == AVMEDIA_TYPE_AUDIO)
- {
- encoder = avcodec_find_encoder(pC->codec_id);
- avcodec_parameters_to_context(p2C, iStream->codecpar);
- avcodec_open2(p2C, encoder, NULL);
- avcodec_open2(pC, avcodec_find_decoder(pC->codec_id), NULL);
- }
- }
- avformat_write_header(ps2, NULL);
- printf("Fine\n");
- 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(ps, pkts) == 0)
- {
- //decoding
- int ret1 = avcodec_send_packet(pC, pkts);
- int ret2 = avcodec_receive_frame(pC, rawFrame);
- //encoding
- avcodec_send_frame(p2C, rawFrame);
- avcodec_receive_packet(p2C, pktr);
- int ret = av_interleaved_write_frame(ps2, pktr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement