Guest User

Untitled

a guest
Apr 21st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. ====== Begin C code for testConsole.exe ======
  2.  
  3. #include <sandbox_DecoderTest.h>
  4.  
  5. #include <stdio.h>
  6.  
  7. #pragma comment( lib, "libavDecode.lib" )
  8.  
  9. void main()
  10. {
  11. decode();
  12. }
  13.  
  14. =END==========================================
  15. ====== Begin Java code for sandbox.DecoderTest ======
  16. package sandbox;
  17.  
  18. public class DecoderTest {
  19.  
  20. static {
  21. System.loadLibrary("libavDecode");
  22. }
  23.  
  24. public static native void startDecoder();
  25.  
  26.  
  27. public static void main(String[] args) {
  28. startDecoder();
  29. }
  30.  
  31. }
  32. =END==========================================
  33. ====== Begin C code for libavDecode.dll ======
  34. #include <windows.h>
  35. #include <stdio.h>
  36. #include <stdint.h>
  37. #include <sandbox_DecoderTest.h>
  38.  
  39. #include <jni.h>
  40.  
  41. extern "C"
  42. {
  43. #include <libavcodec\avcodec.h>
  44. }
  45.  
  46. JNIEXPORT void JNICALL Java_sandbox_DecoderTest_startDecoder(JNIEnv * env, jclass cls)
  47. {
  48. decode();
  49. }
  50.  
  51. void decode(){
  52. int width = 1024;
  53. int height = 768;
  54.  
  55. int fileSize;
  56. int got_pic;
  57. unsigned char *in_buffer;
  58.  
  59. AVCodecContext *codecContext = NULL;
  60. AVPacket *packet = new AVPacket;
  61. AVCodec *codec;
  62. AVFrame *picture;
  63.  
  64. avcodec_init();
  65. avcodec_register_all();
  66.  
  67. codec = avcodec_find_decoder(CODEC_ID_H264);
  68. codecContext = avcodec_alloc_context3(codec);
  69.  
  70. picture = avcodec_alloc_frame();
  71.  
  72. picture->linesize[0] = width;
  73. picture->linesize[1] = width>>1;
  74. picture->linesize[2] = width>>1;
  75.  
  76. int ret = avcodec_open(codecContext,codec);
  77. av_init_packet(packet);
  78.  
  79. FILE * f;
  80.  
  81. f = fopen ("C:\\out.h264","rb");
  82. if (f!=NULL)
  83. {
  84. fseek (f , 0 , SEEK_END);
  85. fileSize = ftell (f);
  86. rewind (f);
  87.  
  88. in_buffer = new unsigned char[fileSize];
  89. memset(in_buffer,0,8);
  90.  
  91. fread(in_buffer,fileSize,1,f);
  92. fclose (f);
  93. }
  94.  
  95.  
  96.  
  97. packet->data = in_buffer;
  98. packet->size = fileSize;
  99.  
  100. int len = avcodec_decode_video2(codecContext, picture, &got_pic, packet);
  101.  
  102. f = fopen ("C:\\finished.yuv","wb");
  103.  
  104. if (f!=NULL)
  105. {
  106. for(int i=0;i<height;i++)
  107. fwrite(picture->data[0] + i * picture->linesize[0],1,width,f);
  108.  
  109. for(int i=0;i<height;i++)
  110. fwrite(picture->data[1] + i * picture->linesize[1],1,width>>1,f);
  111.  
  112. for(int i=0;i<height;i++)
  113. fwrite(picture->data[2] + i * picture->linesize[2],1,width>>1,f);
  114. }
  115.  
  116. fclose(f);
  117. }
  118. =END==========================================
Add Comment
Please, Sign In to add comment