Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Can I use ffmpeg to change 360 video projection ?

    29 janvier 2016, par Guig

    I want to convert 360 videos from equirectangular to cubic projection. Does ffmpeg supports that? Else, what's the best approach?

  • Building my JAVA parameter array for FFMPEG

    29 janvier 2016, par user3541092

    FFmpeg Version: N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)

    Machine: Amazon Linux t2.micro (free tier)

    Sample File: sample_iTunes.mov
    Sample File URL: https://support.apple.com/en-us/HT201549

    I'm trying to replicate the following FFmpeg command, using a string array and then pass this array into the Runtime.getRuntime().exec().

    ffmpeg -i file:/var/local/ffmpegtest/media_input/sample_iTunes.mov -pix_fmt yuv420p -c:v libx264 -vtag mp42 -metadata major_brand="mp42" -b:v 8000k -minrate 8000k -maxrate 10000k -ac 2 -strict experimental -c:a aac -b:a 256k -metadata:s:a:0 handler="Stereo" /var/local/ffmpegtest/media_output/sample_iTunes.mp4 -y
    

    NOTE: This works when I pass the full command, as a single string into Runtime.getRuntime().exec().

        String _cmd = "ffmpeg -i %s -pix_fmt yuv420p -c:v libx264 -vtag mp42 -metadata major_brand=\"mp42\" "
                + "-b:v 8000k -minrate 8000k -maxrate 10000k -ac 2 -strict experimental -c:a aac -b:a 256k -metadata:s:a:0 handler=\"Stereo\" %s -y";
        String _ffmpegCommand = String.format(_cmd, _inputFile, _outPutFile);
        p = Runtime.getRuntime().exec(_ffmpegCommand);
        BufferedReader _reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
        String _line = null;
    
        while((_line = _reader.readLine()) != null) {
            lw.writeLine(_logPath + _logName, _line);
            System.out.println(_line);
        }
    

    I started out with just a basic parameter list. As I add add each additional parameter, I re-build the JAR file and upload it to my EC2 instance to test for any errors.

    The following string array works:

    try
            {
                String[] _params = {"ffmpeg",
                           "-i",
                           String.format("%s", _inputFile),
                           "-pix_fmt",
                           "yuv420p",
                           "-c:v",
                           "libx264",
                           String.format("%s", _outPutFile),
                           "-y"};
    
                p = Runtime.getRuntime().exec(_params);
    
                BufferedReader _reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
                String _line = null;
    
                while((_line = _reader.readLine()) != null) {
                    lw.writeLine(_logPath + _logName, _line);
                    System.out.println(_line);
                }
            }
            catch (Exception e) {
                BufferedReader _reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
                String _line = null;
    
                while((_line = _reader.readLine()) != null) {
                    lw.writeLine(_logPath + _logName, _line);
                    System.out.println(_line);
                }
    
            }
    

    However, when I continue to build the array with additional parameters, I begin to experience problems (lets add -vtag mp42):

    try
            {
                String[] _params = {"ffmpeg",
                           "-i",
                           String.format("%s", _inputFile),
                           "-pix_fmt",
                           "yuv420p",
                           "-c:v",
                           "libx264",
                           "-vtag", // <---- New
                           "mp42", // <---  New
                           String.format("%s", _outPutFile),
                           "-y"};
    
                p = Runtime.getRuntime().exec(_params);
    
                BufferedReader _reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
                String _line = null;
    
                while((_line = _reader.readLine()) != null) {
                    lw.writeLine(_logPath + _logName, _line);
                    System.out.println(_line);
                }
            }
            catch (Exception e) {
                BufferedReader _reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
                String _line = null;
    
                while((_line = _reader.readLine()) != null) {
                    lw.writeLine(_logPath + _logName, _line);
                    System.out.println(_line);
                }
    
            }
    

    Error Message: Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input

    Full Log output for errant trail run:

    29 Jan 2016 03:45:09 UTC - Running FFMpeg...
    29 Jan 2016 03:45:09 UTC -  Input file: /var/local/ffmpegtest/media_input/sample_iTunes.mov
    29 Jan 2016 03:45:09 UTC -  Output file: /var/local/ffmpegtest/media_output/sample_iTunes.mp4
    29 Jan 2016 03:45:09 UTC - ffmpeg version N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers
    29 Jan 2016 03:45:09 UTC -   built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)
    29 Jan 2016 03:45:09 UTC -   configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
    29 Jan 2016 03:45:09 UTC -   libavutil      52. 89.100 / 52. 89.100
    29 Jan 2016 03:45:09 UTC -   libavcodec     55. 66.101 / 55. 66.101
    29 Jan 2016 03:45:09 UTC -   libavformat    55. 43.100 / 55. 43.100
    29 Jan 2016 03:45:09 UTC -   libavdevice    55. 13.101 / 55. 13.101
    29 Jan 2016 03:45:09 UTC -   libavfilter     4.  8.100 /  4.  8.100
    29 Jan 2016 03:45:09 UTC -   libswscale      2.  6.100 /  2.  6.100
    29 Jan 2016 03:45:09 UTC -   libswresample   0. 19.100 /  0. 19.100
    29 Jan 2016 03:45:09 UTC -   libpostproc    52.  3.100 / 52.  3.100
    29 Jan 2016 03:45:09 UTC - Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/local/ffmpegtest/media_input/sample_iTunes.mov':
    29 Jan 2016 03:45:09 UTC -   Metadata:
    29 Jan 2016 03:45:09 UTC -     major_brand     : qt  
    29 Jan 2016 03:45:09 UTC -     minor_version   : 537199360
    29 Jan 2016 03:45:09 UTC -     compatible_brands: qt  
    29 Jan 2016 03:45:09 UTC -     creation_time   : 2005-10-17 22:54:32
    29 Jan 2016 03:45:09 UTC -   Duration: 00:01:25.50, start: 0.000000, bitrate: 307 kb/s
    29 Jan 2016 03:45:09 UTC -     Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 261 kb/s, 10 fps, 10 tbr, 3k tbn, 25 tbc (default)
    29 Jan 2016 03:45:09 UTC -     Metadata:
    29 Jan 2016 03:45:09 UTC -       creation_time   : 2005-10-17 22:54:33
    29 Jan 2016 03:45:09 UTC -       handler_name    : Apple Video Media Handler
    29 Jan 2016 03:45:09 UTC -       encoder         : 3ivx D4 4.5.1
    29 Jan 2016 03:45:09 UTC -     Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 43 kb/s (default)
    29 Jan 2016 03:45:09 UTC -     Metadata:
    29 Jan 2016 03:45:09 UTC -       creation_time   : 2005-10-17 22:54:34
    29 Jan 2016 03:45:09 UTC -       handler_name    : Apple Sound Media Handler
    29 Jan 2016 03:45:09 UTC - [libx264 @ 0x30c2c00] using SAR=1/1
    29 Jan 2016 03:45:09 UTC - [libx264 @ 0x30c2c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX AVX2 FMA3 BMI1 BMI2
    29 Jan 2016 03:45:09 UTC - [libx264 @ 0x30c2c00] profile High, level 2.2
    29 Jan 2016 03:45:09 UTC - [libx264 @ 0x30c2c00] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    29 Jan 2016 03:45:09 UTC - [mp4 @ 0x30c21a0] Tag mp42/0x3234706d incompatible with output codec id '28' ([33][0][0][0])
    29 Jan 2016 03:45:09 UTC - Output #0, mp4, to '/var/local/ffmpegtest/media_output/sample_iTunes.mp4':
    29 Jan 2016 03:45:09 UTC -   Metadata:
    29 Jan 2016 03:45:09 UTC -     major_brand     : qt  
    29 Jan 2016 03:45:09 UTC -     minor_version   : 537199360
    29 Jan 2016 03:45:09 UTC -     compatible_brands: qt  
    29 Jan 2016 03:45:09 UTC -     Stream #0:0(eng): Video: h264 (libx264) (mp42 / 0x3234706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 10 fps, 90k tbn, 10 tbc (default)
    29 Jan 2016 03:45:09 UTC -     Metadata:
    29 Jan 2016 03:45:09 UTC -       creation_time   : 2005-10-17 22:54:33
    29 Jan 2016 03:45:09 UTC -       handler_name    : Apple Video Media Handler
    29 Jan 2016 03:45:09 UTC -       encoder         : Lavc55.66.101 libx264
    29 Jan 2016 03:45:09 UTC -     Stream #0:1(eng): Audio: aac (libvo_aacenc), 32000 Hz, mono, s16, 128 kb/s (default)
    29 Jan 2016 03:45:09 UTC -     Metadata:
    29 Jan 2016 03:45:09 UTC -       creation_time   : 2005-10-17 22:54:34
    29 Jan 2016 03:45:09 UTC -       handler_name    : Apple Sound Media Handler
    29 Jan 2016 03:45:09 UTC -       encoder         : Lavc55.66.101 libvo_aacenc
    29 Jan 2016 03:45:09 UTC - Stream mapping:
    29 Jan 2016 03:45:09 UTC -   Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))
    29 Jan 2016 03:45:09 UTC -   Stream #0:1 -> #0:1 (aac (native) -> aac (libvo_aacenc))
    29 Jan 2016 03:45:09 UTC - Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
    
  • FFMpeg image sequence to video using VP9 encoder [migrated]

    29 janvier 2016, par user778968

    I'm trying to transcode mp4 to webm format in a lossless way. I tried two ways to do that.

    For that purpose, I extracted mp4 video to image sequences (png). Then, I converted image sequence(without changing any frame) to webm video with a lossless flag. But, when i extract webm video to image sequences and compared with the images that i extracted from mp4 video, i realized that PSNR values were not infinity. It changes from between around 53-55 dB.

    On the other hand, I directly transcoded mp4 to webm with a lossless flag. Then, I extracted image sequences from mp4 and webm format and compared PSNR values. This time i realized that PSNR values are infinity.

    Encoding image sequences to webm video with lossless flag is not actually lossless. Is this true or am i doing something wrong?

  • What is the point of encrypting HLS files ?

    29 janvier 2016, par APITC

    I am currently working on a project of videos on demand where I convert videos to HLS using FFMPEG.

    Videos are publicly hosted on AWS S3 and there is an API giving the URL of the HLS playlist.

    Now, I was looking at encrypting HLS files with AES-128 so that people can't download and watch the video offline. I found the procedure which consists in hosting the key online and using that key while converting the video to encrypt the segments.

    The URL of the key is written in the HLS playlist, and the file is publicly available online.

    So anyone has access to the encryption key.

    I don't understand what is the point of encrypting the segments if anyone has access to the key.

    Can someone enlighten me? I know I must be missing something. Thanks!

  • How to encode a video from several images generated in a C++ program without writing the separate frame images to disk ?

    29 janvier 2016, par ksb496

    I am writing a C++ code where a sequence of N different frames is generated after performing some operations implemented therein. After each frame is completed, I write it on the disk as IMG_%d.png, and finally I encode them to a video through ffmpeg using the x264 codec.

    The summarized pseudocode of the main part of the program is the following one:

    std::vector B(width*height*3);
    for (i=0; i/ void generateframe(std::vector &, int)
      generateframe(B, i); // Returns different images for different i values.
      sprintf(s, "IMG_%d.png", i+1);
      WriteToDisk(B, s); // void WriteToDisk(std::vector, char[])
    }
    

    The problem of this implementation is that the number of desired frames, N, is usually high (N~100000) as well as the resolution of the pictures (1920x1080), resulting into an overload of the disk, producing write cycles of dozens of GB after each execution.

    In order to avoid this, I have been trying to find documentation about parsing directly each image stored in the vector B to an encoder such as x264 (without having to write the intermediate image files to the disk). Albeit some interesting topics were found, none of them solved specifically what I exactly want to, as many of them concern the execution of the encoder with existing images files on the disk, whilst others provide solutions for other programming languages such as Python (here you can find a fully satisfactory solution for that platform).

    The pseudocode of what I would like to obtain is something similar to this:

    std::vector B(width*height*3);
    video_file=open_video("Generated_Video.mp4", ...[encoder options]...);
    for (i=0; icode>

    According to what I have read on related topics, the x264 C++ API might be able to do this, but, as stated above, I did not find a satisfactory answer for my specific question. I tried learning and using directly the ffmpeg source code, but both its low ease of use and compilation issues forced me to discard this possibility as a mere non-professional programmer I am (I take it as just as a hobby and unluckily I cannot waste that many time learning something so demanding).

    Another possible solution that came to my mind is to find a way to call the ffmpeg binary file in the C++ code, and somehow manage to transfer the image data of each iteration (stored in B) to the encoder, letting the addition of each frame (that is, not "closing" the video file to write) until the last frame, so that more frames can be added until reaching the N-th one, where the video file will be "closed". In other words, call ffmpeg.exe through the C++ program to write the first frame to a video, but make the encoder "wait" for more frames. Then call again ffmpeg to add the second frame and make the encoder "wait" again for more frames, and so on until reaching the last frame, where the video will be finished. However, I do not know how to proceed or if it is actually possible.

    Edit 1:

    As suggested in the replies, I have been documenting about named pipes and tried to use them in my code. First of all, it should be remarked that I am working with Cygwin, so my named pipes are created as they would be created under Linux. The modified pseudocode I used (including the corresponding system libraries) is the following one:

    FILE *fd;
    mkfifo("myfifo", 0666);
    
    for (i=0; i/ void WriteToPipe(std::vector, FILE *&fd)
      fflush(fd);
      fd=fclose("myfifo");
    }
    unlink("myfifo");
    

    WriteToPipe is a slight modification of the previous WriteToFile function, where I made sure that the write buffer to send the image data is small enough to fit the pipe buffering limitations.

    Then I compile and write the following command in the Cygwin terminal:

    ./myprogram | ffmpeg -i pipe:myfifo -c:v libx264 -preset slow -crf 20 Video.mp4
    

    However, it remains stuck at the loop when i=0 at the "fopen" line (that is, the first fopen call). If I had not called ffmpeg it would be natural as the server (my program) would be waiting for a client program to connect to the "other side" of the pipe, but it is not the case. It looks like they cannot be connected through the pipe somehow, but I have not been able to find further documentation in order to overcome this issue. Any suggestion?