Newest 'libx264' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/libx264

Les articles publiés sur le site

  • Dynamically change video parameters in FFmpeg ?

    18 octobre 2017, par Guppy_00

    Would it be possible to change video parameters such as bitrate or framerate while transcoding in ffmpeg?

    I've read a lot about this topic. Some suggests reinitializing the codec context but when I close the codec context then re-open it after changing video parameter values, I get a bunch of errors from libx264 "using CPU capabilities: MMX SSE2Fast SSESE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2" keeps printing non-stop!

    Also, changing the bitrate via AVCodecContext->bit_rate is no use as the change is not being reflected on ffmpeg stats. Would there be an easy way of doing this by simply changing a parameter? Thanks

  • ffmpeg to dvb-c. Need some advices

    12 octobre 2017, par pentarhh

    I'd like to get some advices about ffmpeg transcoding and broadcasting it to DVB-C environment. Have a server, based on Linux with external GPUs based on Nvidia P4000. Target of this machine is getting live streams at HLS, then it transcode files to multicast UDP. After transcoding multicast TS gets to receiver (Sumavision EMR 3.0), then modulates into DVB-C with QAM-card for next transmission to fiber.

    So, there is a strange trouble. In IPTV such stream have no visible troubles. Analyzing TS, saw an errors with PCR accuracy (>500 ms 'cause of pseudo-CBR) and very rare discontinuity errors, that could be based on source errors. Then I take it to Sumavision and apply inbound parameters (just remultiplexing this stream with making loyal reference, buffer size values and CBR output values). Analyzer sees no problem, after putting in QAM-modulator customize output streams, such as PSI/SI tables, frequency, symbol rate etc.

    After I see the result at some test TVs. First one shows this channel great, with no visible troubles (no artefacts, no asynchronous sound). Second TV has a problem of video, it looks like a lost frames. Sometimes sound interrupts for a milliseconds. But there is no freezes 'Cause of ETR 101 290 passes well, may be this model of TV decodes this service incorrect. Example of video record is here.

    Here is the code of ffmpeg. May be, I missed some common parameters, that may get the output is better for such tuners. Can you see it's alright?

    sudo -u nobody ffmpeg -threads 0 -v warning -re -hwaccel cuvid -hwaccel_device 2 -c:v h264_cuvid -deint 0 -i http://x.x.x.x/playlist.m3u8 -bsf:v h264_mp4toannexb -map 0:0 -map 0:1 -vcodec h264_nvenc -gpu 2 -cbr true -sc_threshold 0 -filter:v scale_npp=960:540:interp_algo=lanczos -vprofile baseline -b:v 1000k -bufsize 1400k -maxrate 1400k -minrate 900k -force_key_frames 1 -g 50 -bf 0 -refs 1 -r 25 -strict experimental -c:a aac -b:a 64K -af aresample=44100 -ac 2 -flags -global_header -f segment -segment_format mpegts -segment_time 10 /path1/segment-1507744758-%06d.ts -map 0:0 -map 0:1 -vcodec h264_nvenc -gpu 2 -cbr true -sc_threshold 0 -vprofile high -b:v 8000k -bufsize 400k -maxrate 9000k -minrate 7200k -force_key_frames 1 -g 50 -bf 2 -refs 1 -r 25 -strict experimental -c:a aac -b:a 192K -af aresample=44100 -ac 2 -flags -global_header -f tee 
    [f=segment:segment_format=mpegts:segment_time=10]/path2/segment-1507744758-%06d.ts|[f=mpegts:muxrate=9333k:mpegts_pmt_start_pid=0xB4A:mpegts_start_pid=0xB4B]'udp://y.y.y.y:1234?buffer_size=0&overrun_nonfatal_option=1&pkt_size=1316&ttl=15'
    
  • libx264 encoded video lags by few seconds in comparison to audio

    18 septembre 2017, par Herdesh Verma

    Below is the code i am using for reading a .3gp file encoding it using libx264 and writing it to .mp4 container. Code is working but when i play .mp4 file then video is not in sync with audio. Video is few second slow in comparison to audio.

    // Read all packet from context
    while( av_read_frame( fmt_ctx , pAVPacket ) >= 0 )
    {
        int decoded = pAVPacket->size;
        if(pAVPacket->stream_index == video_stream_idx)
        {
            //decode packet
            value = avcodec_decode_video2(video_dec_ctx , pAVFrame , 
            &frameFinished , pAVPacket );
            if( value < 0)
            {
                av_free_packet(pAVPacket);
                return -1;
            }
    
            if(frameFinished)// Frame successfully decoded :)
            {
                sws_scale(swsCtx_, (const uint8_t *const *) pAVFrame->data, 
                pAVFrame->linesize, 0, video_dec_ctx->height, outFrame->data, 
                outFrame->linesize);
                av_init_packet(&outPacket);
                outPacket.data = NULL;    // packet data will be allocated by 
                the encoder
                outPacket.size = 0;
    
                outFrame->pts=z;
                //encode frame
                avcodec_encode_video2(outAVCodecContext , &outPacket ,outFrame , 
                &got_picture);
    
    
                if(got_picture)
                {
                    if(outPacket.pts != AV_NOPTS_VALUE)
                        outPacket.pts = av_rescale_q(outPacket.pts, video_st-
                        >codec->time_base, video_st->time_base);
                    if(outPacket.dts != AV_NOPTS_VALUE)
                        outPacket.dts = av_rescale_q(outPacket.dts, video_st-
                        >codec->time_base, video_st->time_base);
    
                    //Write encoded packet to file.
                    if(av_write_frame(outAVFormatContext , &outPacket) != 0)
                    {
                        av_free_packet(pAVPacket);
                        av_free_packet(&outPacket);
                        return -1;
                    }
                    z++;
                    av_free_packet(&outPacket);
                } // got_picture
            } // got_picture
        }
        // If packet is from audio stream
        else if (pAVPacket->stream_index == audio_stream_idx)
        {
           //Write to file without decoding and encoding it
           if(av_write_frame(outAVFormatContext , pAVPacket) != 0)
            {
            }
        }
        av_free_packet(pAVPacket);
        //z++;
    }// End of while-loop
    
    value = av_write_trailer(outAVFormatContext);
    if( value < 0)
    {
        return -1;
    }
    

    I am using below settings:

            outAVCodecContext->codec_id = AV_CODEC_ID_H264;// AV_CODEC_ID_MPEG4; // AV_CODEC_ID_H264 // AV_CODEC_ID_MPEG1VIDEO
        outAVCodecContext->bit_rate_tolerance = BIT_RATE_TOLERANT;
        outAVCodecContext->rc_max_rate = RC_MAX_RATE;
        outAVCodecContext->rc_buffer_size = RC_BUFFER_SIZE;
        outAVCodecContext->gop_size = GOP_SIZE;
        outAVCodecContext->b_frame_strategy = B_FRAME_STRATEGY;
        outAVCodecContext->coder_type = CODER_TYPE;
        outAVCodecContext->me_cmp = ME_CMP;
        outAVCodecContext->me_range = ME_RANGE; //16
        outAVCodecContext->qmin = QMIN;  //10
        outAVCodecContext->qmax = QMAX;  //51
        outAVCodecContext->scenechange_threshold = SCENECHANGE_THRESHOLD; //40
        outAVCodecContext->flags |= CODEC_FLAG_LOOP_FILTER;
        outAVCodecContext->me_method = ME_METHOD;
        outAVCodecContext->me_subpel_quality = ME_SUBPEL_QUALITY;
        outAVCodecContext->i_quant_factor = I_QUANT_FACTOR; //0.71
        outAVCodecContext->qcompress = QCOMPRESS;
        outAVCodecContext->max_qdiff = MAX_QDIFF;
        av_dict_set( &codec_options, "preset", "superfast", 0 );
    

    And values are defined as below:

    #define VAVLON_VALUES_H
    #define BIT_RATE_TOLERANT 0;
    #define RC_MAX_RATE 0;
    #define RC_BUFFER_SIZE 0;
    #define GOP_SIZE 40;
    #define B_FRAME_STRATEGY 0;
    #define CODER_TYPE 1;
    #define ME_CMP 1;
    #define ME_RANGE 16; //16
    #define QMIN 30;  //37
    #define QMAX 40;  //70
    #define SCENECHANGE_THRESHOLD 40; //40
    #define ME_METHOD ME_HEX;
    #define ME_SUBPEL_QUALITY 40;
    #define I_QUANT_FACTOR 0.71;
    #define QCOMPRESS 0.3;
    #define MAX_QDIFF 4;
    #define BIT_RATE 500000;
    #define CODEC_TYPE AVMEDIA_TYPE_VIDEO;
    #define PIX_FMT AV_PIX_FMT_YUV420P;
    #define MAX_B_FRAMES 0;
    #define NUM 1;
    #define DEN 30;
    

    Above code works as expected when i am encoding .mp4 file but i notice lag in video when i try to encode .3gp file. Can you please help in finding out what i am doing wrong?

  • Encoding frames to video with ffmpeg h264 codec

    14 septembre 2017, par Mher Didaryan

    I am trying to encode a video in Unreal Engine 4 with C++. With this Encoding frames to video with ffmpeg answer everything works fine if mpeg encoder is being used. However when I try to use libx256 or h264_nvenc avcodec_open2 returns negative value indicating error.

    I followed this FFmpeg CompilationGuide

    Below is configure parameters.

    ./configure --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --enable-libx264 --enable-gpl --enable-shared

    Paths were set correctly and there were no errors or warnings on configure, make and make install. I copied all dlls to Unreal project binary folder.

    With ./configure --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --enable-libx264 --enable-gpl without --enable-shared option I get an ffmpeg.exe which has libx264 and h264_nvenc in it's codecs.

    $ ./ffmpeg.exe -codecs | grep h264
    ffmpeg version N-87130-g2b9fd15 Copyright (c) 2000-2017 the FFmpeg developers
      built with gcc 6.2.0 (Rev2, Built by MSYS2 project)
      configuration: --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --enable-libx264 --enable-gpl --enable-shared
      libavutil      55. 74.100 / 55. 74.100
      libavcodec     57.104.100 / 57.104.100
      libavformat    57. 79.100 / 57. 79.100
      libavdevice    57.  8.100 / 57.  8.100
      libavfilter     6.101.100 /  6.101.100
      libswscale      4.  7.103 /  4.  7.103
      libswresample   2.  8.100 /  2.  8.100
      libpostproc    54.  6.100 / 54.  6.100
     DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc nvenc nvenc_h264 )
    

    Is there something I missed? How to integrate h264 enabled build of ffmpeg in a C++ project?

  • installing x264 0.120 for redhat el7

    16 août 2017, par Mohammad Alkhaldi

    im trying to install x264 for redhat el7

    i cloned it from github then compiled it and installed

    this is the clone link:http://git.videolan.org/git/x264.git

    when i run x264 --version it gives me this output

    x264 0.148.x built on Aug 16 2017, gcc: 4.8.5 20150623 (Red Hat 4.8.5-11) x264 configuration: --bit-depth=8 --chroma-format=all libx264 configuration: --bit-depth=8 --chroma-format=all x264 license: GPL version 2 or later

    i need x264 0.120 for installing x264-plugins-ugly

    Thank you in advance.