Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Buffering and writing video from rtsp to file

    31 juillet 2017, par gogoer

    I need to get rtsp stream from IP-cam and write it to file. Program check the state of two flags: "start" and "stop". My program needs to write video from IP-cam to 10 sec buffer. When flag "start" is on, i need to write video from buffer to file and start to record video to file directly. When flag "stop" becomes on, i need to write to file 10 sec more and close file. Then program goes to beginning (writes video to buffer).

    Program works, but i have problems with first 10 sec (from buffer) and last 10 sec. Video freezes or just black. Please help me with properly buffering video and combining buffered part, main part and after part to one file.

    Here is my code:

    int main( int argc, char* argv[] )
    {
    
    
        while(error_flag==0){
    
            //no flags, write video to buffer
            if(start_flag==0 && stop_flag==0){
    
                printf("writing bufer, no command\n");
    
                av_init_packet( &pkt );
                while ( av_read_frame( ifcx, &pkt ) >= 0 && start_flag==0 && stop_flag==0){
    
                    if ( pkt.stream_index == i_index ) {
    
                        pkt.stream_index = ost->id;
                        pkt.pts = av_rescale_q_rnd(pkt.pts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.dts = av_rescale_q_rnd(pkt.dts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);
                        pkt.pos = -1;
    
                        av_copy_packet(&pkt_arr[0],&pkt);
    
                        printf("writing block to section: %i\n", pkg_index);
    
    
                    }
    
                    av_free_packet( &pkt );
                    av_init_packet( &pkt );
                    pkg_index++;
    
                    if(pkg_index>=bufer_size){
                        pkg_index=pkg_index-bufer_size;
                    }
                }
            }
    
            //command 'start' comes
            if(start_flag==1){
    
                printf("command start comes \n");
                //if buffer data is not writed to file
                if(bufer_writed==0){
                    printf("writing bufer to file \n");
                //writing data to file
                    int i;
                    for(i=0; i=bufer_size){
                            pkg_index=pkg_index-bufer_size;
                        }
                    }
                    printf("writed bufer to file \n");
                    //after writing buffer to file bufer_writed flag is ON.
                    bufer_writed=1;
                }
    
                printf("starting write to file from cam \n");
                //now we start to write packets direct to file
                av_init_packet( &pkt );
                while ( av_read_frame( ifcx, &pkt ) >= 0 && stop_flag==0){
                    if ( pkt.stream_index == i_index ) {
    
                        pkt.stream_index = ost->id;
                        pkt.pts = av_rescale_q_rnd(pkt.pts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.dts = av_rescale_q_rnd(pkt.dts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);
                        pkt.pos = -1;
    
                        printf("writing to file from cam \n");
    
                        av_interleaved_write_frame( ofcx, &pkt );
    
                    }
    
                    av_free_packet( &pkt );
                    av_init_packet( &pkt );
                }
    
            }
    
            //if command 'stop' comes
            if(stop_flag==1){
                printf("command stop comes \n");
                //writing buffer_size video part to the end of file.
                int pk_cnt=bufer_size;
                while ( av_read_frame( ifcx, &pkt ) >= 0 && pk_cnt>0){
                    if ( pkt.stream_index == i_index ) {
    
                        pkt.stream_index = ost->id;
                        pkt.pts = av_rescale_q_rnd(pkt.pts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.dts = av_rescale_q_rnd(pkt.dts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                        pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);
                        pkt.pos = -1;
    
                        printf("writing last packets to file from cam \n");
    
                        av_interleaved_write_frame( ofcx, &pkt );
    
                    }
    
                    av_free_packet( &pkt );
                    av_init_packet( &pkt );
                    pk_cnt--;
                }
    
                  av_write_trailer( ofcx );
                  avio_close( ofcx->pb );
                  stop_flag=0;
                  printf("end writing file \n");
    
            }
    
        }
    
      return EXIT_SUCCESS;
    }
    
  • extracting quantization matrix in jpeg conversion and residual error in mpeg conversion in ffmpeg ?

    31 juillet 2017, par Saeid Zangeneh

    Im not familiar with the ffmpeg source code and I'm not so professional in programming to can change or find out the code.I just want to extract quantization matrix in jpeg conversion also the residual error in mpeg conversion.

  • Video transcoding during stream

    31 juillet 2017, par Wajahat

    I am trying to setup a testbed that will be used for experimentation, and I have deployed some VMs over Openstack and the setup looks like this currently: current VM setup The far right machine is running Apache2 server and video is hosted in /var/www/html/videos folder. VNF1 and VNF2 machines are acting as intermediate routers with static routes configured to route traffic to Apache server machine.

    The client machine runs VLC player to stream video on-demand from the server over HTTP like this:

    vlc http://10.10.2.7/videos/bunny.mp4
    

    Now, I want to be able to do dynamic transcoding of video while it is being streamed, but I don't want to do transcoding at server side (for experiment's purpose the server is not in our control) neither at client side but somewhere in the middle machines (VNF1 for example) so that it is transparent to client. Basically, I want to implement video transcoder as a network function.

    I have found FFmpeg which I think should be able to get this done, ffmpeg-server for example allows streaming over HTTP, but I am not exactly sure how to use it for transcoding video traffic?

  • Convert WebM/H.264 to MP4/H.264 efficiently with ffmpeg.js

    31 juillet 2017, par SB2055

    As a result of the answer here: Recording cross-platform (H.264?) videos using WebRTC MediaRecorder

    How can one go about using ffmpeg.js to efficiently unwrap a webm h.264 video and re-wrap it into an mp4 container?

    I'm looking through the docs: https://github.com/Kagami/ffmpeg.js?files=1

    However I don't see (or perhaps I'm looking for the wrong terminology) any examples for the above. This operation will be performed on the browser (chrome) prior to uploading as a Blob - I could use a web worker though hopefully rewrapping is a trivial enough operation to not require it.

  • FFmpeg - CRF Command for Nvenc encode ? [migrated]

    31 juillet 2017, par hongducwb

    My current command for resize videos, 1080p 2GB to 300MB but it take a lot of time on my CPU

    mkdir newfiles
    for %%a in ("*.mp4") do ffmpeg -i "%%a" -c:v libx264 -preset slow -crf 21 c:a aac -b:a 128k -vf scale=678:-2 "newfiles\%%~na.mp4"
    pause

    i try nvenc with my 1070.

    mkdir newfiles
    for %%a in ("*.mp4") do ffmpeg -i "%%a" -c:v h264_nvenc -preset slow -c:a aac -b:a 128k -vf scale=678:-2 "newfiles\%%~na.mp4"
    pause

    output size always 3x or 5x original size, nvenc not working with -crf

    so anyone know command to resize/convert video with high quality and small size ?
    and should i use gpu for encoding ?

    THANK