int main(int argc, char ** argv) { if (argc < 3) { fprintf(stderr, "need at least 3 arguments.\n"); exit(1); } av_register_all(); MediaSource ms; MediaMuxer muxer; ms.open(argv[1], 0); muxer.open(argv[2], ms.getFmtCtx(), true); AVPacket pkt; AVFrame * frame = NULL; while (!ms.read(&pkt)) { AVMediaType type = ms.getMediaType(&pkt); int ret = ms.decode(frame, &pkt); if (ret < 0) { fprintf(stderr, "decode error.\n"); exit(1); } if (ret == 0) continue; switch(type) { case AVMEDIA_TYPE_AUDIO: break; case AVMEDIA_TYPE_VIDEO: break; default: av_log(NULL, AV_LOG_INFO, "Unsupported packet type.\n"); break; } muxer.write(frame->data, frame->nb_samples, type); if (pkt.data) av_free_packet(&pkt); } muxer.close(); ms.close(); return 0; }
int main(int argc, char ** argv) { av_register_all(); MediaSource ms; AVPacket pkt; AVFrame * frame = avcodec_alloc_frame(); // AVFrame * dst_frame = avcodec_alloc_frame(); AVPicture picture; int index = 1; char str[100] = {0}; ms.open(argv[1], 1); VideoScale sc; sc.init(ms.getWidth(), ms.getHeight(), ms.getPixFormat(), 352, 288, ms.getPixFormat(), 0, NULL, NULL, NULL); avpicture_alloc(&picture, ms.getPixFormat(), 352, 288); while (ms.read(&pkt) == 0) { int ret = ms.decode(frame, &pkt); if (ret > 0) { if (ms.isVideoPacket(&pkt)) { if (index > 30) continue; snprintf(str, 100, "%02d.pgm", index++); sc.scale(frame->data, frame->linesize, 0, ms.getHeight(), picture.data, picture.linesize); pgm_save(picture.data[0], picture.linesize[0], 352, 288, str); } if (ms.isAudioPacket(&pkt)) { /* static AudioResample rsp; rsp.init(ms.getChannelLayout(), ms.getSampleFormat(), ms.getSampleRate(), ms.getChannelLayout(), ms.getSampleFormat(), ms.getSampleRate()); */ } } } ms.close(); return 0; }