Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Javacv : Decoding H.264 "live" stream coming from red5 server on android device
26 mars 2015, par Ichigo KurosakiHere is my problem, I have implemented a server side application using Red5, which sends H.264 encoded live stream, on client side the stream is received as byte[]
In order to decode it on Android client side i have followed the Javacv-FFmpeg library. The code for decoding is as followspublic Frame decodeVideo(byte[] data,long timestamp){ frame.image = null; frame.samples = null; avcodec.av_init_packet(pkt); BytePointer video_data = new BytePointer(data); avcodec.AVCodec codec = avcodec.avcodec_find_decoder(codec_id); video_c = null; video_c = avcodec.avcodec_alloc_context3(codec); video_c.width(320); video_c.height(240); video_c.pix_fmt(0); video_c.flags2(video_c.flags2()|avcodec.CODEC_FLAG2_CHUNKS); avcodec.avcodec_open2(video_c, codec, null)) picture = avcodec.avcodec_alloc_frame() pkt.data(video_data); pkt.size(data.length); int len = avcodec.avcodec_decode_video2(video_c, picture, got_frame, pkt); if ((len >= 0) && ( got_frame[0] != 0)) { .... process the decoded frame into **IPLImage of Javacv** and render it with **Imageview** of Android } }
Data received from server is as follows
Few Frames having following pattern
17 01 00 00 00 00 00 00 02 09 10 00 00 00 0F 06 00 01 C0 01 07 09 08 04 9A 00 00 03 00 80 00 00 16 EF 65 88 80 07 00 05 6C 98 90 00...Many frames having following pattern
27 01 00 00 00 00 00 00 02 09 30 00 00 00 0C 06 01 07 09 08 05 9A 00 00 03 00 80 00 00 0D 77 41 9A 02 04 15 B5 06 20 E3 11 E2 3C 46 ....With H.264 codec for decoder, decoder outputs length >0 but got_frames=0 always.
With MPEG1 codec, decoder outputs length >0 and got_frames>0 but the output image is green or distorted.However following FFmpegFrameGrabber code of javacv i can decode the local files( H.264 encoded ) with similar code as above.
I wonder what details i am missing, and header related data manipulation or setting codec appropriate for decoder.
Any suggestion, help appreciated.
Thanks in advance. -
ffmpeg AVFrame to opencv Mat conversion
26 mars 2015, par YoohooI am currently work on a project which decode the received frame using ffmepg, after decode, I want to convert the AVFrame to opencv Mat frame so that I can play it on the imShow function.
What I have is the byte stream, I read it into buffer, decoded to AVFrame:
f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "Could not open %s\n", filename); exit(1); } frame = avcodec_alloc_frame(); if (!frame) { fprintf(stderr, "Could not allocate video frame\n"); exit(1); } framergb = avcodec_alloc_frame(); if (!framergb) { fprintf(stderr, "Could not allocate video frame\n"); exit(1); } bytes=avpicture_get_size(PIX_FMT_RGB24, CAMER_WIDTH, CAMER_HEIGHT); buffer=(uint8_t *)av_malloc(bytes*sizeof(uint8_t)); avpicture_fill((AVPicture *)framergb, buffer, PIX_FMT_RGB24, CAMER_WIDTH, CAMER_HEIGHT); frame_count = 0; for(;;) { avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); if (avpkt.size == 0) break; avpkt.data = inbuf; while (avpkt.size > 0) if (decode_write_frame(outfilename, c, frame, &frame_count, &avpkt, 0) < 0) exit(1); } avpkt.data = NULL; avpkt.size = 0; decode_write_frame(outfilename, c, frame, &frame_count, &avpkt, 1);
and the decode_write_frame defined like this:
static int decode_write_frame(const char *outfilename, AVCodecContext *avctx,AVFrame *frame, int *frame_count, AVPacket *pkt, int last) { int len, got_frame; char buf[1024]; struct SwsContext *convert_ctx; len = avcodec_decode_video2(avctx, frame, &got_frame, pkt); if (len < 0) { fprintf(stderr, "Error while decoding frame %d\n", *frame_count); return len; } if (got_frame) { printf("Saving %sframe %3d\n", last ? "last " : "", *frame_count); fflush(stdout); int w = avctx->width; int h = avctx->height; convert_ctx = sws_getContext(w, h, avctx->pix_fmt, w, h, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if(convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } sws_scale(convert_ctx, frame->data, frame->linesize, 0, h, framergb->data, framergb->linesize); /* the picture is allocated by the decoder, no need to free it */ snprintf(buf, sizeof(buf), outfilename, *frame_count); bmp_save(framergb->data[0], framergb->linesize[0], avctx->width, avctx->height, buf); (*frame_count)++; } if (pkt->data) { pkt->size -= len; pkt->data += len; } return 0; }
here the bmp_save() is defined by the original code author to realise AVFrame to bmp picture conversion. I want to modify here so that let the AVFrame convert to opencv Mat frame. How should I do this conversion?
Thanks in advance.
-
How to handle bitrate for the video in FFMPEG ?
26 mars 2015, par MahavirI am using the FFMPG to play video. The video is playing too slow on iPhone 5.
I have the following information.
Bitrate : 2788 kb/s.
metadata : h264(High) 1280*532 , q = 2-31
is this possible to decrease the metadata or bitrate to play video at normal speed.
-
Non-PIE FFMpeg 2.4.2 Binaries for Android Ice Cream Sandwich
26 mars 2015, par S.M.I am able to successfully utilize the PIE compatible FFMpeg binaries provided at https://github.com/hiteshsondhi88/ffmpeg-android/releases/download/v0.3.3/prebuilt-binaries.zip on Ice Cream Sandwich and above including Lollipop.
Since my app targets API Level 8+. Can you point me to an equivalent non-PIE binary that I could use in parallel with the newer binary to target API Level < 16? Thanks.
Regards, Sam
-
FFMPEG Video becomes very slow when bitrate is above 1000 per second ?
25 mars 2015, par user3772344I m showing video with using the ffmpeg library. But some of the video play too slowly special when its bitrate is more then 1000 per second.
Is there any way to load video faster? I am playing the video in iPhone.
Thanks.