Advertisement
Guest User

Untitled

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