Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • libmp3lame ignore ffmpeg options, and can not change audio bitrate

    27 août 2018, par Ahmed

    i have java application to encode audio and send it via socket to server, i use ffmpeg to get compressed avpacket then send this packet via socket , the problem is the bandwidth is large than what is want, and can not control it, i try to set bitrate option to encoder (libmp3lame) but it's ignore it completely, and i don not know is the problem from code or because i did not use ffmpeg libformat to send the packet to socket ?

    this how i open a codec

           codec = avcodec_find_encoder_by_name("libmp3lame");
            //codec = avcodec_find_encoder(AV_CODEC_ID_MP3);
    
            if(codec == null)
                throw new Exception("Codec not found");
    
            context = avcodec_alloc_context3(codec);
    
            if(context == null)
                throw new Exception("Could not allocate audio codec context");
    
            context.codec_tag(0);
            context.codec_id(AV_CODEC_ID_MP3);
            context.codec_type(AVMEDIA_TYPE_AUDIO);
    
            // set sample parameter
            context.bit_rate(audio_bitrate);
            context.sample_rate(samples_rate);
            context.channels(samples_channels);
            context.channel_layout(av_get_default_channel_layout(samples_channels));
            context.time_base().num(1).den(samples_rate);
    
            context.sample_fmt(AV_SAMPLE_FMT_S16);
            context.bits_per_raw_sample(16);        
    
            context.flags(context.flags() | AV_CODEC_FLAG_QSCALE);
            context.global_quality((int)Math.round(FF_QP2LAMBDA * audioQuality));
    
            if ((codec.capabilities() & AV_CODEC_CAP_EXPERIMENTAL) != 0) {
                context.strict_std_compliance(AVCodecContext.FF_COMPLIANCE_EXPERIMENTAL);
            }
    
            // priv_data()
            av_opt_set(context.priv_data() , "crf" , audioQuality + "" , 0);
            av_opt_set(context.priv_data() , "b" , "85" , 0);
            //av_opt_set(context.priv_data() , "V" , "2" , 0);
            //av_opt_set(context.priv_data() , "lowpass" , "120" , 0);
            av_opt_set(context.priv_data() , "abr" , "1" , 0);
    
            AVDictionary options = new AVDictionary(null);
            //av_dict_set(options, "crf", ""+audioQuality , 0);
            av_dict_set(options, "b:a", "8k" , 0);
            av_dict_set(options , "q:a" , "8" , 0);
            //av_dict_set(options , "lowpass" , "19.5" , 0);
            //av_dict_set(options, "b" , "8K" , 0);
    
    
            // open codec
            if (avcodec_open2(context, codec, (PointerPointer)null ) < 0) 
                throw new Exception("Could not open codec");
    ....
    
  • How to seek to a specific frame in a h.264 video ?

    27 août 2018, par Freeny

    I need to decode a video from specific frame by FFmpeg, I know h.264 video has I-frame/P-frame/B-frame, when I use av_seek_frame() to seek to a specific frame, it could only help me to find the nearest previous I-frame, so I tried to use the AVPacket.dts and a while loop to navigate to the location of the specific frame, and then start to demux the video frame.

    auto DurationTime = static_cast(m_pAVFormatContext->streams[m_VideoStreamIndex]->duration);
    auto FrameNum = m_pAVFormatContext->streams[m_VideoStreamIndex]->nb_frames;
    av_seek_frame(m_pAVFormatContext, m_VideoStreamIndex, DurationTime / FrameNum * (vSpecificFrame), AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD);
    int TempValue = 0;
    while ((TempValue = av_read_frame(m_pAVFormatContext, &m_AVPacket)) >= 0 && m_AVPacket.stream_index != m_VideoStreamIndex)
    {
        av_packet_unref(&m_AVPacket);
    }
    while(m_AVPacket.dts / (DurationTime / FrameNum) < vSpecificFrame)
    {
        if(m_AVPacket.data)
            av_packet_unref(&m_AVPacket);
        while ((TempValue = av_read_frame(m_pAVFormatContext, &m_AVPacket)) >= 0 && m_AVPacket.stream_index != m_VideoStreamIndex)
        {
            av_packet_unref(&m_AVPacket);
        }
    }
    if(m_AVPacket.data)
        av_packet_unref(&m_AVPacket);
    

    But the question is when I demux the next frame, I can get it's pos, data, size and all other information, but the image is unable to display. Before demuxing the next I-frame, all frames between this specific frame with the next I-frame has the same case. Did I use the wrong method? Or whether there has any other method to seek to the specific frame of a video? Thanks very much.

  • Streaming low latency video

    26 août 2018, par user4893295

    Goal is to get low latency HD video over the LAN from a USB camera on a ARM device (a10 Lime running Armbian Jessie) to OBS Studio.

    Thinking first step is to at least get it viewable on VLC on another device. So, to that end, I have tried gstreamer (no joy), ffmpeg (same) and VLC. Best luck with VLC so far, but the picture is mostly blank with occasional spots of picture.

    This is the command I'm using:

    cvlc v4l2:///dev/video0:chroma=h264:width=1920:height=1080 --sout '#standard{access=http,mux=ts,dst=0.0.0.0:8080/stream,name=stream,mime=video/ts}' -vvv
    

    It moans a bit at first with

    [00b4a178] core interface error: no suitable interface module
    [00ab18f8] core libvlc error: interface "globalhotkeys,none" initialization failed
    [00b4a178] core interface debug: looking for interface module matching "dbus,none": 18 candidates
    [00b4a178] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
    [00b4a178] core interface debug: no interface modules matched
    [00b4a178] core interface error: no suitable interface module
    [00ab18f8] core libvlc error: interface "dbus,none" initialization failed
    

    But then seems to get a bit happier

    [b4316038] core demux meta debug: no meta reader modules matched
    [b4300508] core input debug: `v4l2:///dev/video0:chroma=h264:width=1920:height=1080' successfully opened
    [b4300508] core input debug: Buffering 0%
    [b4300508] core input debug: switching to sync mode
    [b430cce8] packetizer_h264 decoder debug: found NAL_SPS (sps_id=0)
    [b430cce8] packetizer_h264 decoder debug: found NAL_PPS (pps_id=0 sps_id=0)
    [b4300508] core input debug: Buffering 10%
    [b43041a0] core stream output debug: adding a new sout input (sout_input:0xb49004f0)
    [b43060f8] core mux debug: adding a new input
    [b43060f8] mux_ts mux debug: adding input codec=h264 pid=68
    [b43060f8] mux_ts mux debug: new PCR PID is 68
    [b4300508] core input debug: Buffering 32%
    [b4300508] core input debug: Buffering 44%
    [b4300508] core input debug: Buffering 55%
    [b4300508] core input debug: Buffering 65%
    [b4300508] core input debug: Buffering 77%
    [b4300508] core input debug: Buffering 88%
    [b4300508] core input debug: Buffering 98%
    [b4300508] core input debug: Stream buffering done (332 ms in 331 ms)
    [b4300508] core input debug: Decoder wait done in 0 ms
    

    And I can connect to it from VLC, but the picture looks like

    enter image description here

    Processor peaks at around 17% and memory even less than that, so it's not that.

    Any suggestions?

  • ffmpeg - how can I capture the timestamp of a screenshot using a seek and finding the nearest iframe ?

    26 août 2018, par Charles Kirk

    I've tried various different methods. ffprobe has always shown sensical results, with the pts_time increasing as the frames go on, using this command:

    ffprobe -show_frames video.mp4 > probestats.txt
    

    I thought about using that data to find the video frame nearest to the seconds I'm seeking to in ffmpeg, but I am trying to keep this performant, as I'm generating thumbnails on uploads that could exceed 5GB, which means I would end up with 50MB+ probe files to parse.

    So, currently, I'm looping over this ffmpeg command, so as to end up with 10 thumbnails total per file, regardless of length:

    ffmpeg -i video.mp4 -ss 00:00:05 -vf select="eq(pict_type\\,I)[s1];[s1]showinfo[out]" -vframes 1 -q:v 1 thumbs/thumb-1.jpg 2>&1
    

    The aim is to get the nearest iframe of the seconds I'm seeking to, e.g. find the nearest iframe near the 5 second mark and take a thumbnail -- which gives some increased performance.

    The issue is, ffmpeg is outputting seemingly random pts_time's, definitely not correct compared to the pkt_pts_time shown in ffprobe.

    So as the title states, I'm looking for an ffmpeg command to generate a thumbnail at the nearest iframe to a specified seek, and get the timestamp.

  • How to setup ffmpeg + nginx + rtmp

    26 août 2018, par MakarkinPRO

    Please help me setup nginx + rtmp. The right 1 and 2 is working - its not need to modify. And 3rd cannot undesrtand how to realize.

    https://pp.userapi.com/c844723/v844723097/cf34a/YiRr6rDnbAo.jpg

    WHere the red arrow I need help

    https://pp.userapi.com/c844723/v844723097/cf366/jaw7eSDZarw.jpg

    I'm not strong with the nginx, ffmpeg, rtmp config. Need some help.

    I think it's should be something -rotate 90 and resize 720*1280 (actually thats straming go to instagram).