Newest 'libx264' Questions - Stack Overflow
Les articles publiés sur le site
-
Android h264 decode non-existing PPS 0 referenced
8 juin 2023, par nmxprimeIn Android JNI, using
ffmpeg with libx264
use below codes to encode and decode raw rgb data!. I should use swscale to convert rgb565 to yuv420p as required by H.264. But not clear about this conversion.Please help, where i am wrong, with regard the log i get!Code for Encoding
codecinit()- called once(JNI wrapper function)
int Java_com_my_package_codecinit (JNIEnv *env, jobject thiz) { avcodec_register_all(); codec = avcodec_find_encoder(AV_CODEC_ID_H264);//AV_CODEC_ID_MPEG1VIDEO); if(codec->id == AV_CODEC_ID_H264) __android_log_write(ANDROID_LOG_ERROR, "set","h264_encoder"); if (!codec) { fprintf(stderr, "codec not found\n"); __android_log_write(ANDROID_LOG_ERROR, "codec", "not found"); } __android_log_write(ANDROID_LOG_ERROR, "codec", "alloc-contest3"); c= avcodec_alloc_context3(codec); if(c == NULL) __android_log_write(ANDROID_LOG_ERROR, "avcodec","context-null"); picture= av_frame_alloc(); if(picture == NULL) __android_log_write(ANDROID_LOG_ERROR, "picture","context-null"); c->bit_rate = 400000; c->height = 800; c->time_base= (AVRational){1,25}; c->gop_size = 10; c->max_b_frames=1; c->pix_fmt = AV_PIX_FMT_YUV420P; outbuf_size = 768000; c->width = 480; size = (c->width * c->height); if (avcodec_open2(c, codec,NULL) < 0) { __android_log_write(ANDROID_LOG_ERROR, "codec", "could not open"); } ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height, c->pix_fmt, 32); if (ret < 0) { __android_log_write(ANDROID_LOG_ERROR, "image","alloc-failed"); fprintf(stderr, "could not alloc raw picture buffer\n"); } picture->format = c->pix_fmt; picture->width = c->width; picture->height = c->height; return 0; }
encodeframe()-called in a while loop
int Java_com_my_package_encodeframe (JNIEnv *env, jobject thiz,jbyteArray buffer) { jbyte *temp= (*env)->GetByteArrayElements(env, buffer, 0); Output = (char *)temp; const uint8_t * const inData[1] = { Output }; const int inLinesize[1] = { 2*c->width }; //swscale should implement here av_init_packet(&pkt); pkt.data = NULL; // packet data will be allocated by the encoder pkt.size = 0; fflush(stdout); picture->data[0] = Output; ret = avcodec_encode_video2(c, &pkt, picture,&got_output); fprintf(stderr,"ret = %d, got-out = %d \n",ret,got_output); if (ret < 0) { __android_log_write(ANDROID_LOG_ERROR, "error","encoding"); if(got_output > 0) __android_log_write(ANDROID_LOG_ERROR, "got_output","is non-zero"); } if (got_output) { fprintf(stderr,"encoding frame %3d (size=%5d): (ret=%d)\n", 1, pkt.size,ret); fprintf(stderr,"before caling decode"); decode_inline(&pkt); //function that decodes right after the encode fprintf(stderr,"after caling decode"); av_free_packet(&pkt); } fprintf(stderr,"y val: %d \n",y); (*env)->ReleaseByteArrayElements(env, buffer, Output, 0); return ((ret)); }
decode_inline() function
decode_inline(AVPacket *avpkt){ AVCodec *codec; AVCodecContext *c = NULL; int frame, got_picture, len = -1,temp=0; AVFrame *rawFrame, *rgbFrame; uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; char buf[1024]; char rawBuf[768000],rgbBuf[768000]; struct SwsContext *sws_ctx; memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE); avcodec_register_all(); c= avcodec_alloc_context3(codec); if(c == NULL) __android_log_write(ANDROID_LOG_ERROR, "avcodec","context-null"); codec = avcodec_find_decoder(AV_CODEC_ID_H264); if (!codec) { fprintf(stderr, "codec not found\n"); fprintf(stderr, "codec = %p \n", codec); } c->pix_fmt = AV_PIX_FMT_YUV420P; c->width = 480; c->height = 800; rawFrame = av_frame_alloc(); rgbFrame = av_frame_alloc(); if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } sws_ctx = sws_getContext(c->width, c->height,/*PIX_FMT_RGB565BE*/ PIX_FMT_YUV420P, c->width, c->height, AV_PIX_FMT_RGB565/*PIX_FMT_YUV420P*/, SWS_BILINEAR, NULL, NULL, NULL); frame = 0; unsigned short *decodedpixels = &rawBuf; rawFrame->data[0] = &rawBuf; rgbFrame->data[0] = &rgbBuf; fprintf(stderr,"size of avpkt %d \n",avpkt->size); temp = avpkt->size; while (temp > 0) { len = avcodec_decode_video2(c, rawFrame, &got_picture, avpkt); if (len < 0) { fprintf(stderr, "Error while decoding frame %d\n", frame); exit(1); } temp -= len; avpkt->data += len; if (got_picture) { printf("saving frame %3d\n", frame); fflush(stdout); //TODO //memcpy(decodedpixels,rawFrame->data[0],rawFrame->linesize[0]); // decodedpixels +=rawFrame->linesize[0]; frame++; } } avcodec_close(c); av_free(c); //free(rawBuf); //free(rgbBuf); av_frame_free(&rawFrame); av_frame_free(&rgbFrame);
}
The log i get
For the decode_inline() function:
01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error 01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] Invalid mix of idr and non-idr slices 01-02 14:50:50.160: I/stderr(3407): Error while decoding frame 0
Edit: Changing GOP value:
If i change
c->gop_size = 3;
as expected it emitsone I frame
every three frames. Thenon-existing PPS 0 referenced
message is not there for in every third execution, but all other have this message -
Flutter PNG screenshots are not working properly with FFMPEG
7 juin 2023, par seggaI'm trying to convert screenshots I took in my flutter app programmatically to an .mp4 video, but the video is just black/blank. I'm using PNG to encode the images saved and the .PNG extension too. This is the code base I'm currently using and I expected to be able to use these images with ffmpeg. I also tried the ImageFormat.rawRgba or so but I don't think I used that properly
import 'dart:io'; import 'package:flutter/rendering.dart'; void captureScreenshot() async { try { RenderRepaintBoundary boundary = globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary; ui.Image image = await boundary.toImage(pixelRatio: 1.0); ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png); Uint8List imageData = byteData!.buffer.asUint8List(); // Save the image to a file File file = File('/path/to/screenshot.png'); await file.writeAsBytes(imageData); print('Screenshot saved successfully!'); } catch (e) { print('Error capturing screenshot: $e'); } }
-
How to extract per Coding Tree Unit (CTU) Quantization Parameter (QP) from a h.265 encoded video [closed]
16 avril 2023, par ali falahatiI want to extract and analyze per CTU or per macro-block information such as QP value from a encoded video file.
All the methods I found are either changing the ffmpeg source code or deprecated tools. Also other questions are not answered correctly. I wanted to know if there is a simple, straight forward and up to date tutorial on how to extract QP values from an encoded video file using tools such as HM or ffmpeg. Even if the only way to do it is to change the source code of ffmpeg please provide a clear explanation of what to do and change.
-
How to fix the "No working C compiler found." problem for compiling x264 in Linux ?
27 février 2023, par gc xuFirstly I have read all other solutions related to this problem, including adding path and reinstall yasm, nasm, gcc... I git clone the source code from https://code.videolan.org/videolan/x264.git. Then, I run command ./configure, it shows
./configure: line 169: conftest.log: Invalid argument ./configure: line 169: conftest.log: Invalid argument ./configure: line 169: conftest.log: Invalid argument ./configure: line 169: conftest.log: Invalid argument No working C compiler found.
I check the file "config.log". It shows:
checking for -Werror=unknown-warning-option... no Failed commandline was: -------------------------------------------------- gcc conftest.c -Wall -I. -I$(SRCPATH) -Werror=unknown-warning-option -o conftest cc1: error: ‘-Werror=unknown-warning-option’: no option -Wunknown-warning-option -------------------------------------------------- Failed program was: -------------------------------------------------- int main (void) { return 0; } -------------------------------------------------- checking for -Werror=unknown-attributes... no Failed commandline was: -------------------------------------------------- gcc conftest.c -Wall -I. -I$(SRCPATH) -Werror=unknown-attributes -o conftest cc1: error: ‘-Werror=unknown-warning-option’: no option -Wunknown-warning-option -------------------------------------------------- Failed program was: -------------------------------------------------- int main (void) { return 0; } -------------------------------------------------- checking for -Werror=attributes... no Failed commandline was: -------------------------------------------------- gcc conftest.c -Wall -I. -I$(SRCPATH) -Werror=attributes -o conftest cc1: error: ‘-Werror=unknown-warning-option’: no option -Wunknown-warning-option -------------------------------------------------- Failed program was: -------------------------------------------------- int main (void) { return 0; } -------------------------------------------------- checking for -Werror=ignored-attributes... no Failed commandline was: -------------------------------------------------- gcc conftest.c -Wall -I. -I$(SRCPATH) -Werror=ignored-attributes -o conftest cc1: error: ‘-Werror=unknown-warning-option’: no option -Wunknown-warning-option -------------------------------------------------- Failed program was: -------------------------------------------------- int main (void) { return 0; } -------------------------------------------------- x264 configure script Command line options: "--enable-shared" "--enable-static" checking whether gcc works... no Failed commandline was: -------------------------------------------------- gcc conftest.c -m64 -Wall -I. -I$(SRCPATH) -m64 -lm -o conftest cc1: error: ‘-Werror=unknown-warning-option’: no option -Wunknown-warning-option -------------------------------------------------- Failed program was: -------------------------------------------------- int main (void) { return 0; } -------------------------------------------------- DIED: No working C compiler found.
Plus I wonder is there something to do with nasm? Becasuse I install nasm with some C grammer problems:
./config/config.h:659:16: error: duplicate ‘unsigned’ 659 | #define size_t unsigned int | ^~~~~~~~ ./config/config.h:659:25: error: two or more data types in declaration specifiers 659 | #define size_t unsigned int | ^~~ In file included from /usr/include/string.h:633, from ./include/compiler.h:89, from asm/nasm.c:38: ./include/compiler.h:241:7: error: expected identifier or ‘(’ before ‘__extension__’ 241 | char *strsep(char **, const char *); | ^~~~~~ ./include/compiler.h:241:7: error: expected identifier or ‘(’ before ‘)’ token 241 | char *strsep(char **, const char *); | ^~~~~~ make[1]: *** [asm/nasm.o] Error 1 make[1]: Leaving directory `/mnt/nfs0/gengcheng/ffmpeg-5.0.2/nasm-2.15.05' make: *** [all] Error 2
I have read all other solutions related to this problem, including adding path and reinstall yasm, nasm, gcc... I want to install x264 to configure it in ffmpeg. Thanks for all your answers!
-
How to use x264 encoder in Ant Media Server v2.5
26 février 2023, par farawayAnt Media Server starts to use OpenH264 as a software encoder in v2.5 but I need to use x264. How can I use x264 in Ant Media Server v2.5?
https://github.com/ant-media/Ant-Media-Server/releases/tag/ams-v2.5.0 https://antmedia.io