Newest 'x264' Questions - Stack Overflow
Les articles publiés sur le site
-
h264 ffmpeg : How to initialize ffmpeg to decode NALs created with x264
19 février 2024, par Raul CalvoI encoded some frames using x264, using
x264_encoder_encode()
and after that I createdAVPackets
using a function like this:bool PacketizeNals( uint8_t* a_pNalBuffer, int a_nNalBufferSize, AVPacket* a_pPacket ) { if ( !a_pPacket ) return false; a_pPacket->data = a_pNalBuffer; a_pPacket->size = a_nNalBufferSize; a_pPacket->stream_index = 0; a_pPacket->flags = AV_PKT_FLAG_KEY; a_pPacket->pts = int64_t(0x8000000000000000); a_pPacket->dts = int64_t(0x8000000000000000); }
I call this function like this:
x264_nal_t* nals; int num_nals = encode_frame(pic, &nals); for (int i = 0; i < num_nals; i++) { AVPacket* pPacket = ( AVPacket* )av_malloc( sizeof( AVPacket ) ); av_init_packet( pPacket ); if ( PacketizeNals( nals[i].p_payload, nals[i].i_payload, pPacket ) ) { packets.push_back( pPacket ); } }
Now what I want to do is to decode these
AVPackets
usingavcodec_decode_video2
. I think the problem is that I haven't properly initialized the decoder because to encode I used "ultrafast" profile and "zerolatency" tune (x264) and to decode I don't know how to specify these options to ffmpeg.In some examples I have read people initialize the decoder using the file where the video is stored, but in this case I have the
AVPackets
directly.What I'm doing to try to decode is:
avcodec_init(); avcodec_register_all(); AVCodec* pCodec; pCodec=avcodec_find_decoder(CODEC_ID_H264); AVCodecContext* pCodecContext; pCodecContext=avcodec_alloc_context(); avcodec_open(pCodecContext,pCodec); pCodecContext->width = 320; pCodecContext->height = 200; pCodecContext->extradata = NULL; unsigned int nNumPackets = packets.size(); int frameFinished = 0; for ( auto it = packets.begin(); it != packets.end(); it++ ) { AVFrame* pFrame; pFrame = avcodec_alloc_frame(); AVPacket* pPacket = *it; int iReturn = avcodec_decode_video2( pCodecContext, pFrame, &frameFinished, pPacket ); }
But
iReturn
is always -1.Can anyone help me? Sorry if my knowledge in this area is low, I'm new.
-
how to use x264 dll in another project
7 février 2024, par Hadi RasekhI want to use x264 in my project. There is some line in the code said:
`/* Application developers planning to link against a shared library version of
- libx264 from a Microsoft Visual Studio or similar development environment
- will need to define X264_API_IMPORTS before including this header.
- This clause does not apply to MinGW, similar development environments, or non
- Windows platforms. */`
But I don't get this line: define X264_API_IMPORTS before including this header
We can create x264 dll by its configuration and make
./configure --enable-shared make
but I can not use the dll in my Qt Project.
I can make my own dll (in another code) and use it in the project. But when I start to use x264 dll in my project I get the following error:
C:\DataHiding\SourceCode2\GUI\DataHiding\mainwindow.cpp:10: error: 'pulldown_frame_duration' was not declared in this scope qDebug() << pulldown_frame_duration[1]; ^
-
How to limit the maximum bitrate of x264 ?
23 janvier 2024, par Chan CharisI want to encode Blu-ray M2TS files with x264, my code is like this:
enc_ctx = avcodec_alloc_context3(codec); enc_ctx->codec_id = AV_CODEC_ID_H264; enc_ctx->bit_rate = 20000000;
When a video has a simple scene, such as 10 seconds, its encoding bitrate will be very small, only 1M or 2M bitrate. In order to achieve an average bitrate of 20M/s, the subsequent bitrate will be very large, sometimes reaching 150M/s. , at this time Blu-ray Player will freeze due to high bitrate. I set
enc_ctx->rc_max_rate = 50000000;
but it seems to have no effect. How can I limit the maximum bitrate? -
Unknown encoder 'libx264'
19 décembre 2023, par whyI installed ffmpeg 0.8.9 on ubuntu11 by
./configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libx264
When I run it
ffmpeg -y -i test.mp4 -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -vcodec libx264 -b 250k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 250k -maxrate 250k -bufsize 250k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 a.ts
It said
Unknown encoder 'libx264'
(Note: the same error could occour with
avconv
)How can I fix this? Thanks!
-
Encode NV12 frames to h264 using x264enc (appsrc and appsink)
9 octobre 2023, par Abdul RehmanI am trying to encode NV12 frames to h264 files. For that I found a following code that is encoding raw frames to jpeg using jpegenc. The code works fine with jpeg encoder after some minor changes for NV12 frames. However x264enc encode only first frame and the rest of them are outputting the pps error when running with mplayer.
First frame output
[h264 @ 0x7f1ea2ed3600]decoding for stream 0 failed [lavf] stream 0: video (h264), -vid 0 VIDEO: [H264] 1920x1080 0bpp 1.000 fps 0.0 kbps ( 0.0 kbyte/s) ========================================================================== Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family libavcodec version 58.54.100 (external) Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264) ========================================================================== Load subtitles in ./ Audio: no sound Starting playback... Movie-Aspect is 1.78:1 - prescaling to correct movie aspect. VO: [vdpau] 1920x1080 => 1920x1080 Planar YV12
Error frame output:
[h264 @ 0x7f9c2e44f4c0]non-existing PPS 0 referenced [h264 @ 0x7f9c2e44f4c0]non-existing PPS 0 referenced [h264 @ 0x7f9c2e44f4c0]decode_slice_header error [h264 @ 0x7f9c2eece600]decoding for stream 0 failed [h264 @ 0x7f9c2eece600]Could not find codec parameters for stream 0 (Video: h264, none): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options [lavf] stream 0: video (h264), -vid 0 VIDEO: [H264] 0x0 0bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s) ========================================================================== Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family libavcodec version 58.54.100 (external) Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
I have changed the pipeline, block size and added queue. Pipeline:
pipeline = gst_pipeline_new("mypipeline"); appsrc = gst_element_factory_make("appsrc", "mysource"); queue1 = gst_element_factory_make("queue", "myqueue1"); jpegenc = gst_element_factory_make("x264enc", "myenc"); //parser = gst_element_factory_make("h264parse", "parser"); appsink = gst_element_factory_make("appsink", "mysink"); ... g_object_set(G_OBJECT(appsrc), "format", GST_FORMAT_TIME, "is-live", TRUE, "do-timestamp", TRUE, NULL); g_object_set(G_OBJECT(jpegenc), "tune", 0x00000004, NULL); // 0x00000004 is the ultrafast preset ... capsappsrc2Jpegenc = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "NV12", "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, 1, 1, "interlace-mode", G_TYPE_STRING, "progressive", "colorimetry", G_TYPE_STRING, "bt601", NULL); // blocksize is important for jpegenc to know how many data to expect from appsrc in a single frame, too char szTemp[64]; sprintf(szTemp, "%d", 3110400); g_object_set(G_OBJECT (appsrc), "blocksize", szTemp, NULL);