Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Which filter should be used when i want to add watermark to a video ?

    28 mai 2013, par Blade Master

    Hi everyone,

    I want to add a watermark to a video use a picture. here is the problem enter image description here

    and this is my command:

    c:\ffmpeg.exe -y -i c:\ffmpeg\input\walk.mp4 -acodec copy -b 300k -vf "movie=w1.jpg [watermark];[in][watermark] overlay=5:5 [out]" c:\ffmpeg\output\walk.mp4

    What am I doing wrong?

  • FFmpeg : Generating .ts files and adding Metadata to them [closed]

    28 mai 2013, par Jonovono

    Before I was following the steps:

    1. Create some metadata:

      id3taggenerator -o 1.id3 -artist "Emma Stone"
      id3taggenerator -o 2.id3 -artist "Patricia Clarkson"
      
    2. Create a file saying where to place the metadata in the file:

      68 id3 /path/to/file/1.id3
      78 id3 /path/to/file/2.id3
      
    3. Segment the files and include the metadata

      mediafilesegmenter -f video -M meta.txt video.mp4
      

    More detail:

    http://jmacmullin.wordpress.com/2010/11/03/adding-meta-data-to-video-in-ios/

    I want to do something similar to this, but with FFmpeg.

    I am also wondering if I could first segment the file into .ts files and add metadata directly to those?

    I am having trouble finding the solution on the website. Any help or resources would be great. Thanks!

  • catch percentage File conversion ffmpeg

    28 mai 2013, par offboard

    I've been thinking about implementing a new function on my system. so I thought to show the state of the file conversion. I thought of a logic to it. updating table from the database according to the percentage of file conversion.

    <?
    exec('ffmpeg -i p17prdvj251lk11d3v12ntijfq2u1.mp4 -vf scale=-1:360 -c:v libx264 -preset ultrafast output.flv');
    for($i = 0; $i <= 1; $i++){
        mysql_query("UPDATE progress SET pss='".$i."' WHERE id='1'");
    }
    

    the problem is that I do not know if it's possible to get the percentage. I thought about using the extension of ffmpeg and create a function to convert the files but do not know if it will work

  • Improper use of system() call ?

    28 mai 2013, par Dima1982

    I have a particle system program that generates a .dat file with particle coordinates in every iteration. The end goal is to run the program multiple times via a script with different parameters. So, I am trying to setup my program in a way that, for every run, all relevant data are going to be stored in a folder.

    What I do is to generate PNGs from the .dat files with Gnuplot, call ffmpeg to create a video out of the PNGs, use WinRAR to compress the .dat files and finally clean up, by deleting all the intermediate files. This works, when I do it in the working directory.

    Now I try to create a new directory and do the same stuff in there. My code:

    // Load the proper library to use chdir() function
    #ifdef _WIN32
    #include 
    #elif defined __linux__ || defined __APPLE__&&__MACH__
    #include 
    #endif
    
    // Make output directory and change working directory to new directory
        ostringstream dirCommand;
        dirCommand << "mkdir " << folderName_str;
        system(dirCommand.str().c_str());
        const char* test  = folderName_str.c_str();
        #ifdef _WIN32
            if(_chdir(test))
            {
                printf( "Unable to locate the directory: %s\n",test);
                return;
            }
        #elif defined __linux__ || defined __APPLE__&&__MACH__
            if(chdir(test))
            {
                printf( "Unable to locate the directory: %s\n",test);
                return;
            }
        #endif
            else
                printf("Created output directory...\n");
    

    Already for this part, I know that there are going to be objections. I have looked extensively on SO and many people favor SetCurrentDirectory() for Windows, or they are skeptical about using system(). In my defense, I am a novice programmer and my knowledge is really limited...

    Now, when I try to make the video with FFMpeg and then rar/tar my files:

    // Make video
            std::cout << "Generating Video..." << endl;
            ostringstream command;
            command << "ffmpeg -f image2 -r 1/0.1 -i output_%01d.png -vcodec mpeg4 " << videoName_str << ".avi -loglevel quiet";
            std::system(command.str().c_str());
    
            // Clean Up!
            std::cout << "Cleaning up!" << endl;
            ostringstream command2;
            #ifdef _WIN32
                command2 << "rar -inul a " << videoName_str << ".rar *.dat settings.gp loadfile.gp";
            #elif defined __linux__ || defined __APPLE__&&__MACH__
                command2 << "tar cf " << videoName_str << ".tar *.dat settings.gp loadfile.gp";
            #endif
            std::system(command2.str().c_str());
    

    I get very different behaviors in Win/ Linux.

    Win 7 x64, Visual Studio 2010/12

    In windows, the folder is created. The .dat files are generated correctly and gnuplot plots the PNGs as well. When ffmpeg is called, nothing happens. No error message from FFMpeg or anything. The same goes for WinRAR. Maybe, for the last thing, I can use the command line utility of 7z which is free!

    Linux Mint 14 x64, Qt 4.8.1

    Strangely enough, the behavior is inverted from that of Windows. As soon as the dir is changed, only the first .dat file is generated. It is as if every subsequent call I make to fprintf() for my file generation does not work, or gets lost somewhere. Gnuplot works, as do ffmpeg and tar!!

    I am really perplexed. Any help, would be really appreciated.

  • FFMPEG Muxing from Audio and Video files.(C++)

    27 mai 2013, par Michael IV

    I am learning how to create MP4 video from this example.The problem is that the example demonstrates audio encoding from some dummy source data generated on the fly.I need to encode audio from a file.I have checked many examples and most of them show the same or just a separate audio encoding. In my trial and error process I am using the same AVFormatContext for both audio and video frames.I am not sure if it's right thing to do, or should I rather have 2 separate contexts?So far I got Video encoding ok but audio stream fails as AVPacket can't locate correct audio stream index. Here is how I setup audio stream:

      void open_audio(AVFormatContext *oc, AVCodec **codec, AVStream **st ,enum AVCodecID codec_id){
    
        //    AVCodecContext *c;
        int ret;
        //    c = st->codec;
    
        *codec = avcodec_find_encoder(codec_id);
        if (!(*codec)) {
            fprintf(stderr, "Could not find encoder for '%s'\n",avcodec_get_name(codec_id));
    
        }
        /* open it */
    
    
    
        if(avformat_open_input(&oc,_audioInName.c_str(),NULL,NULL) !=0){
    
            Msg::PrintErrorMsg("Error opening audio file");
    
        }
    
    
        AVStream* audioStream = NULL;
    
        // Find the audio stream (some container files can have multiple streams in them)
    
        for (uint32_t i = 0; i < oc->nb_streams; ++i)
    
        {
    
            if (oc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
    
            {
    
                audioStream = oc->streams[i];
    
                break;
    
            }
    
        }
    
        if (audioStream == NULL)
        {
            Msg::PrintErrorMsg("Could not find any audio stream in the file");
    
        }
        *st =audioStream;
    
        AVCodecContext *c  = audioStream->codec;
        c->codec = *codec;//avcodec_find_decoder(c->codec_id);
        audioStream->id = 1;
        c->sample_fmt  = AV_SAMPLE_FMT_S16;
        c->bit_rate    = 64000;
        c->sample_rate = 44100;
        c->channels    = 1;
    
        if (oc->oformat->flags & AVFMT_GLOBALHEADER){
            c->flags |= CODEC_FLAG_GLOBAL_HEADER;
    
        }
    
        if (c->codec == NULL)
        {
            Msg::PrintErrorMsg("Couldn't find a proper decoder");
    
        }
    
        ret = avcodec_open2(c, *codec, NULL);
        if (ret < 0) {
    
            Msg::PrintErrorMsg("Could not open audio codec\n");
    
        }
    
    }
    

    Here "oc" is the same context used to initialize video stream as well.

    Then I am trying to write audio frame like this:

      void write_audio_frame(AVFormatContext *oc, AVStream *st){
        AVCodecContext *c;
        AVPacket pkt = { 0 }; // data and size must be 0;
        AVFrame *frame = avcodec_alloc_frame();
        int got_packet, ret;
        av_init_packet(&pkt);
        c = st->codec;
        /////
        //  get_audio_frame(samples, audio_input_frame_size, c->channels);
    
        ////Read the packet:
        while(av_read_frame(oc,&pkt) == 0 ){
    
            if(pkt.stream_index ==st->index){
    
            // Try to decode the packet into a frame
            int frameFinished = 0;
            avcodec_decode_audio4(c, frame, &frameFinished, &pkt);
    
            // Some frames rely on multiple packets, so we have to make sure the frame is finished before
            // we can use it
            if (frameFinished){
                assert(frameFinished);
                ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
                if (ret < 0) {
                    Msg::PrintErrorMsg("Error encoding audio frame\n");
    
                }
                if (!got_packet){
                    printf("failed to aquire packet");
                }
                pkt.stream_index = st->index;
                /* Write the compressed frame to the media file. */
                ret = av_interleaved_write_frame(oc, &pkt);
                if (ret != 0) {
    
                    Msg::PrintErrorMsg("Error while writing audio frame.");
                }
    
              }
            }
    
           }
        }
        av_free_packet(&pkt);
        avcodec_free_frame(&frame);
    }
    

    The thing is I never pass this statement: "if(pkt.stream_index ==st->index)".Packet stream index is never equal to the audio stream index.Anyone can point out where I am wrong?