Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Source file c:\out.h264 is encoded using x264 - contains only one packet containing a single 1024x768 frame
- No errors when running testConsole.exe.
- Running java sandbox.DecoderTest results in the following error and then subsequently crashes:
- [h264 @ 004f3f60] get_buffer() failed (-1 0 0 00000000)
- [h264 @ 004f3f60] decode_slice_header error
- [h264 @ 004f3f60] no frame!
- ====== Begin C code for testConsole.exe ======
- #include <sandbox_DecoderTest.h>
- #include <stdio.h>
- #pragma comment( lib, "libavDecode.lib" )
- void main()
- {
- decode();
- }
- =END==========================================
- ====== Begin Java code for sandbox.DecoderTest ======
- package sandbox;
- public class DecoderTest {
- static {
- System.loadLibrary("libavDecode");
- }
- public static native void startDecoder();
- public static void main(String[] args) {
- startDecoder();
- }
- }
- =END==========================================
- ====== Begin C code for libavDecode.dll ======
- #include <windows.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <sandbox_DecoderTest.h>
- #include <jni.h>
- extern "C"
- {
- #include <libavcodec\avcodec.h>
- }
- JNIEXPORT void JNICALL Java_sandbox_DecoderTest_startDecoder(JNIEnv * env, jclass cls)
- {
- decode();
- }
- void decode(){
- int width = 1024;
- int height = 768;
- int fileSize;
- int got_pic;
- unsigned char *in_buffer;
- AVCodecContext *codecContext = NULL;
- AVPacket *packet = new AVPacket;
- AVCodec *codec;
- AVFrame *picture;
- avcodec_init();
- avcodec_register_all();
- codec = avcodec_find_decoder(CODEC_ID_H264);
- codecContext = avcodec_alloc_context3(codec);
- picture = avcodec_alloc_frame();
- picture->linesize[0] = width;
- picture->linesize[1] = width>>1;
- picture->linesize[2] = width>>1;
- int ret = avcodec_open(codecContext,codec);
- av_init_packet(packet);
- FILE * f;
- f = fopen ("C:\\out.h264","rb");
- if (f!=NULL)
- {
- fseek (f , 0 , SEEK_END);
- fileSize = ftell (f);
- rewind (f);
- in_buffer = new unsigned char[fileSize];
- memset(in_buffer,0,8);
- fread(in_buffer,fileSize,1,f);
- fclose (f);
- }
- packet->data = in_buffer;
- packet->size = fileSize;
- int len = avcodec_decode_video2(codecContext, picture, &got_pic, packet);
- f = fopen ("C:\\finished.yuv","wb");
- if (f!=NULL)
- {
- for(int i=0;i<height;i++)
- fwrite(picture->data[0] + i * picture->linesize[0],1,width,f);
- for(int i=0;i<height;i++)
- fwrite(picture->data[1] + i * picture->linesize[1],1,width>>1,f);
- for(int i=0;i<height;i++)
- fwrite(picture->data[2] + i * picture->linesize[2],1,width>>1,f);
- }
- fclose(f);
- }
- =END==========================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement