Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to decode HEVC files to YUV ?

    3 septembre 2015, par NiRR

    I would like to decode HEVC encoded files to YUV files.

    Is there any simple way to do this yet? An executable would be nice but I would make do with source code that is easily compilable.

  • Streaming H.264 over UDP using FFmpeg, and "dimensions not set" error

    3 septembre 2015, par Baris Demiray

    I'm trying to stream H.264 over UDP with no luck so far. Here is a minimal code that you can reproduce the problem.

    To compile,

    g++ -o test -lavcodec -lavformat -lavutil test.cpp
    

    Extra information, I start ffplay as follows. Currently it's of no use.

    ffplay -i udp://127.0.0.1:8554/live.sdp
    

    Output of my code (see avio_open() call),

    [libx264 @ 0x6a26c0] using mv_range_thread = 24
    [libx264 @ 0x6a26c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
    [libx264 @ 0x6a26c0] profile High, level 3.1
    Output #0, h264, to 'udp://127.0.0.1:8554/live.sdp':
        Stream #0:0, 0, 0/0: Video: h264 (libx264), -1 reference frame, none, q=-1--1
    [h264 @ 0x6a2020] dimensions not set
    Cannot write header to stream: Success
    

    And the code,

    extern "C" {
        #include avcodec.h>
        #include avformat.h>
        #include avutil.h>
    }
    
    #include 
    using namespace std;
    
    int main() {
        AVCodecContext* m_codecContext;
        AVCodec* m_codec;
        AVFormatContext* m_formatContext;
        AVStream* m_stream;
    
        unsigned m_outWidth = 768;
        unsigned m_outHeight = 608;
    
        av_register_all();
        avcodec_register_all();
        avformat_network_init();
    
        int errorStatus = 0;
        char errorLog[128] = { 0 };
        av_log_set_level(AV_LOG_TRACE);
    
        string m_output("udp://127.0.0.1:8554/live.sdp");
    
        if (avformat_alloc_output_context2(&m_formatContext, NULL, "h264", m_output.c_str()) < 0) {
            cerr << "Cannot allocate output context: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        AVOutputFormat *m_outputFormat = m_formatContext->oformat;
    
        m_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
        if (!m_codec) {
            cerr << "Cannot find an encoder: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        m_codecContext = avcodec_alloc_context3(m_codec);
        if (!m_codecContext) {
            cerr << "Cannot allocate a codec context: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        m_codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
        m_codecContext->width = m_outWidth;
        m_codecContext->height = m_outHeight;
    
        if (avcodec_open2(m_codecContext, m_codec, NULL) < 0) {
            cerr << "Cannot open codec: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        m_stream = avformat_new_stream(m_formatContext, m_codec);
        if (!m_stream) {
            cerr << "Cannot create a new stream: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        av_dump_format(m_formatContext, 0, m_output.c_str(), 1);
    
        if ((errorStatus = avio_open(&m_formatContext->pb, m_output.c_str(), AVIO_FLAG_WRITE)) < 0) {
            cerr << "Cannot open output: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        if (avformat_write_header(m_formatContext, NULL) < 0) {
            cerr << "Cannot write header to stream: "
                 << av_make_error_string(errorLog, 128, errorStatus) << endl;
            return -1;
        }
    
        cout << "All done." << endl;
    
        return 0;
    }
    

    For those who has even more time to spare on my problem, when I change m_output to rtsp://127.0.0.1:8554/live.sdp, and ffplay command to ffplay -rtsp_flags listen -i rtsp://127.0.0.1:8554/live.sdp I get the error,

    [libx264 @ 0x1e056c0] using mv_range_thread = 24
    [libx264 @ 0x1e056c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
    [libx264 @ 0x1e056c0] profile High, level 3.1
    Output #0, h264, to 'rtsp://127.0.0.1:8554/live.sdp':
        Stream #0:0, 0, 0/0: Video: h264 (libx264), -1 reference frame, none, q=-1--1
    Cannot open output: Protocol not found
    

    Am I naive to expect that streaming protocol will be changed like this?

  • Writing to a custom output with FFmpeg AVIOContex

    3 septembre 2015, par Joe Allen

    So I have been reading about using AVIO struct to be able to load from a custom source. Here are the posts I have been reading:

    How can libavformat be used without using other libav libraries?

    Reading a file located in memory with libavformat

    But in each of these posts talk about loading data from a different source. What about if you want to write your converted data to a different source for instance? How would you go about it? Ideally, I want to avoid as much file I/O as possible.

  • Paperclip Video Skewed (does not maintain aspect ratio)

    3 septembre 2015, par zreitano

    The video uploaded does not maintain aspect ratio. In the readme (paperclip av-transcoder) it says, " '!' - Keep the same aspect of the image/video, but with the passed dimension." I have also tried the other options(<>#!) and none of them effect the size of the video.

    My goal is to be able to be able to have the video returned in a square (while maintaining the aspect ratio). Cropping from the center would be ideal, as well.

    Any help would be greatly appreciated. I included my code below.

    class Video < Post
    
      Paperclip.interpolates :id do |attachment, style|
        attachment.instance.id
      end
    
      #basename/extension is paperclip interpolation from attachment, can write own interpolations as needed
    
      # have to link /usr/local/bin to the linuxbrew version of ffmpeg
      has_attached_file :video,  path: "/posts/videos/:id/:style.:extension",
      :styles => {
        :square => {:geometry => "500x500!", :format => 'mp4', :streaming => true }
      },
      :processors => [:transcoder]
    
      validates_attachment :video, :presence => true,
                               :content_type => { content_type: ["video/mp4", "video/mov", "video/mpeg","video/mpeg4", "video/quicktime"] }
    
      def video_url
        video = self.video
        if video.present?
          return video.url(:square)
        end
      end
    
    end
    
  • H264 keyframe issue with RTP

    3 septembre 2015, par Mat DePasquale

    I'm building an RTP encoder for H264 video. The video data provider doesn't periodically stream the keyframe in the data, instead they have provided me with a binary file representation of the keyframe. This includes the SPS-PPS-SEI and then 8 slices of the i-frame.

    Since I am encoding RTP, I need to rebroadcast this keyframe at 2 second intervals. I am doing that in my code, along with the rest of the data as it comes in. I am using ffmpeg to connect to the RTP data via a UDP socket for display testing.

    I am noticing that every 2 seconds, the video seems to blank and resync itself, pixelate, etc. Obviously, this is highly undesirable in the video product. I've been trying to debug this for quite some time and the only thing I can determine is that it has to do with the keyframe. If I just send the keyframe once, and then the rest of the data, ffmpeg displays the video fine. But in a network environment, I need to send the keyframe at periodic intervals.

    Does anyone have an idea as to why this resyncing of the video happens and most importantly, how to stop it from happening?

    Thanks!