fork(1) download
  1. void ffmmGG()
  2. {
  3.  
  4. AVFormatContext *pFormatCtx = NULL;
  5. int i, videoStream;
  6. AVCodecContext *pCodecCtx;
  7. AVCodec *pCodec;
  8. AVFrame *pFrame;
  9. AVFrame *pFrameRGB;
  10. AVPacket packet;
  11. int frameFinished;
  12. int numBytes;
  13. uint8_t *buffer;
  14.  
  15. av_register_all();
  16. if( avformat_open_input(&pFormatCtx, "01.rmvb", NULL, NULL) != 0 )
  17. return -1;
  18.  
  19. if( avformat_find_stream_info(pFormatCtx, NULL ) < 0 )
  20. return -1;
  21.  
  22. av_dump_format(pFormatCtx, -1, "01.rmvb", 0);
  23.  
  24. videoStream = -1;
  25. for( i = 0; i < pFormatCtx->nb_streams; i++ )
  26. {
  27. if( pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
  28. videoStream = i;
  29. break;
  30. }
  31. }
  32. if( videoStream == -1 )
  33. return -1;
  34.  
  35. pCodecCtx = pFormatCtx->streams[videoStream]->codec;
  36.  
  37. pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
  38. if( pCodec == NULL )
  39. return -1;
  40.  
  41. if( avcodec_open2(pCodecCtx, pCodec, NULL) < 0 )
  42. return -1;
  43.  
  44. pFrame = avcodec_alloc_frame();
  45. if( pFrame == NULL )
  46. return -1;
  47.  
  48. pFrameRGB = avcodec_alloc_frame();
  49. if( pFrameRGB == NULL )
  50. return -1;
  51.  
  52. numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
  53. pCodecCtx->height);
  54.  
  55. buffer = (uint8_t*)av_malloc(numBytes);
  56.  
  57. avpicture_fill( (AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
  58. pCodecCtx->width, pCodecCtx->height);
  59.  
  60. i = 0;
  61. while( av_read_frame(pFormatCtx, &packet) >= 0 )
  62. {
  63. if( packet.stream_index == videoStream )
  64. {
  65. avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
  66. if( frameFinished )
  67. {
  68. struct SwsContext *img_convert_ctx = NULL;
  69. img_convert_ctx =
  70. sws_getCachedContext(img_convert_ctx, pCodecCtx->width,
  71. pCodecCtx->height, pCodecCtx->pix_fmt,
  72. pCodecCtx->width, pCodecCtx->height,
  73. PIX_FMT_RGB24, SWS_BICUBIC,
  74. NULL, NULL, NULL);
  75. if( !img_convert_ctx )
  76. {
  77. fprintf(stderr, "Cannot initialize sws conversion context\n");
  78. exit(1);
  79. }
  80. sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data,
  81. pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data,
  82. pFrameRGB->linesize);
  83. if( i++ < 100 ) SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);
  84. else break;
  85. }
  86. }
  87. av_free_packet(&packet);
  88. }
  89. av_free(buffer);
  90. av_free(pFrameRGB);
  91. av_free(pFrame);
  92. avcodec_close(pCodecCtx);
  93. avformat_close_input(&pFormatCtx);
  94. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty