Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to create overlay image advanced transition on FFMpeg

    22 janvier 2019, par Piyush Softpulse

    How to overlay image transition in ffmpeg. Any idea please help out. and also some demo for ffmpeg.

    Like this Example : https://youtu.be/WUuk4fkjz58

  • UDP Networking - SO_REUSEADDR and select failing on Windows

    22 janvier 2019, par Luca

    I'm trying to set up multiple instances of FFMpeg for receiving a MPEG 2 TS stream. Both application setup the SO_REUSEADDR socket option.

    The UDP socket bind is successful, but only the first FFMpeg instance is actually receiving. As soon as the receiving instance is closed, the second instance starts receiving.

    I've set up a unit test demonstrating the actual FFMpeg behavior, extracting the actual system calls executed. The test is failing because the select call does not detect an I/O event on the second socket.

    What prevents the second socket to receive the datagram?

    Note: this is a Google Test test. Just replace the TEST macro with a main function to get it working.

    #include 
    #include 
    
    #pragma comment(lib, "ws2_32.lib")
    
    typedef unsigned long nfds_t;
    
    int FFMPEGSocket_CreateSocketTx()
    {
        return socket(AF_INET, SOCK_DGRAM, 0);
    }
    
    int FFMPEGSocket_CreateSocket()
    {
        // Create socket
        int fd = socket(AF_INET, SOCK_DGRAM, 0);
    
        EXPECT_GT(fd, 0);
    
        // Set SO_REUSEADDR
        int reuse_socket = 1;
    
        EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_socket, sizeof(reuse_socket)), 0);
    
        // Bind
        struct sockaddr_in udpService;
    
        udpService.sin_family = AF_INET;
        udpService.sin_addr.s_addr = htonl(INADDR_ANY);
        udpService.sin_port = htons(4609);
    
        EXPECT_EQ(::bind(fd, (SOCKADDR*)&udpService, sizeof(udpService)), 0);
    
        // Set non blocking IO
        u_long param = 1;
    
        EXPECT_EQ(ioctlsocket(fd, FIONBIO, &param), 0);
    
        return fd;
    }
    
    void FFMPEGSocket_CloseSocket(int fd)
    {
        closesocket(fd);
    }
    
    int FFMPEGSocket_Pool(struct pollfd *fds, nfds_t numfds, int timeout)
    {
        fd_set read_set;
        fd_set write_set;
        fd_set exception_set;
        nfds_t i;
        int n = 0;
        int rc;
    
        FD_ZERO(&read_set);
        FD_ZERO(&write_set);
        FD_ZERO(&exception_set);
    
        for (int i = 0; i < numfds; i++) {
            if (fds[i].events & POLLIN)
                FD_SET(fds[i].fd, &read_set);
            if (fds[i].events & POLLOUT)
                FD_SET(fds[i].fd, &write_set);
            if (fds[i].events & POLLERR)
                FD_SET(fds[i].fd, &exception_set);
    
            if (fds[i].fd >= n)
                n = fds[i].fd + 1;
        }
    
        timeval tv;
        tv.tv_sec = 100 / 1000;
        tv.tv_usec = 1000 * (100 % 1000);
        rc = select(n, &read_set, &write_set, &exception_set, &tv);
    
        for (int i = 0; i < numfds; i++) {
            fds[i].revents = 0;
    
            if (FD_ISSET(fds[i].fd, &read_set))
                fds[i].revents |= POLLIN;
            if (FD_ISSET(fds[i].fd, &write_set))
                fds[i].revents |= POLLOUT;
            if (FD_ISSET(fds[i].fd, &exception_set))
                fds[i].revents |= POLLERR;
        }
    
        return rc;
    }
    
    TEST(FFMPEGSocket, PosixReuseAddr)
    {
        WSADATA wsaData;
    
        // Initialize network layer
        std::memset(&wsaData, 0, sizeof(wsaData));
        WSAStartup(MAKEWORD(2, 2), &wsaData);
    
        // Create two receiving sockets
        int fd1 = FFMPEGSocket_CreateSocket();
        int fd2 = FFMPEGSocket_CreateSocket();
        int fdtx = FFMPEGSocket_CreateSocketTx();
    
        // Read loop
        int ev = POLLIN;
        struct pollfd p1 = { fd1, ev, 0 };
        struct pollfd p2 = { fd2, ev, 0 };
    
        bool p1event = false, p2event = false;
        char datagram[32] = { 0 };
    
        for (int i = 0; (i < 10) && (!p1event || !p2event); i++) {
            {   // Transmit a single datagram
                struct sockaddr_in udpService;
    
                udpService.sin_family = AF_INET;
                udpService.sin_addr.s_addr = htonl(0x7F000001);
                udpService.sin_port = htons(4609);
    
                sendto(fdtx, datagram, 32, 0, (const sockaddr*)&udpService, sizeof(udpService));
            }
    
            // Receive
            struct pollfd fds[2] = { p1, p2 };
    
            if (FFMPEGSocket_Pool(fds, 2, 1000) < 0)
                break;      // Fail
    
            if (fds[0].revents & POLLIN)
                p1event = true;
            if (fds[1].revents & POLLIN)
                p2event = true;
        }
    
        EXPECT_TRUE(p1event);
        EXPECT_TRUE(p2event);
    
        FFMPEGSocket_CloseSocket(fd1);
        FFMPEGSocket_CloseSocket(fd2);
    
        // Shutdown network layer
        WSACleanup();
    }
    
  • ffmpeg works from terminal but not by php script

    22 janvier 2019, par Naman Tamrakar

    I have to get the thumbnail image of video i am using the ffmpeg. On my server i run the ffmpeg command from ssh then it is working but from the php exec function it is not working it gives the error /usr/bin/ffmpeg : no such file or dirctory but the ffmpeg is installed on this location usr/bin/ffmpeg. my source code is:

    $ffmpeg = '/usr/bin/ffmpeg';
    
    $videoname = 'myvideo.mp4';
    
    $video = $_SERVER['DOCUMENT_ROOT'].'/uploads/videos/'.$videoname;
    
    $image = $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/thumb.jpg';
    
    $second = 1;
    
    $cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
    
    exec($cmd);
    

    Please provide any solution.

  • using ffmpeg in Azure function to cut files using c#

    22 janvier 2019, par abhishekmoondra1989

    I have written an Azure function in C# which will cut a big mp4 files into some small duration. I have copied everything that is required (ffmpeg executeable, video file) in home directory via KUDU console. But when I run the the function it runs for more than 5 minutes and it doesn't give any files in the home directory.

    Function :

    using System;
    using System.Diagnostics;
    
    public static void Run(string input, TraceWriter log)
    {
        log.Info("Executing");
        using (var process = new Process())
        {
            process.StartInfo.FileName = @"D:\home\ffmpeg.exe";
            process.StartInfo.Arguments = @"-i D:\home\AmnestyInternational.mp4 -ss 00:00:03 -t 00:00:08 -async 1 D:\home\cut.mp4";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            log.Info(Directory.GetCurrentDirectory());
            log.Info("Cutting starts:"+DateTime.Now.ToString("h:mm:ss tt"));
            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            log.Info("Cutting ends :"+DateTime.Now.ToString("h:mm:ss tt"));
            log.Info(output);
        }
    }
    

    Output seen on Azure function Console:

    2017-03-24T11:06:00.705 Function started (Id=df082f54-719a-415f-b7f1-b10548a213be)
    2017-03-24T11:06:00.721 Executing
    2017-03-24T11:06:00.721 D:\Windows\system32
    2017-03-24T11:06:00.721 Cutting start :11:06:00 AM
    2017-03-24T11:07:14  No new trace in the past 1 min(s).
    2017-03-24T11:08:14  No new trace in the past 2 min(s).
    2017-03-24T11:09:14  No new trace in the past 3 min(s).
    2017-03-24T11:10:14  No new trace in the past 4 min(s).
    2017-03-24T11:11:00.758 Microsoft.Azure.WebJobs.Host: Timeout value of 00:05:00 was exceeded by function: Functions.ManualTriggerCSharp1.
    

    When I try to execute this same command on KUDU console or my own PC it only take 1.5 mins and I get a file of the desired duration

    Could anyone please help me with this? What I might be missing?

  • ffmpeg output doesn't play on multiple devices

    22 janvier 2019, par jchaykow

    I have read the other stackoverflow posts regarding this topic so I am fairly certain this is not exact duplicate.

    ffmpeg exports a video that seems to only play on select players. I want to export a video that plays on iphone/mac/general players. I have seen the suggestions for the -pix_fmt yuv420p tag but this does not seem to work anymore - I read that Mac has since changed their systems that makes it not compatible anymore.

    I am running:

    ffmpeg -start_number 1 -framerate 4 -pix_fmt yuv420p -i screen%01d.png output.mp4
    

    This all works fine and I can see the video by doing:

    ffplay output.mp4
    

    But I would like to be able to transfer this to mobile or general playback, any way to do this, ideally using ffmpeg? I'd rather not use two tools to do 1 job.


    • Works on gmail
    • Doesn't work on QuickTime Player
    • Doesn't work on Flip Player
    • Doesn't work on iPhone