Newest 'ffmpeg' Questions - Stack Overflow

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

Articles published on the website

  • ffmpeg how add header info into pcm?

    23 September, by Zheng Xiaodong

    I use this cmd convert s16le to pcmu8, but will lost header info.

    ffmpeg -i s16le.wav -f u8 pcmu8.wav
    ffmpeg -i pcmu8.wav
    # pcmu8.wav: Invalid data found when processing input
    

    I want known, how add this header info into pcmu8.wav?

    It should be this:

    ffmpeg -i pcmu8.wav
    #Input #0, wav, from 'pcmu8.wav':
    #  Duration: 00:13:39.20, bitrate: 64 kb/s
    #  Stream #0:0: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 8000 Hz, mono, u8, 64 kb/s
    
  • How to convert gif in mp4 video with Nodejs?

    23 September, by Somename

    Is there a way to convert a .gif uploaded image into .mp4 with only Nodejs? How do I integrate that with a MEAN app? I want to be able to store the converted .mp4 file to S3.

    Using : https://www.npmjs.com/package/fluent-ffmpeg-extended but get error : Invalid Input

    var upload = multer({
        storage: multerS3({
           s3: s3,
           bucket: 'mybucket',
           key: function (req, file, cb) {
            var extension = file.originalname.substring(file.originalname.lastIndexOf('.')+1).toLowerCase();
                if(extension == "gif"){
                    console.log(file);
                    var proc = new ffmpeg({ source: file })
                      .usingPreset('podcast')
                      .saveToFile('/path/to/your_target.m4v', function(stdout, stderr) {
                        console.log('file has been converted succesfully');
                      });
                }
                else{
                    cb(null, file.originalname);
                }
            }
        })
    });
    

    Many thanks.

  • Extract text between

    23 September, by Kaique Vortex

    Could you please help me?

    frame=48612 fps= 50 q=28.0 size=  113664kB time=00:33:45.42 bitrate= 459.7kbits/s speed=2.09x    
    frame=48612 fps= 50 q=28.0 size=  113664kB time=00:33:45.45 bitrate= 459.7kbits/s speed=2.09x    
    frame=48613 fps= 51 q=28.0 size=  113664kB time=00:33:45.45 bitrate= 459.7kbits/s speed=2.09x    
    frame=48613 fps= 50 q=28.0 size=  113664kB time=00:33:45.47 bitrate= 459.7kbits/s speed=2.09x    
    frame=48613 fps= 49 q=28.0 size=  113664kB time=00:33:45.49 bitrate= 459.7kbits/s speed=2.09x    
    frame=48614 fps= 50 q=28.0 size=  113664kB time=00:33:45.49 bitrate= 459.7kbits/s speed=2.09x    
    frame=48614 fps= 50 q=28.0 size=  113664kB time=00:33:45.51 bitrate= 459.7kbits/s speed=2.09x    
    frame=48614 fps= 51 q=28.0 size=  113664kB time=00:33:45.53 bitrate= 459.7kbits/s speed=2.09x    
    frame=48615 fps= 50 q=28.0 size=  113664kB time=00:33:45.53 bitrate= 459.7kbits/s speed=2.09x    
    frame=48615 fps= 50 q=28.0 size=  113664kB time=00:33:45.55 bitrate= 459.7kbits/s speed=2.09x    
    frame=48615 fps= 50 q=28.0 size=  113664kB time=00:33:45.57 bitrate= 459.7kbits/s speed=2.09x    
    frame=48616 fps= 52 q=25.0 size=  113664kB time=00:33:45.57 bitrate= 459.7kbits/s speed=2.09x    
    

    Do you know if it's possible to remove everything except FPS={num}? I want to output something like this:

    50
    50
    51
    50
    49
    50
    ...
    

    What I have tried:

    ffmpeg -i in.mp4 -stats_period 0.0001 out.mp4 | grep -o -P '(?<=fps= ).*(?= q=)'
    ffmpeg -i in.mp4 -stats_period 0.0001 out.mp4 | grep fps | awk '{print $2}' | tr -d , 
    

    Both do not work!

    uname -svr => Linux 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021
    

    Also, ffmpeg return each frame per second, isn't a static .txt file.

    Thank you.

  • Rotating videos with FFmpeg

    23 September, by jocull

    I have been trying to figure out how to rotate videos with FFmpeg. I am working with iPhone videos taken in portrait mode. I know how to determine the current degrees of rotation using MediaInfo (excellent library, btw) but I'm stuck on FFmpeg now.

    From what I've read, what you need to use is a vfilter option. According to what I see, it should look like this:

    ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4
    

    However, I can't get this to work. First, -vfilters doesn't exist anymore, it's now just -vf. Second, I get this error:

    No such filter: 'rotate'
    Error opening filters!
    

    As far as I know, I have an all-options-on build of FFmpeg. Running ffmpeg -filters shows this:

    Filters:
    anull            Pass the source unchanged to the output.
    aspect           Set the frame aspect ratio.
    crop             Crop the input video to x:y:width:height.
    fifo             Buffer input images and send them when they are requested.
    format           Convert the input video to one of the specified pixel formats.
    hflip            Horizontally flip the input video.
    noformat         Force libavfilter not to use any of the specified pixel formats
     for the input to the next filter.
    null             Pass the source unchanged to the output.
    pad              Pad input image to width:height[:x:y[:color]] (default x and y:
     0, default color: black).
    pixdesctest      Test pixel format definitions.
    pixelaspect      Set the pixel aspect ratio.
    scale            Scale the input video to width:height size and/or convert the i
    mage format.
    slicify          Pass the images of input video on to next video filter as multi
    ple slices.
    unsharp          Sharpen or blur the input video.
    vflip            Flip the input video vertically.
    buffer           Buffer video frames, and make them accessible to the filterchai
    n.
    color            Provide an uniformly colored input, syntax is: [color[:size[:ra
    te]]]
    nullsrc          Null video source, never return images.
    nullsink         Do absolutely nothing with the input video.
    

    Having the options for vflip and hflip are great and all, but they just won't get me where I need to go. I need to the ability to rotate videos 90 degrees at the very least. 270 degrees would be an excellent option to have as well. Where have the rotate options gone?

  • Video editing in UWP apps

    23 September, by MatS2510

    I'm creating an video downloading app in C# and Universal Windows Platform. App downloads movies in three different file sets depending on the source:

    • .ts audio & video file
    • .mp4 only video file and .webm only audio file
    • .mp4 audio & video file The video lenghts, on which I tested the app, range from a few seconds to several hours. Video qualities are standard YouTube qualities.

    The next step is video editing. User can specify start and end trimming timestamp. Video can be saved in three different modes:

    • Audio & Video
    • Only audio
    • Only video

    This is where the problem begins.

    I can't use FFmpeg as executable, because UWP framework doesn't allow to run external app.

    So I tried to use Windows.Media.Editing library. It works fine with all .mp4 audio & video files and some .ts files (but only with short videos up to an hour). Other cases throws two types of exceptions:

    • System.Exception HResult=0xC00DA7FC Message=Stream is not in a state to handle the request. Stream is not in a state to handle the request. Source=System.Private.CoreLib
    • System.Exception HResult=0xC00D6D60 Message=A valid type has not been set for this stream or a stream that it depends on. (Exception from HRESULT: 0xC00D6D60) Source=System.Private.CoreLib

    I wrote a separate question about it: Exception when rendering a video in UWP . Here is also a link to an example (In comments with sample videos, which causes an error. Link to github repository.) that downloads and tries to convert the .ts file to the .mp4 file.

    So I decided to try the most complicated solution. I created a C++ DLL project and set build output destination to the new folder in the main app project folder (and set this folder to copy to build output directory). I installed an ffmpeg libraries by vcpkg and imported them in C++ project. Here is the .cpp file:

    #include "pch.h"
    #include "mux.h"
    
    extern "C" {
        #include "libavformat/avformat.h"
    }
    
    int test() {
        av_register_all();
        return 0;
    }
    

    Here is the header:

    #pragma once
    
    #ifdef FFMPEGLIB_EXPORTS
    #define FFMPEGLIB_API __declspec(dllexport)
    #else
    #define FFMPEGLIB_API __declspec(dllimport)
    #endif
    
    extern "C" FFMPEGLIB_API int test();
    

    And here is the C# class where is imported C++ function:

    class FFmpeg
    {
        [DllImport(@"FFmpeg\FFmpegLib.dll")] private static extern int test();
    
        public static void Test()
        {
            test();
        }
    }
    

    But calling an Test() void throws an error: System.DllNotFoundException: 'Unable to load DLL 'FFmpeg\FFmpegLib.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

    There are also ffmpeg libraries (avcodec-58.dll, avformat-58.dll, avutil-56.dll, swresample-3.dll) in FFmpeg folder. I also tried to import avformat-58.dll directly in C# (main app project) and call av_register_all() function, but it throws the same exception. I also checked if I could include "libavformat/avformat.h" in C++ UWP app, but it shows error "cannot open source file "libavformat/avformat.h"". I guess that C libraries are incompatible with UWP, but I'm not sure.

    I have no more ideas. If it is not possible to use the methods I have mentioned, my question is Are there any other ways to process videos in UWP app?