Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Opening Video with opencv3 and python on Amazon EC2

    11 octobre 2016, par stml

    I successfully set up python and opencv3 on an t2.micro instance by following these instructions: http://stackoverflow.com/a/38867965/1213715

    The script which worked on my local machine no longer works. The problem seems to be with importing video. The start of my code now looks like this:

    import numpy as np
    import cv2
    
    cap = cv2.VideoCapture('/home/ec2-user/test.mov')
    
    if(cap.isOpened() == False):
        print "Can't open video"
        exit()
    

    This exits every time. I have tried different paths and different video formats (including .avi).

    In other threads, I read that ffmpeg is essential to cv2 video functions, and successfully installed this using the instructions at https://forums.aws.amazon.com/thread.jspa?messageID=524523. I can now run ffmpeg from the command line - but it has not changed the cv2 output.

    Do I need to link ffmpeg to cv2 somehow, or do I need to recompile entirely - and if so, what change should I make to the original installation instructions?

    Python version 2.7.12

    Opencv version 3.1.0

  • How to combine 2 videos using either NReco ffmpeg ConvertMedia or just ffmpeg command line ?

    11 octobre 2016, par M. Ilchuk

    We have 2 videos: video1.webm and video2.webm. How to combine these two and get output.mp4 which contains video from video1.webm and audio from video1 and video2?

    Example:

    video1(audio1 in video1) + video2(audio2 in video2) = outputVideo(video1 + audio1 +audio2)

    image example

    ffmpeg -i 1.webm -i 2.webm ffmpeg version N-81872-gbe1d324 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 5.4.0 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib libavutil 55. 32.100 / 55. 32.100 libavcodec 57. 60.101 / 57. 60.101 libavformat 57. 51.102 / 57. 51.102 libavdevice 57. 0.102 / 57. 0.102 libavfilter 6. 63.100 / 6. 63.100 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 2.100 / 2. 2.100 libpostproc 54. 0.100 / 54. 0.100 Input #0, matroska,webm, from '1.webm': Metadata: encoder : libwebm-0.2.1.0 creation_time : 2016-10-05T07:54:05.064000Z Duration: 00:00:30.11, start: 0.000000, bitrate: 798 kb/s Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default) Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 8.33 tbr, 1k tbn, 1k tbc (default) Input #1, matroska,webm, from '2.webm': Metadata: encoder : libwebm-0.2.1.0 creation_time : 2016-10-05T07:54:20.135000Z Duration: 00:00:30.20, start: 0.000000, bitrate: 523 kb/s Stream #1:0(eng): Audio: opus, 48000 Hz, mono, fltp (default) Stream #1:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 1k tbr, 1k tbn, 1k tbc (default) At least one output file must be specified.

    No sound from video 2, video 1 but it is very bad. The process of converting long.

    >ffmpeg -i 1.webm -i 2.webm -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -ac 2 -shortest output.webm
    ffmpeg version N-81872-gbe1d324 Copyright (c) 2000-2016 the FFmpeg developers
      built with gcc 5.4.0 (GCC)
      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
      libavutil      55. 32.100 / 55. 32.100
      libavcodec     57. 60.101 / 57. 60.101
      libavformat    57. 51.102 / 57. 51.102
      libavdevice    57.  0.102 / 57.  0.102
      libavfilter     6. 63.100 /  6. 63.100
      libswscale      4.  1.100 /  4.  1.100
      libswresample   2.  2.100 /  2.  2.100
      libpostproc    54.  0.100 / 54.  0.100
    Input #0, matroska,webm, from '1.webm':
      Metadata:
        encoder         : libwebm-0.2.1.0
        creation_time   : 2016-10-05T07:54:05.064000Z
      Duration: 00:00:30.11, start: 0.000000, bitrate: 798 kb/s
        Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
        Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 8.33 tbr, 1k tbn, 1k tbc (default)
    Input #1, matroska,webm, from '2.webm':
      Metadata:
        encoder         : libwebm-0.2.1.0
        creation_time   : 2016-10-05T07:54:20.135000Z
      Duration: 00:00:30.20, start: 0.000000, bitrate: 523 kb/s
        Stream #1:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
        Stream #1:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 1k tbr, 1k tbn, 1k tbc (default)
    [Parsed_amerge_0 @ 00000000026d4400] No channel layout for input 1
    [Parsed_amerge_0 @ 00000000026d4400] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
    [libvpx-vp9 @ 0000000002592280] v1.6.0
    [libopus @ 00000000024d81e0] No bit rate set. Defaulting to 96000 bps.
    Output #0, webm, to 'output.webm':
      Metadata:
        encoder         : Lavf57.51.102
        Stream #0:0(eng): Video: vp9 (libvpx-vp9), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 200 kb/s, 8.33 fps, 1k tbn, 8.33 tbc (default)
        Metadata:
          encoder         : Lavc57.60.101 libvpx-vp9
        Side data:
          cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
        Stream #0:1: Audio: opus (libopus), 48000 Hz, stereo, flt, 96 kb/s (default)
        Metadata:
          encoder         : Lavc57.60.101 libopus
    Stream mapping:
      Stream #0:0 (opus) -> amerge:in0 (graph 0)
      Stream #1:0 (opus) -> amerge:in1 (graph 0)
      Stream #0:1 -> #0:0 (vp8 (native) -> vp9 (libvpx-vp9))
      amerge (graph 0) -> Stream #0:1 (libopus)
    Press [q] to stop, [?] for help
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate=  91.8kbits/s speed=2.33x
        Last message repeated 4 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 100.0kbits/s speed=1.62x
        Last message repeated 23 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 133.1kbits/s speed=1.27x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 160.5kbits/s speed=1.06x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 164.1kbits/s speed=0.932x
        Last message repeated 23 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 185.8kbits/s speed=0.819x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 212.5kbits/s speed=0.72x
        Last message repeated 4 times
    Error while decoding stream #0:0: Cannot allocate memory28 bitrate= 242.0kbits/s speed=0.68x
        Last message repeated 18 times
    Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 190.1kbits/s speed= 0.9x
        Last message repeated 13 times
    Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 205.9kbits/s speed=0.849x
        Last message repeated 21 times
    Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 209.5kbits/s speed=0.781x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 225.2kbits/s speed=0.741x
        Last message repeated 16 times
    Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 240.9kbits/s speed=0.695x
        Last message repeated 18 times
    Error while decoding stream #0:0: Cannot allocate memory68 bitrate= 239.9kbits/s speed=0.665x
    Error while decoding stream #0:0: Cannot allocate memory76 bitrate= 251.1kbits/s speed=0.659x
        Last message repeated 10 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 211.2kbits/s speed=0.791x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 212.8kbits/s speed=0.751x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 224.7kbits/s speed=0.724x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 225.4kbits/s speed=0.701x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 235.8kbits/s speed=0.678x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 244.0kbits/s speed=0.654x
        Last message repeated 12 times
    Error while decoding stream #0:0: Cannot allocate memory16 bitrate= 242.8kbits/s speed=0.645x
        Last message repeated 1 times
    Error while decoding stream #0:0: Cannot allocate memory00 bitrate= 242.9kbits/s speed=0.638x
    Error while decoding stream #0:0: Cannot allocate memory36 bitrate= 246.9kbits/s speed=0.639x
        Last message repeated 8 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 218.2kbits/s speed=0.727x
        Last message repeated 16 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 219.9kbits/s speed=0.707x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 227.5kbits/s speed=0.69x
        Last message repeated 18 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 229.6kbits/s speed=0.673x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 237.3kbits/s speed=0.657x
        Last message repeated 16 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 238.8kbits/s speed=0.642x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 245.4kbits/s speed=0.627x
        Last message repeated 9 times
    Error while decoding stream #0:0: Cannot allocate memory76 bitrate= 242.9kbits/s speed=0.625x
        Last message repeated 1 times
    Error while decoding stream #0:0: Cannot allocate memory60 bitrate= 246.0kbits/s speed=0.618x
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 229.5kbits/s speed=0.697x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 235.1kbits/s speed=0.679x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 236.4kbits/s speed=0.664x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 241.4kbits/s speed=0.652x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 242.8kbits/s speed=0.639x
        Last message repeated 11 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 247.9kbits/s speed=0.627x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 249.4kbits/s speed=0.616x
        Last message repeated 8 times
    Error while decoding stream #0:0: Cannot allocate memory24 bitrate= 252.4kbits/s speed=0.611x
        Last message repeated 4 times
    Error while decoding stream #0:0: Cannot allocate memory96 bitrate= 253.9kbits/s speed=0.612x
    Error while decoding stream #0:0: Cannot allocate memory32 bitrate= 252.1kbits/s speed=0.611x
        Last message repeated 15 times
    Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 233.6kbits/s speed=0.663x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 239.7kbits/s speed=0.652x
        Last message repeated 17 times
    Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 245.3kbits/s speed=0.641x
        Last message repeated 23 times
    Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 246.6kbits/s speed=0.629x
        Last message repeated 25 times
    Error while decoding stream #0:0: Cannot allocate memory60 bitrate= 251.4kbits/s speed=0.621x
        Last message repeated 8 times
    Error while decoding stream #0:0: Cannot allocate memory80 bitrate= 254.7kbits/s speed=0.629x
        Last message repeated 18 times
    Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 239.0kbits/s speed=0.676x
        Last message repeated 29 times
    Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 243.4kbits/s speed=0.663x
        Last message repeated 21 times
    Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 247.8kbits/s speed=0.655x
        Last message repeated 13 times
    Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 252.1kbits/s speed=0.644x
        Last message repeated 15 times
    Error while decoding stream #0:0: Cannot allocate memory17 bitrate= 251.6kbits/s speed=0.642x
        Last message repeated 4 times
    Error while decoding stream #0:0: Cannot allocate memory44 bitrate= 253.6kbits/s speed=0.64x
        Last message repeated 4 times
    Error while decoding stream #0:0: Cannot allocate memory40 bitrate= 254.2kbits/s speed=0.644x
        Last message repeated 5 times
    frame=  249 fps=5.4 q=0.0 Lsize=     946kB time=00:00:30.12 bitrate= 257.2kbits/s speed=0.654x
    video:806kB audio:133kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.632650%
    
  • Convert FLV to MP4 using ffmpeg php

    11 octobre 2016, par Kiran

    I have video with FLV format i want to covert that videos in to the MP4 format to using it in HTML5 video tag. Can anybody know the command to convert FLV to MP4.

    Thanks

  • FFmpeg - How to trim with high precision ?

    11 octobre 2016, par DSalenga

    I am pretty stucked with the way that FFmpeg trims videos, so I would be really grateful if someone could help me. Basically, what I am trying to do is: I have a video sequence and I want it to stop in a certain second, freeze the image some seconds (like a pause), and then reproduce again from the same exact frame. I could say that I am dealing with three videos: A.mp4 (first part of the video sequence), B.mp4 (frozen image) and C.mp4 (second part of the video sequence). Besides, I also perform an overlay with filter_complex.

    The part of generating a video from a static image is not a problem, my main concern is to find the way to trim and concatenate videos accurately. From other posts and sources, I discovered that FFmpeg trims from those Frames that are Keyframes, which can be forced. However, the result I obtain is not the appropriate one, because my video A ends in a frame different from the one in the beginning of C.

    The commands I am using are the following ones:

    ffmpeg -y -i VideoSequence.mp4 -c:v libx264 -pix_fmt yuv420p \
    -force_key_frames "expr: gte(t,n_forced * 15)" -t 30 VideoOut.mp4
    

    [Note that everything inside Filter Complex is about an Overlay, which works fine]

    As far as I know, the resulting video should have a Keyframe every 15 seconds. Now, I want to cut the video into 2 parts ("before second 15" and "after second 15"):

    ffmpeg -y -ss 00:00:01 -i VideoOut.mp4 -t 14 -c copy A.mp4
    
    ffmpeg -y -ss 00:00:15 -i VideoOut.mp4 -t 5 -c copy C.mp4 
    

    As mentioned, I expect the end of A.mp4 to "match" with the beginning of C.mp4 (at a frame precision), but the result I obtain is far from being perfect.

    Thank you very much, any kind of help will be appreciated!

  • can write frames to rtsp server, but can't display them in the ffplay or live555 client

    11 octobre 2016, par tankyx

    I am working on a zero latency streaming server, using ffmpeg libraries and I am facing a problem. My server is working when using nvenc, I can streaming successfully to my client, which is another computer on LAN. But if I change my encoder to use the libx264 (in order to reduce the latency), the server still write the frames, but the client is facing problems with the sdp header, and more specifically, the media subsession does not seem to be initialized. Therefore, the client crashes.

    The thing is, when I dump the sdp header when using nvenc and libx264, it is actually the same in both case.

    Here is the code I have done to initialize my encoder :

    /*
        Init the codec that is used to encode the video.
        Init the output format context (aka RTSP uri).
    */
    FfmpegEncoder::FfmpegEncoder(char *url)
    {
        AVRational      tmp_time_base;
        AVDictionary*   options = NULL;
    
        this->pCodec = avcodec_find_encoder_by_name("libx264");
        if (this->pCodec == NULL)
            throw myExceptions("Error: Can't initialize the encoder. FfmpegEncoder.cpp l:9\n");
    
        this->pCodecCtx = avcodec_alloc_context3(this->pCodec);
    
        //Alloc output context
        if (avformat_alloc_output_context2(&outFormatCtx, NULL, "rtsp", url) < 0)
            throw myExceptions("Error: Can't alloc stream output. FfmpegEncoder.cpp l:17\n");
    
        this->st = avformat_new_stream(this->outFormatCtx, this->pCodec);
        this->st->id = this->outFormatCtx->nb_streams - 1;
    
        if (this->st == NULL)
            throw myExceptions("Error: Can't create stream . FfmpegEncoder.cpp l:22\n");
    
        //Define the framerate of the output. The numerator should stay 1. Denumerator is the framerate we are aiming for.
    
        tmp_time_base.num = 1;
        tmp_time_base.den = 60;
    
        //TODO : parse these values
        this->pCodecCtx->bit_rate = 5000000;
        this->pCodecCtx->width = 1280;
        this->pCodecCtx->height = 720;
        //This set the fps. 60fps at this point.
        this->pCodecCtx->time_base = tmp_time_base;
        this->st->time_base = tmp_time_base;
        //Add a intra frame every 12 frames
        this->pCodecCtx->gop_size = 10;
        this->pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
    
        av_opt_set(this->pCodecCtx, "tune", "zerolatency", 0);
        av_opt_set(this->pCodecCtx, "vprofile", "main", 0);
        av_opt_set(this->pCodecCtx, "preset", "faster", 0);
    
        //Open Codec, using the context + x264 options
        if (avcodec_open2(this->pCodecCtx, this->pCodec, &options) < 0)
            throw myExceptions("Error: Can't open the codec. FfmpegEncoder.cpp l:43\n");
    
        if (avcodec_copy_context(this->st->codec, this->pCodecCtx) != 0) {
            throw myExceptions("Error : Can't copy codec context. FfmpegEncoder.cpp : l.46");
        }
        av_dump_format(this->outFormatCtx, 0, url, 1);
    
        //write the header needed to start the stream.
        if (avformat_write_header(this->outFormatCtx, NULL) != 0)
            throw myExceptions("Error: failed to connect to RTSP server. FfmpegEncoder.cpp l:48\n");
    }