Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • After scaled video, it convert transparent background to white

    8 mars 2017, par Sohaib Raza

    I scaled video using ffmpeg. When i scaled video, the output video having white background ,while the input video having transparent background. below command using for scaled video.

    ffmpeg -i inputVideo.mp4 -vf scale=100:100 outputVideo.mp4

    you can see the image below that is take from my video,for more understanding my problem.

    image from input video enter image description here

    you can see the above image from input video having no white background.

    image from output video enter image description here

    you can see the above image from output video having white backgournd.

    please give me your valuable answer regarding this question. any answer will be very appreciate.D: onProgress: configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= D: onProgress: libavutil 55. 17.103 / 55. 17.103 D: onProgress: libavcodec 57. 24.102 / 57. 24.102 D: onProgress: libavformat 57. 25.100 / 57. 25.100 D: onProgress: libavdevice 57. 0.101 / 57. 0.101 D: onProgress: libavfilter 6. 31.100 / 6. 31.100 D: onProgress: libswscale 4. 0.100 / 4. 0.100 D: onProgress: libswresample 2. 0.101 / 2. 0.101 D: onProgress: libpostproc 54. 0.100 / 54. 0.100 D: onProgress: Input #0, gif, from '/storage/emulated/0/Pictures/eye.gif': D: onProgress: Duration: N/A, bitrate: N/A D: onProgress: Stream #0:0: Video: gif, bgra, 480x190, 5 fps, 10 tbr, 100 tbn, 100 tbc D: onProgress: Output #0, gif, to '/storage/emulated/0/GIF/REV20170308_101145.gif': D: onProgress: Metadata: D: onProgress: encoder : Lavf57.25.100 D: onProgress: Stream #0:0: Video: gif, bgr8, 125x56, q=2-31, 200 kb/s, 10 fps, 100 tbn, 10 tbc D: onProgress: Metadata: D: onProgress: encoder : Lavc57.24.102 gif D: onProgress: Stream mapping: D: onProgress: Stream #0:0 -> #0:0 (gif (native) -> gif (native)) D: onProgress: Press [q] to stop, [?] for help D: onProgress: frame= 11 fps=0.0 q=-0.0 Lsize= 17kB time=00:00:02.90 bitrate= 48.8kbits/s speed=14.8x
    D: onProgress: video:16kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.287261% D: Started command : ffmpeg [Ljava.lang.String;@422f62d0 D: onSuccess: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Input #0, gif, from '/storage/emulated/0/Pictures/eye.gif': Duration: N/A, bitrate: N/A Stream #0:0: Video: gif, bgra, 480x190, 5 fps, 10 tbr, 100 tbn, 100 tbc Output #0, gif, to '/storage/emulated/0/GIF/REV20170308_101145.gif': Metadata: encoder : Lavf57.25.100 Stream #0:0: Video: gif, bgr8, 125x56, q=2-31, 200 kb/s, 10 fps, 100 tbn, 10 tbc Metadata: encoder : Lavc57.24.102 gif Stream mapping: Stream #0:0 -> #0:0 (gif (native) -> gif (native)) Press [q] to stop, [?] for help frame= 11 fps=0.0 q=-0.0 Lsize= 17kB time=00:00:02.90 bitrate= 48.8kbits/s speed=14.8x
    video:16kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.287261%

  • AVFormatContext with alsa,v4l2 to output AVFormatContext

    8 mars 2017, par GeneralN00bs

    Read first: I'm a new guy with Stack Overflow, and poor English, so please excuse my English, which is really bad.

    I'm trying to do web streaming with open input device; audio, video devices to HTML5 video.

    for example, this project using ffmpeg command to like this:

    ffmpeg -f v4l2 -i 

    Here's the main question: I can open 2 avformatcontext with C language like this:

     AVFormatContext* get_ctx(const char* dev,const char* driver,AVDictionary *options)
     {
          AVFormatContext *ictx = avformat_alloc_context();
          AVInputFormat *fmt = NULL;
    
          //get input format.
          fmt = av_find_input_format(driver);
          //if have options
          if(options){
              //open device with options
              if(avformat_open_input(&ictx,dev,fmt,&options)<0){
                  printf("get device with options failed.\n");
                  return NULL;
              }
              //find stream info.
              if(avformat_find_stream_info(ictx,&options)<0){
                  printf("get stream info with options failed.\n");
                  return NULL;
              }
          //not have options.
          }else{
              if(avformat_open_input(&ictx,dev,fmt,NULL)<0){
                  printf("get device failed.\n");
                  return NULL;
              }
              if(avformat_find_stream_info(ictx,NULL)<0){
                  printf("get stream info failed.\n");
                  return NULL;
              }
          }
          av_dump_format(ictx,0,adev,0);
          return ictx;
      }
    

    Well, get v4l2 and alsa devices successfully using function above. but I can't figure it out (2 input avformatcontext) to output avformatcontext. Any idea how can I am muxing 2 avformatcontext to output avformatcontext?

  • FFMPEG -F Concat Video, Audio Sycn Issue

    7 mars 2017, par Zakir_SZH

    i am having issue, to concat video, it looses the audio sync and audio started from previous video.

    i have tried below two link/so answer by Mulvya, but none of them work :(

    here is the code i am trying:

    1: re-encode file a (1):

    ffmpeg.exe -i "f:\1.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 01.mp4
    

    2: re-encode file b (2):

    ffmpeg.exe -i "f:\2.mp4" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 02.mp4
    

    3: Now contact using following command:

    ffmpeg.exe -f concat -safe 0 -i "f:\files.txt" -c copy test.mp4
    

    but audio is not synced with video ;(

    i also uploaded both video (and also the output) on dropbox:

    Video Sync Issue Source And Result Files

    so, any help, how to make audio perfectly sync with video would be great :)

  • OpenCV MP4 Creation

    7 mars 2017, par user5051092

    I've been trying to trying to write MP4 video files using OpenCV, in python.

    AVI creation works fine, both on linux and windows, when I use both:

    out = cv2.VideoWriter('x.avi', 0, 30, (640, 480))
    

    and

    fourcc = cv2.VideoWriter_fourcc(*"XVID")
    out = cv2.VideoWriter('x.avi', fourcc, 30, (640, 480))
    

    and even

    fourcc = cv2.VideoWriter_fourcc(*"XVID")
    out = cv2.VideoWriter('x', fourcc, 30, (640, 480))
    

    .

    When I try to save an MP4 however nothing ever saves - using:

    fourcc = cv2.VideoWriter_fourcc(*"H264")
    out = cv2.VideoWriter('x.mp4', fourcc, 30, (640, 480))
    

    and

    fourcc = cv2.VideoWriter_fourcc(*"AVC1")
    out = cv2.VideoWriter('x.mp4', fourcc, 30, (640, 480))
    

    No errors occur, just nothing saves.

    I've tried everything over the past few days, doing everything to avoid creating the AVI and then converting it to MP4 using ffmpeg as I find that to be horrible practice.

  • How do I properly enable ffmpeg for matplotlib.animation ?

    7 mars 2017, par spanishgum

    I have covered a lot of ground on stack so far trying to get ffmpeg going so I can make a timelapse video.

    I am on a CentOS 7 machine, running python3.7.0a0.

    python3
    >>> import numpy as np
    >>> np.__version__
    '1.12.0'
    >>> import matplotlib as mpl
    >>> mpl.__version__
    '2.0.0'
    >>> import mpl_toolkits.basemap as base
    >>> base.__version__
    '1.0.7'
    

    I found this github gist on installing ffmpeg. I used the chromium source, and installed without a prefix option (using the default).

    I have confirmed that ffmpeg is installed, although I don't know anything about testing whether it works.

    which ffmpeg
    /usr/local/bin/ffmpeg
    
    ffmpeg -version
    ffmpeg version N-83533-gada281d Copyright (c) 2000-2017 the FFmpeg dev elopers
    built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11
    configuration:
    libavutil      55. 47.100 / 55. 47.100
    libavcodec     57. 80.100 / 57. 80.100
    libavformat    57. 66.102 / 57. 66.102
    libavdevice    57.  2.100 / 57.  2.100
    libavfilter     6. 73.100 /  6. 73.100
    libswscale      4.  3.101 /  4.  3.101
    libswresample   2.  4.100 /  2.  4.100
    

    I tried to run a few sample examples I found online:

    [1] http://matplotlib.org/examples/animation/basic_example_writer.html

    [2] http://stackoverflow.com/a/23098090/3454650

    Everything works fine up until I try to save the animation file.

    [1]

     anim.save('basic_animation.mp4', writer = FFwriter, fps=30, extra_args=['-vcodec', 'libx264'])
    

    [2]

    im_ani.save('im.mp4', writer=writer)
    

    I found here that explictly setting the path to ffmpeg might be necessary so I added this to the top of the test scripts:

    plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg'
    

    I tried a few more tweaks in the code but always get the same response, which I do not know how to begin deciphering:

    Traceback (most recent call last):
      File "testanim.py", line 27, in 
        writer.grab_frame()
      File "/usr/local/lib/python3.7/contextlib.py", line 100, in __exit__
        self.gen.throw(type, value, traceback)
      File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 256, in saving
        self.finish()
      File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 276, in finish
        self.cleanup()
      File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 311, in cleanup
        out, err = self._proc.communicate()
      File "/usr/local/lib/python3.7/subprocess.py", line 836, in communicate
        stdout, stderr = self._communicate(input, endtime, timeout)
      File "/usr/local/lib/python3.7/subprocess.py", line 1474, in _communicate
        selector.register(self.stdout, selectors.EVENT_READ)
      File "/usr/local/lib/python3.7/selectors.py", line 351, in register
        key = super().register(fileobj, events, data)
      File "/usr/local/lib/python3.7/selectors.py", line 237, in register
        key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
      File "/usr/local/lib/python3.7/selectors.py", line 224, in _fileobj_lookup
        return _fileobj_to_fd(fileobj)
      File "/usr/local/lib/python3.7/selectors.py", line 39, in _fileobj_to_fd
        "{!r}".format(fileobj)) from None
    ValueError: Invalid file object: <_io.BufferedReader name=6>
    

    Is there something with my configuration that is malformed? I searched google for this error for some time but never found anything relevant to animations / ffmpeg. Any help would be greatly appreciated.


    UPDATE:

    @LordNeckBeard pointed me here: https://trac.ffmpeg.org/wiki/CompilationGuide/Centos

    I ran into problems with installing the x264 encoding dependency. Some files in libavcodec/*.c (in the make output) were reporting undefined references to several functions. After a wild goose chase found this: https://mailman.videolan.org/pipermail/x264-devel/2015-February/010971.html

    To fix the x264 installation, I simply added some configure flags:

    ./configure --enable-static --enable-shared --extra-ldflags="-lswresample -llzma"
    

    UPDATE:

    So everything installed fine after fixing the libx264 problems. I went ahead and copied the ffmpeg binary from the ffmpeg_build folder into /usr/local/bin/ffmpeg.

    After running the script I was getting problems where ffmpeg could not find the libx264 shared object. I think I will have to recompile everything using different prefixes. My intuition tells me there are old files laying around after I have messed with everything, using some configuration that is broken.

    So I decided maybe I should just try to use NUX: http://linoxide.com/linux-how-to/install-ffmpeg-centos-7/ I installed ffmpeg using the new rpm, but to no avail. I still was not able to run ffmpeg because of a missing shared object.

    Finally, instead of usiong files copied into my /usr/local/bin folder, I ran ffmpeg directly from the build bin directory. Turns out that this does work properly!

    So in essence, if I want to install ffmpeg system wide, I need to manually compile from sources again but using a nonlocal prefix.