Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Efficiently write a movie directly from np.array using pipes

    16 juin 2017, par Matt Billman

    I have a 4D numpy array of movie frames. I'm looking for a function to write them to a movie, at a given framerate. I have FFMPEG installed on my OS, and as I can see from these answers, the most efficient way to do so is via pipes.

    However, I have very little experience using pipes, and the explanations in the link above make little sense to me. Furthermore, very few of the answers seem actually implement pipes, and the one that does uses mencoder, not FFMPEG. I am relatively inexperienced with FFMPEG, so am not sure how to modify the command string from the mencoder answer to make it work in FFMPEG.

    WHAT I WOULD LIKE:

    A function of the following form:

    animate_np_array(4d_array, framerate) -> output.mp4 (or other video codec)

    Which implements pipes to send frames one after the other to FFMPEG, and which I can copy-paste into my existing code.

    Furthermore, it is absolutely necessary that this function never actually plots any of the frames, as calls to the matplotlib.imshow() function (as I have most typically seen used) slow things down considerably.

  • Simple ffmpeg merge and volume customization

    16 juin 2017, par 1234567

    I have following commands to change volume of audio, video and then merge it.

    First, change volume level of a MP3 File.

    ffmpeg -i audio.mp3 -vol 100 audio1.mp3

    then change volume level of a MP4 File.

    ffmpeg -i video.mp4 -vol 300 video1.mp4

    and then to merge both audio and video at specific time of video.

    String[] complexCommand = 
                   {"-ss", "" + startMs / 1000, "-y", "-i", video1.mp4`,"-i",
                   audio1.mp3, "-t", "" + (endMs - startMs) / 1000, "-s",
                   "320x240", "-vcodec", "mpeg4", "-b:v",
                   "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", output.mp4};
    

    I want to simplify this into just one process.

    How can this be done?

    I tried this command:

    String[] complexCommand = {"-i",STORE_DIRECTORY,"-i",yourRealPath,"-filter_complex","[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];[a1][a2]amerge,pan=stereo:c0code>

    I am using https://github.com/WritingMinds/ffmpeg-android-java

    It gave me the error Unknown encoder '-vcodec' but when I tried to simply merge audio with video without volume customization, it worked fine.

  • Suppress subprocess console output in a python windowed (Tkinter) app

    16 juin 2017, par Eliad Cohen

    I am attempting to run the following code in a python app executable made using

    pyinstaller -w -F script.py

    :

    def ffmpeg_command(sec):
        cmd1 = ['ffmpeg', '-f','gdigrab','-framerate',config.get('FFMPEG_Settings','Framerate'),'-i','desktop',gen_filename_from_timestamp_and_extension()]
    
    
        proc = subprocess.Popen(cmd1,stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    
        duration = sec
        sleeptime = 0
        while proc.poll() is None and sleeptime < duration: 
            # Wait for the specific duration or for the process to finish
            time.sleep(1)
            sleeptime += 1
    
        proc.terminate()
    

    The above code is run when a Tkinter button is pressed and this code is called from the button click handler.

    My problem is that when I am running the exe this doesn't run ffmpeg. However, If I set the command to be:

    proc = subprocess.Popen(cmd1)
    

    FFMPEG does run, I get the movie file I wanted but I can see the console window for FFMPEG. So I end up getting the console window in my movie. (I take care of minimizing the Tkinter window in the button click handler)

    My question is how do I suppress the console window and still have FFMPEG run the way I want it to? I looked at the following threads but couldn't make it work: How to hide output of subprocess in Python 2.7, Open a program with python minimized or hidden

    Thank you

  • Rotate Android video for display on web

    16 juin 2017, par Kim

    I'm building a website. I'm trying to load my first video onto it. This mp4 video is in portrait orientation and was recorded on an Android device.

    When I load this mp4 onto my website, it plays perfectly (in portrait orientation) on Chrome; however, it plays in landscape orientation on Firefox & IE. I realise that this is because Chrome is using the rotation metadata that is stored within the mp4 to play the video in the correct orientation, while FF & IE don't use this metadata.

    I've tried to correct this issue using FFMPEG, and various combinations of the Transpose, Metadata & Rotate commands. I am using MediaInfo to view the metadata associated with the files that I produce using FFMPEG.

    My problem is: 1) If I use Transpose=1, then on FF & IE & Windows Media Player, the resulting video is actually rotated through 180 degrees, and the metadata shows the file width and depth to be the same as the original file. 2) If I use -metadata:s:v rotate=0 (I've also tried rotate=90), then MediaInfo tells me that the resulting files width & depth are now portrait, but FF & IE & WMP will not play the resulting file. WMP plays the sound but no image, and FF gives an error message "Error Loading This Resource".

    What ffmpeg command do I need to use to convert a portrait MP4 recorded an android device into an mp4 that will play in the correct orientation on Firefox?

    Thanks in advance

  • Create Slideshow video by merge png and jpeg images and audio files using ffmpeg on linux

    16 juin 2017, par Darshan ambaliya

    I am creating slideshow video using png,jpeg and audio files the issue i am getting is the at a time only either i have to use png or jpeg but i want to used both so how can i do this here are my list of commands which i am trying. Please help me regards this.

    /usr/bin/ffmpeg '-framerate' '1/27' '-pattern_type' 'glob' '-i' '/var/www/html/phpvideotoolkit-v2-master/examples/media/images/*.jpg' '-i' '/var/www/html/phpvideotoolkit-v2-master/examples/media/1.mp3' '-pix_fmt' 'yuv420p' '-shortest' '-y' '-q' '4' '-strict' 'experimental' '-threads' '1' '-acodec' 'aac' '-ar' '22050' '-vcodec' 'mpeg4' '-s' '320x240' '/var/www/html/ffmpe/1.mp4' 
    

    By doing this i am only able to create jpg images video but i want to both.

    i have used concat command also but not getting any output i have read about some filter but how to used with images i dont know so could you please help me with this.