Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • saving H.264 encoded images with libavcodec

    8 octobre 2011, par user846400

    I am getting H.264 images from an IP camera and want to save the encoded images (without decoding). I am using output-example.c from ffmpeg (libavformat/output-example.c) for this purpose. For Saving the raw H.264 image, I do the following:

    AVPacket pkt;
    av_init_packet(&pkt);
    if (c->coded_frame->pts != AV_NOPTS_VALUE)
            pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
    if(c->coded_frame->key_frame)
            pkt.flags |= PKT_FLAG_KEY;
    pkt.stream_index= st->index;
    pkt.data= (uint8_t *)ulAddr;//video_outbuf;
    pkt.size= out_size;
    save_image(pkt.data, out_size);
    

    Where ulAddr is the address pointer to the image and out_size is the image size. Instead of saving the images to a media video file, I want to save the individual images. save_image function simply uses basic fopen and fwrite functions for saving the images. If I decode the frame and then save, everything works fine. But I have problem saving the encoded frames. The encoded frames are saved with a very small size and then they cannot be decoded. Is there anything wrong? I will really appreciate any help in this regard.

  • FFMpeg generating screenshots drop frames

    6 octobre 2011, par Morgan

    I'm using FFMpeg to extract frames from a video file, and for most videos it works flawlessly. But certain videos it seems to have to seek to the position that I want to take the screenshot from, and drops all the frames on the way there taking quite a while if the position i'm generating a screenshot from is near the end of the video. Here is the command I'm using to extract my screenshot.

    ffmpeg -ss 60 -i input.mkv -vframes 1 -f image2 -an -r 1/5 output.jpg

    and the output I receive

    ffmpeg version 0.8.3, Copyright (c) 2000-2011 the FFmpeg developers
      built on Sep 20 2011 00:46:47 with clang 2.1 (tags/Apple/clang-163.7.1)
      configuration: --prefix=/Users/Morgan/Downloads/installed/ffmpeg --extra-libs=/Users/Morgan/Downloads/installed/lib/libfaac.a --enable-gpl --extra-cflags=-I/Users/Morgan/Downloads/installed/include --disable-ffplay --disable-ffserver --disable-shared --disable-debug --extra-ldflags=-L/Users/Morgan/Downloads/installed/lib --enable-libmp3lame --enable-libfaac --enable-libx264 --enable-nonfree --cc=clang
      libavutil    51.  9. 1 / 51.  9. 1
      libavcodec   53.  7. 0 / 53.  7. 0
      libavformat  53.  4. 0 / 53.  4. 0
      libavdevice  53.  1. 1 / 53.  1. 1
      libavfilter   2. 23. 0 /  2. 23. 0
      libswscale    2.  0. 0 /  2.  0. 0
      libpostproc  51.  2. 0 / 51.  2. 0
    [matroska,webm @ 0x7f9dd3007c00] Estimating duration from bitrate, this may be inaccurate
    
    Seems stream 0 codec frame rate differs from container frame rate: 47.95 (500000/10427) -> 23.98 (24000/1001)
    Input #0, matroska,webm, from 'input.mkv':
      Duration: 01:01:36.16, start: 0.000000, bitrate: 576 kb/s
        Stream #0.0(eng): Video: h264 (High), yuv420p, 1280x720, PAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
        Metadata:
          title           : Input Video
        Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s (default)
        Metadata:
          title           : English Dolby Digital 5.1 AC3
        Stream #0.2(eng): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s
        Metadata:
          title           : Commentary
        Stream #0.3(eng): Subtitle: [0][0][0][0] / 0x0000 (default)
        Metadata:
          title           : English
    Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
    [buffer @ 0x106c10c00] w:1280 h:720 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
    [buffersink @ 0x106c10e40] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
    [scale @ 0x106c11140] w:1280 h:720 fmt:yuv420p -> w:1280 h:720 fmt:yuvj420p flags:0x4
    Output #0, image2, to 'output.jpg':
      Metadata:
        encoder         : Lavf53.4.0
        Stream #0.0(eng): Video: mjpeg, yuvj420p, 1280x720 [PAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 0.20 tbc (default)
        Metadata:
          title           : Input Video
    Stream mapping:
      Stream #0.0 -> #0.0
    Press [q] to stop, [?] for help
    frame=    0 fps=  0 q=0.0 Lsize=      -0kB time=00:00:00.00 bitrate=   0.0kbits/s dup=0 drop=275    
    video:0kB audio:0kB global headers:0kB muxing overhead -inf%
    
  • Can I force FFMPEG to insert keyframes every second ?

    6 octobre 2011, par Kristian Frost

    I'm converting a bunch of videos to FLV with FFmpeg, and I've found the -force_key_frames option in the FFmpeg documentation.

    I want to insert a keyframe every second of the video, to enable smooth seeking. Is there any (easy) way to tell FFmpeg that I want a keyframe every second?

  • Python/FFMPEG command line issues

    5 octobre 2011, par 12hys

    I have a problem with running an FFMPEG command from within a Python script. When I run the following command from the terminal, I can stream video and audio from my attached webcam (Logitech C310) and output to file "out.avi" without any errors.

    ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 out.avi
    

    When I run the same command in a Python script below,

    def call_command(command):
        subprocess.Popen(command.split(' '))
    
    call_command("ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 out.avi")
    

    it gives me the error:

    Input #0, alsa, from 'default':
      Duration: N/A, start: 1317762562.695397, bitrate: N/A
      Stream #0.0: Audio: pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s
    [video4linux2 @ 0x165eb10]Cannot find a proper format for codec_id 0, pix_fmt -1.
    /dev/video0: Input/output error
    

    Could anyone shed some light on what could be going on here? I've tried using os.system() as well as subprocess.call() and it gives me the same errors. I'm not sure where to start on what could be going wrong here. I tried searching for the "video4linux2 Cannot find a proper format for codec_id 0, pix_fmt -1" error, but couldn't find anything consistent.

    I've also tried putting the "ffmpeg -f..." command in a shell script "test.sh", and giving it executable permissions. I then open terminal, and run "./test.sh", and it works. When I try calling the command "./test.sh" from within my Python script, I'm left with the original error as before. This is the Python command I tried with the test.sh script:

    subprocess.call(["./test.sh"])
    
  • iPad Doesn't Render H.264 Video with HTML5

    5 octobre 2011, par jgoldberg

    I have some H.264-encoded videos which render in HTML5 correctly in the web browser, but do not render correctly on the iPad. When I use a H.264 video I downloaded off the internet, my video renders correctly on the iPad, so it is not an HTML problem.

    Here is the ffmpeg info about my videos --

    My original .mov video:

    Seems stream 1 codec frame rate differs from container frame rate: 6000.00 (6000/1) -> 30.00 (30/1)

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a_video.mp4':

    Metadata:

    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    

    Duration: 00:00:42.74, start: 0.000000, bitrate: 220 kb/s

    Stream #0.0(eng): Audio: aac, 44100 Hz, stereo, s16, 94 kb/s
    Stream #0.1(eng): Video: h264, yuv420p, 762x464, 122 kb/s, 30 fps, 30 tbr, 3k tbn, 6k tbc
    

    After using Handbrake to convert my .mov to a mp4, yet doesn't render on the iPad:

    Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 29.97 (30000/1001)

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a_video.m4v':

    Metadata:

    major_brand     : mp42  
    minor_version   : 0
    compatible_brands: mp42isomavc1  
    encoder: HandBrake 0.9.5 2011010300  
    

    Duration: 00:00:42.77, start: 0.000000, bitrate: 169 kb/s

    Stream #0.0(und): Video: h264, yuv420p, 752x464 [PAR 381:376 DAR 381:232], 35 kb/s, PAR 145161:141376 DAR 145161:87232, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 128 kb/s

    Here is a .mp4 I found online which does render on the iPad:

    Seems stream 1 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 25.00 (25/1)

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a_video_3_emu.mp4':

    Metadata: major_brand : M4VP
    minor_version : 1
    compatible_brands: M4VPM4A mp42isom
    encoder : CoreMediaAuthoring 677, CoreMedia 420.17, i386

    Duration: 00:01:38.01, start: 0.000000, bitrate: 1023 kb/s

    Stream #0.0(und): Audio: aac, 32000 Hz, mono, s16, 97 kb/s
    Stream #0.1(und): Video: h264, yuv420p, 480x360 [PAR 1:1 DAR 4:3], 914 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc

    Does anyone see something wrong with the way I am encoded my videos?

    Edit

    At first my theory was that the iPad was sensitive to different container formats; but that appears not to be the case. I took a video which does render correctly on the iPad and converted it to a .mov, and it still played correctly on the iPad. So there must be a problem with how the iPad deals with the underlying H.264 stream.