Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • FFmpeg : About filter_complex command [closed]

    18 juin, par HJ Kim

    I use this command.

    ffmpeg -i Input.mp4 -i logo.png -c:v h264_nvenc -filter_complex "[0:v]scale=-1:720[video];[1:v][video]scale2ref=(iw/ih)*ih/8/sar:ih/8[wm][base];[base][wm]overlay=10:10" output.mp4

    But what does this mean?

    scale2ref=(iw/ih)*ih/8/sar:ih/8

  • Using FFmpeg in .net ?

    17 juin, par daniel

    So I know its a fairly big challenge but I want to write a basic movie player/converter in c# using the FFmpeg library. However, the first obstacle I need to overcome is wrapping the FFmpeg library in c#. I've downloaded ffmpeg but couldn't compile it on Windows, so I downloaded a precompiled version for me. Ok awesome. Then I started looking for C# wrappers.

    I have looked around and have found a few wrappers such as SharpFFmpeg (http://sourceforge.net/projects/sharpffmpeg/) and ffmpeg-sharp (http://code.google.com/p/ffmpeg-sharp/). First of all, I wanted to use ffmpeg-sharp as its LGPL and SharpFFmpeg is GPL. However, it had quite a few compile errors. Turns out it was written for the mono compiler, I tried compiling it with mono but couldn't figure out how. I then started to manually fix the compiler errors myself, but came across a few scary ones and thought I'd better leave those alone. So I gave up on ffmpeg-sharp.

    Then I looked at SharpFFmpeg and it looks like what I want, all the functions P/Invoked for me. However its GPL? Both the AVCodec.cs and AVFormat.cs files look like ports of avcodec.c and avformat.c which I reckon I could port myself? Then not have to worry about licencing.

    But I want to get this right before I go ahead and start coding. Should I:

    1. Write my own C++ library for interacting with ffmpeg, then have my C# program talk to the C++ library in order to play/convert videos etc.

    OR

    1. Port avcodec.h and avformat.h (is that all i need?) to c# by using a whole lot of DllImports and write it entirely in C#?

    First of all consider that I'm not great at C++ as I rarely use it but I know enough to get around. The reason I'm thinking #1 might be the better option is that most FFmpeg tutorials are in C++ and I'd also have more control over memory management than if I was to do it in c#.

    What do you think? Also would you happen to have any useful links (perhaps a tutorial) for using FFmpeg?

  • Text on video ffmpeg

    17 juin, par Jesper Madsen

    How can I add text overlay on my video in ffmpeg?

    i.e. given a video "video1.flv", how can I add "StackOverflow" text during the whole video, positioned in the middle of the screen, with white text and a border?

  • Writing a video frame by frame using ffmpeg

    16 juin, par Chris

    I am trying to write a video frame-by-frame using ffmpeg as explained here: http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/

    However, I am always getting an OSError: [Errno 22] Invalid argument. I am on Windows 7 and using Python 3.4.

    Here is the code:

    import subprocess as sp
    import numpy as np
    import time
    
    ffmpeg_bin = r'C:\path\to\ffmpeg\ffmpeg.exe'
    
    command = [ffmpeg_bin,
               '-y', # (optional) overwrite output file if it exists
               '-f', 'rawvideo',
               '-vcodec','rawvideo',
               '-s', '420x360', # size of one frame
               '-pix_fmt', 'rgb24',
               '-r', '24', # frames per second
               '-i', '-', # The imput comes from a pipe
               '-an', # Tells FFMPEG not to expect any audio
               '-vcodec', 'mpeg',
               'my_output_videofile.mp4' ]
    
    proc = sp.Popen(command, stdin=sp.PIPE, stderr=sp.PIPE)
    
    a = np.zeros((360, 420, 3), dtype=np.uint8)
    
    for ii in range(5*24):
        print(ii)
        proc.stdin.write(a.tostring())
        time.sleep(1/24)
    
    proc.stdin.close()
    proc.stderr.close()
    proc.wait()
    

    And here is the output of the program:

    0
    1
    Traceback (most recent call last):
      File ".\write_dummy_video.py", line 25, in 
        proc.stdin.write(a.tostring())
    OSError: [Errno 22] Invalid argument
    

    Interestingly, if I comment line number 26 (i.e. time.sleep(1/24)) the error message changes slightly but the loop still only runs twice. Here is the error output:

    0
    1
    Traceback (most recent call last):
      File ".\write_dummy_video.py", line 25, in 
        proc.stdin.write(a.tostring())
    BrokenPipeError: [Errno 32] Broken pipe
    

    What could be causing this problem, and how can I fix it?

  • How can I convert audio to WAVE_FORMAT_PCM using FFmpeg ?

    16 juin, par Eric Stdlib

    I am using Python's wave module to read audio, and using FFmpeg to convert audio from other types to wav. However, I am encountering some problem.

    I wrote v.py to generate an silence audio file a.wav

    import sys, wave, math
    import numpy as np
    
    wave_data = np.zeros(44100).astype(np.short)
    
    f = wave.open('a.wav', 'wb')
    f.setnchannels(1)
    f.setsampwidth(2)
    f.setframerate(96000)
    f.writeframes(wave_data.tostring())
    f.close()
    

    Then I used FFmpeg to "copy" a.wav to b.wav (though it seems to encode / decode the file), but I can only read a.wav with Python; b.wav cannot be opened.

    [user@localhost tmp]$ ffmpeg -i a.wav b.wav
    Guessed Channel Layout for Input Stream #0.0 : mono
    Input #0, wav, from 'a.wav':
      Duration: 00:00:00.46, bitrate: 1536 kb/s
        Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 96000 Hz, mono, s16, 1536 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
    Press [q] to stop, [?] for help
    Output #0, wav, to 'b.wav':
      Metadata:
        ISFT            : Lavf57.71.100
        Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 96000 Hz, mono, s16, 1536 kb/s
        Metadata:
          encoder         : Lavc57.89.100 pcm_s16le
    size=      86kB time=00:00:00.45 bitrate=1537.8kbits/s speed= 706x    
    video:0kB audio:86kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.115646%
    [user@localhost tmp]$ python3
    Python 3.6.4 (default, Jan 23 2018, 22:25:37) 
    [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import wave
    >>> wave.open('a.wav')
    
    >>> wave.open('b.wav')
    Traceback (most recent call last):
      File "", line 1, in 
      File "/usr/lib64/python3.6/wave.py", line 499, in open
        return Wave_read(f)
      File "/usr/lib64/python3.6/wave.py", line 163, in __init__
        self.initfp(f)
      File "/usr/lib64/python3.6/wave.py", line 143, in initfp
        self._read_fmt_chunk(chunk)
      File "/usr/lib64/python3.6/wave.py", line 260, in _read_fmt_chunk
        raise Error('unknown format: %r' % (wFormatTag,))
    wave.Error: unknown format: 65534
    >>> 
    

    How should I change the command of FFmpeg to convert the file to WAVE_FORMAT_PCM, so that I can read b.wav with Python?