Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg automaticall re-scaling. How can I prevent it wihtout having to provide height for 'force_original_aspect_ratio' ?

    16 février 2020, par user2328273

    I am using ffmpeg to take screenshots of a video file. It seems some video files end up looking squished because ffmpeg is automatically rescaling them for some reason. I am using a python package to do this, not the CLI tool. The only options I am using are specifying the timestamp to capture and quiet output. I am try to get a lossless shot. I don't know why it is resizing automatically. I tried using the force_original_aspect_ratio option and setting it to -1 but it does not work without specifying the height. Is there any way to prevent this from happening without needing to provide the height? I can do that for my script but it seems unnecessary. It should just keep it as-is.

    EDIT: BTW, the video is 720x480. Oddly, the metadata on the video and the screen shot are both 720x480. However I lined them up and the video is clearly wider. VLC takes a screenshot just fine. Someone told me ffmpeg just has issues with SD files. I don't know.

  • runtime/cgo : pthread_create failed : Resource temporarily unavailable

    15 février 2020, par nadermx

    I currently have this function, that pipes multiple youtubedl commands thru ffmpeg, and then pipes the output of ffmpeg to an HTTP client.

    func pipeThruFfmpegToMp4(vi *VideoInfo, rw web.ResponseWriter) error {
        var ffmpeg *exec.Cmd
        ffmpeg = exec.Command(
            "ffmpeg",
            "-i", "-",
            "-i", "pipe:3",
            "-c:v", "copy", "-c:a", "copy",
            "-preset", "veryfast",
            "-metadata", fmt.Sprintf(`title=%s`, vi.GetTitle()),
            "-movflags", "frag_keyframe+empty_moov",
            "-f", "mp4",
            "-")
    
    
        youtubevideo := exec.Command(YoutubeDLPath, "-c", "-f", fmt.Sprintf("%s/bestvideo[ext=mp4]/bestvideo/best", vi.GetFormat()), "--no-cache-dir", "--restrict-filenames", "--hls-prefer-native", "-o", "-", fmt.Sprintf("%s", vi.GetVideoUrl()))
        fmt.Println(youtubevideo)
    
        youtube := exec.Command(YoutubeDLPath, "-c", "-f", "bestaudio[ext=m4a]/bestaudio/best", "--no-cache-dir", "--restrict-filenames", "--hls-prefer-native", "-o", "-", fmt.Sprintf("%s", vi.GetVideoUrl()))
        fmt.Println(youtube)
    
        var ytvbuf, ytbuf, ffbuf bytes.Buffer
        youtubevideo.Stderr = &ytvbuf
        youtube.Stderr = &ytbuf
        ffmpeg.Stderr = &ffbuf
    
        video, err := youtubevideo.StdoutPipe()
        if err != nil {
            log.Printf("pipeThruFfmpegToMp4: %v\n", err)
            return err
        }
    
        pipe3, err := youtube.StdoutPipe()
        if err != nil {
            log.Printf("pipeThruFfmpegToMp4: %v\n", err)
            return err
        }
    
        ffmpeg.Stdin = video
        ffmpeg.ExtraFiles = []*os.File{pipe3.(*os.File)}
        ffmpeg.Stdout = rw
    
        // Headers sent, no turning back now
        rw.Header().Set("Content-Type", "video/mp4")
        rw.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=\"%s.mp4\"", vi.GetSlug()))
        rw.Flush()
    
        ffmpeg.Start()
        youtubevideo.Start()
        youtube.Start()
        ffmpeg.Wait()
        youtubevideo.Wait()
        youtube.Wait()
    
        // check ytvbuf, ytbuf, ffbuf for stderr errors
    
        if ffbuf.Len() != 0 {
            rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ffbuf.String()})
            log.Printf("pipeThruFfmpegToMp4: %v\n", ffbuf.String())
        }
        if ytvbuf.Len() != 0 {
            rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ytvbuf.String()})
            log.Printf("pipeThruYouTubevDLToMp4: %v\n", ytvbuf.String())
        }
        if ytbuf.Len() != 0 {
            rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ytbuf.String()})
            log.Printf("pipeThruYouTubeDLToMp4: %v\n", ytbuf.String())
        }
    
        return nil
    }
    

    The problem is that everything runs fine, but after a while the ram starts filling up on the server, till it gets to the point that it errors out with runtime/cgo: pthread_create failed: Resource temporarily unavailable

    I'm unsure if it's a memory leak, or if either instance of youtube-dl is not closing right or if ffmpeg isn't closing right and just consuming more and more ram as the program runs more, until the program crashes with this error

    runtime/cgo: pthread_create failed: Resource temporarily unavailable
    SIGABRT: abort
    PC=0x7f083501fe97 m=128 sigcode=18446744073709551610
    
    goroutine 0 [idle]:
    runtime: unknown pc 0x7f083501fe97
    stack: frame={sp:0x7f05ff7fd7d0, fp:0x0} stack=[0x7f05feffe288,0x7f05ff7fde88)
    00007f05ff7fd6d0:  00007f05ff7fd700  0000ffff00001fa0
    00007f05ff7fd6e0:  00007f05ff7fdbe0  00007f05f8000da0
    00007f05ff7fd6f0:  0000000000000000  000000000093032c
    00007f05ff7fd700:  0000000000000000  00007f0835600ec3
    00007f05ff7fd710:  0000000000000005  0000000000000000
    00007f05ff7fd720:  000000c0000ce120  00007f0834ff1ce0
    00007f05ff7fd730:  00007f05ff7fdaf0  00007f083560870a
    00007f05ff7fd740:  0000000000000000  0000000000000000
    00007f05ff7fd750:  0000000000000000  00007f05ff7fdbe0
    00007f05ff7fd760:  2525252525252525  2525252525252525
    00007f05ff7fd770:  000000ffffffffff  0000000000000000
    00007f05ff7fd780:  000000ffffffffff  0000000000000000
    00007f05ff7fd790:  000000c00010d1a0  000000c000953740
    00007f05ff7fd7a0:  000000c0000ce120  000000c000cf2300
    00007f05ff7fd7b0:  000000c00010d260  000000c001f4e180
    00007f05ff7fd7c0:  000000c001f4e000  000000c00169f680
    00007f05ff7fd7d0: <0000000000000000  000000c001f34180
    00007f05ff7fd7e0:  6e75720000000000  6f67632f656d6974
    00007f05ff7fd7f0:  0000000000000000  0000000000000000
    00007f05ff7fd800:  000000c000cf2300  000000c00010d260
    00007f05ff7fd810:  000000c001f4e180  000000c001f4e000
    00007f05ff7fd820:  000000c00169f680  000000c00169f500
    00007f05ff7fd830:  000000c001f34180  000000c001f34000
    00007f05ff7fd840:  000000c000c92780  000000c001ec2600
    00007f05ff7fd850:  fffffffe7fffffff  ffffffffffffffff
    00007f05ff7fd860:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd870:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd880:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd890:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd8a0:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd8b0:  ffffffffffffffff  ffffffffffffffff
    00007f05ff7fd8c0:  ffffffffffffffff  ffffffffffffffff
    runtime: unknown pc 0x7f083501fe97
    stack: frame={sp:0x7f05ff7fd7d0, fp:0x0} stack=[0x7f05feffe288,0x7f05ff7fde88)
    00007f05ff7fd6d0:  00007f05ff7fd700  0000ffff00001fa0
    00007f05ff7fd6e0:  00007f05ff7fdbe0  00007f05f8000da0
    00007f05ff7fd6f0:  0000000000000000  000000000093032c
    00007f05ff7fd700:  0000000000000000  00007f0835600ec3
    00007f05ff7fd710:  0000000000000005  0000000000000000
    

    I've also tried building the binary with CGO_ENABLED=0 even though I don't even have a import "c" but that also ends up erroring out as well with

    runtime: failed to create new OS thread (have 21 already; errno=11)
    runtime: may need to increase max user processes (ulimit -u)
    fatal error: newosproc
    

    my limit's are already very generouse, which maybe could also be a problem? Or do I maybe have to increase the pipe size?

    $ ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 192907
    max locked memory       (kbytes, -l) 16384
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 100000
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 65536
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 63883
    virtual memory          (kbytes, -v) unlimited
    

    Either way, I apprecate any and all the help I can get on this. Here is a link to the entire program and here is a thread in the golang-nuts forum regarding this questions

  • FFMpeg - Concat Video Files + Fade Transition

    15 février 2020, par John Doe

    Using BATCH-File, I am piping lots of videos to FFMpeg and would like to crossfade the transitions. Instead of going to black, I'd like them to overlap by 2 seconds during the transition. Audio is not necessary as the videos are all silent. I am adding looped audio separately.

    (
    for /F %%i in ('dir /b "Folder\*.mp4"') do @echo file 'Folder/%%i'
    ) | ffmpeg -y -protocol_whitelist file,pipe -f concat -safe 0 -stream_loop -1 -i pipe: -stream_loop -1 -i "audio.mp3" -c copy -movflags faststart -fflags genpts -preset veryfast -t 3600 -r 30 "output.mp4"
    

    I've found lots of similar examples online but none are suitable. A little help would be appreciated. Thank you.

  • Concatenating on Windows throws "Invalid data found when processing input" while it works on Mac and Linux

    15 février 2020, par miguelmorin

    I need to run a command with a nightly build of FFMPEG to report a bug on the concat protocol. I found it difficult to compile from source with libx264 support on Linux, and I want to spare my Mac computer, so I use the nightly build on Windows from Zeranoe.

    I call this command to concatenate the files:

    ffmpeg -safe 0 concat -i files_to_combine -vcodec libx264 show.mp4
    

    where files_to_combine is:

    file ./short_DSC_0013.MOV
    file ./short_DSC_0014.MOV
    file ./short_DSC_0015.MOV
    file ./short_DSC_0016.MOV
    file ./short_DSC_0017.MOV
    file ./short_DSC_0018.MOV
    file ./short_DSC_0019.MOV
    

    I call this command from the directory containing the video files and files_to_combine.

    On Windows with a nightly build, I get the error:

    files_to_combine: Invalid data found when processing input
    

    I changed file ./DSC_0013.MOV to these options, all with the same error:

    file 'short_DSC_0013.MOV'
    file '.\short_DSC_0013.MOV'
    file 'F:\short_DSC_0013.MOV'
    

    How can I debug this error, or what is the syntax for concatenating on Windows with a nightly build?

    Update with log-level 48

    I ran the same command with -v 48 and got:

    F:\brain squids>C:\Users\migue\Desktop\ffmpeg-20200211-f15007a-win64-static\bin\ffmpeg.exe -v 48 -i files_to_combine -vcodec libx264 show.mp4
    ffmpeg version git-2020-02-11-f15007a Copyright (c) 2000-2020 the FFmpeg developers
      built with gcc 9.2.1 (GCC) 20200122
      configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
      libavutil      56. 39.100 / 56. 39.100
      libavcodec     58. 68.102 / 58. 68.102
      libavformat    58. 38.100 / 58. 38.100
      libavdevice    58.  9.103 / 58.  9.103
      libavfilter     7. 75.100 /  7. 75.100
      libswscale      5.  6.100 /  5.  6.100
      libswresample   3.  6.100 /  3.  6.100
      libpostproc    55.  6.100 / 55.  6.100
    Splitting the commandline.
    Reading option '-v' ... matched as option 'v' (set logging level) with argument '48'.
    Reading option '-i' ... matched as input url with argument 'files_to_combine'.
    Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libx264'.
    Reading option 'show.mp4' ... matched as output url.
    Finished splitting the commandline.
    Parsing a group of options: global .
    Applying option v (set logging level) with argument 48.
    Successfully parsed a group of options.
    Parsing a group of options: input url files_to_combine.
    Successfully parsed a group of options.
    Opening an input file: files_to_combine.
    [NULL @ 0000021c781784c0] Opening 'files_to_combine' for reading
    [file @ 0000021c78179580] Setting default whitelist 'file,crypto,data'
    [AVIOContext @ 0000021c781817c0] Statistics: 182 bytes read, 0 seeks
    files_to_combine: Invalid data found when processing input
    

    The contents of files_to_combine is:

    file 'short_DSC_0013.MOV'
    file 'short_DSC_0014.MOV'
    file 'short_DSC_0015.MOV'
    file 'short_DSC_0016.MOV'
    file 'short_DSC_0017.MOV'
    file 'short_DSC_0018.MOV'
    file 'short_DSC_0019.MOV'
    

    Update because of wrong command

    I had mistyped the command. The right command has a -f in front of concat, which I found because the accepted answer was able to make the command work in a similar environment:

    ffmpeg -safe 0 -f concat -i files_to_combine -vcodec libx264 show.mp4
    
  • Permission denied for openFileDescriptor to pass a file from SDCARD to FFmpeg

    15 février 2020, par 1234567

    Permission denied for openFileDescriptor to pass a file from SDCARD to FFmpeg

    I am trying to work with a file from Sdcard which is to be passed to FFmpeg fro this I am using

     Uri contentUri = ContentUris.withAppendedId(
                MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                cursor.getLong(Integer.parseInt(BaseColumns._ID)));
        String fileOpenMode = "r";
        ParcelFileDescriptor parcelFd =
                resolver.openFileDescriptor(contentUri, fileOpenMode);
        if (parcelFd != null) {
            int fd = parcelFd.detachFd();
            // Pass the integer value "fd" into your native code. Remember to call
            // close(2) on the file descriptor when you're done using it.
        }
    
    int pid = android.os.Process.myPid();
                String mediaFile = "/proc/" + pid + "/fd/" + fd;
    
                Toast.makeText(videoexample.this, "mediafile" + mediaFile, Toast.LENGTH_SHORT).show();
    
                //File directoryToStore = videoexample.this.getExternalFilesDir("tempDirectory");
                File directoryToStore = videoexample.this.getExternalFilesDir("tempDirectory");
                if(directoryToStore != null) {
                    if (!directoryToStore.exists()) {
                        if (directoryToStore.mkdir()) ; //directory is created;
                    }
                }
    
    
                // Output path passed to FFmpeg
                String outputPath = directoryToStore+"/testFile.mp4";
    
                int rc = FFmpeg.execute("-y -i "+mediaFile+" -filter:v scale=1280:720 -c:a copy "+outputPath);
    

    If this file is present in the SDCard , It gives me an error

    E/mobile-ffmpeg: /proc/20124/fd/169: Permission denied in the logcat

    however if the file is from Internal (phone's ) storage it works fine

    all the permissions are given , I am trying it on a Moto C android 7.0

    any help would be useeful