Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg compilation issue on Windows phone 8.1

    24 février 2017, par Mirko Puliafito

    Taking a look at Build ffmpeg for windows phone 8 I was able to compile ffmpeg on Windows phone 8using these steps:

    My configuration

    OS: Windows 8.1 VS: Ultimate 2013 Update 3 (If armasm fails, msvcdis110.dll missing download it from dllsearch ) Mingw (be sure that "link" and "cl" commands point to MS "link" and "cl") FFmpeg 2.1.5

    Follow prerequisites listed here: https://ffmpeg.org/platform.html#Microsoft-Visual-C_002b_002b-or-Intel-C_002b_002b-Compiler-for-Windows

    -) Download c99toc89: https://github.com/libav/c99-to-c89/downloads/. Be sure all files from c99toc89 are in Mingw PATH (copy in /bin)

    -) FFMPEG requires stdint.h and inttypes.h headers standardized as a part of C99. Unfortunately, Visual Studio does not include these files. Fortunately, there is a project that fixes this issue. Download the latest version and unpack it to Visual Studio includes (C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include).

    -) Launch cmd and "c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat x86_arm" and then msys

    -) configure:

    ./configure --toolchain=msvc \
    --disable-programs \
    --disable-network \
    --disable-protocols \
    --extra-cflags="-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE -D_M_ARM -D_WINAPI_FAMILY=WINAPIFAMILY_APP" \
    --enable-cross-compile \
    --target-os=win32 \
    --arch=arm \
    --as=armasm \
    --cpu=armv7 \
    --disable-yasm \
    --extra-ldflags="-MACHINE:ARM" \
    --disable-dxva2 \
    --disable-asm \
    --disable-doc
    

    I was able to get .a static libs but I wasn't able to generate an app using it. I have problems while linking for kernel32.lib and libcmt.lib misses.

    Anyone?

  • live tv recording .ts to mp4

    24 février 2017, par Thaison Nguyen

    I am using HDHomrun Prime to record live TV, the resulted file is a .ts file. I would like to convert this file into .mp4. I tried VLC player to convert that that takes awhile. My research shows that ffmpeg can do this but I ran into an error and google search for this is no help. I ran this code in terminal. (OS ubuntu 16.04)

    ffmpeg -i gsgame.ts -c copy -bsf:a aac_adtstoasc ford_ffmpeg.mp4
    

    and I get this.

    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] SPS unavailable in decode_picture_timing
    [h264 @ 0x561db2eba2e0] non-existing PPS 0 referenced
    [h264 @ 0x561db2eba2e0] decode_slice_header error
    [h264 @ 0x561db2eba2e0] no frame!
    [h264 @ 0x561db2eba2e0] Increasing reorder buffer to 2
    [mpegts @ 0x561db2eb57c0] start time for stream 3 is not set in estimate_timings_from_pts
    [mpegts @ 0x561db2eb57c0] PES packet size mismatch
        Last message repeated 1 times
    [mpegts @ 0x561db2eb57c0] Could not find codec parameters for stream 4 (Unknown: none (ETV1 / 0x31565445)): unknown codec
    Consider increasing the value for the 'analyzeduration' and 'probesize' options
    [mpegts @ 0x561db2eb57c0] Could not find codec parameters for stream 5 (Unknown: none (ETV1 / 0x31565445)): unknown codec
    Consider increasing the value for the 'analyzeduration' and 'probesize' options
    [mpegts @ 0x561db2eb57c0] Could not find codec parameters for stream 6 (Unknown: none ([192][0][0][0] / 0x00C0)): unknown codec
    Consider increasing the value for the 'analyzeduration' and 'probesize' options
    Input #0, mpegts, from 'gsgame.ts':
      Duration: 02:38:20.56, start: 14821.384111, bitrate: 3998 kb/s
      Program 3 
        Stream #0:0[0x1167]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
        Stream #0:1[0x1168](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
        Stream #0:2[0x1169](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
        Stream #0:3[0x116a]: Data: scte_35
        Stream #0:4[0x116b]: Unknown: none (ETV1 / 0x31565445)
        Stream #0:5[0x116c]: Unknown: none (ETV1 / 0x31565445)
        Stream #0:6[0x116d]: Unknown: none ([192][0][0][0] / 0x00C0)
    [AVBSFContext @ 0x561db2ebade0] Codec 'ac3' (86019) is not supported by the bitstream filter 'aac_adtstoasc'. Supported codecs are: aac (86018) 
    Error initializing bitstream filter: aac_adtstoasc
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
        Last message repeated 1 times
    

    I appreciate any help.

  • MLT Framework. How to add text or image watermark on the center of video and add zoomIn animation to it ?

    24 février 2017, par user2455079

    Tried this:

    -filter watermark:"welcome.jpg" in=0 out=320 composite.progressive=1 producer.align=centre composite.valign=middle composite.halign=center crop_to_fill=1 composite.geometry="0=0,0:80%x80%:0%;60=0,0:100%x100%:100%;260=0,0:120%x120%:100%;320=0,0:120%x120%:0%"
    

    But it doesn't increase size of watermark, it just moves it to right bottom side...

  • Different between fragmented mp4 files generated by ffmpeg and by code

    24 février 2017, par dinhnguyen

    Currently I have a problem when generating fragmented MP4 file from code using libavformat. My file can be played using VLC, but can't be streamed (via WebSocket) and played (via MediaSource) in (Chrome) browser. (I used this to test streaming fragmented MP4 file to browser via WebSocket).

    Note: The files below is encoded by Baseline profile, level 4. So you should change the MIME type (in index.html) to const mimeCodec = 'video/mp4; codecs="avc1.42C028"'; to be able to play them.

    I checked and found that my generated Mp4 file is a bit different with the file generated by using ffmpeg tool.

    Here's what I've done:

    I have a .h264 file

    1. The first approach, I use ffmpeg to generate the fragmented MP4 file.

      ffmpeg -i temp.h264 -vcodec copy -f mp4 -movflags empty_moov+default_base_moof+frag_keyframe ffmpeg.mp4
      

      The generated file can be played by both Quicktime player and VLC player

    2. The second approach, I programmaticaly generate the fragmented Mp4 file by using libavformat

      First I initialize the context, the codec in code is the AVCodecContext* of the input stream

       av_register_all();
       avcodec_register_all();
       int ret;
       AVOutputFormat* fmt = av_guess_format("mp4", 0, 0);
       if(!fmt) {
         return;
       }
      
       AVFormatContext* ctx = avformat_alloc_context();
       // Create AVIO context to capture generated Mp4 contain
       uint8_t *avio_ctx_buffer = NULL;
       size_t avio_ctx_buffer_size = 50000;
       IOOutput buffer = {};
       const size_t bd_buf_size = 50000;
       avio_ctx_buffer = (uint8_t*)av_malloc(avio_ctx_buffer_size);
       buffer.buff = (uint8_t*)av_malloc(bd_buf_size);
      
       buffer.size = bd_buf_size;
       AVIOContext* ioCtx = avio_alloc_context(avio_ctx_buffer, (int)avio_ctx_buffer_size, 1, &buffer, NULL, MP4Formatter::onWritePacket, NULL);
      
       ctx->oformat = fmt;
       if (ctx->oformat->flags & AVFMT_GLOBALHEADER)
         ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
       ctx->pb = ioCtx;
       av_opt_set(ctx, "movflags", "frag_keyframe+empty_moov+default_base_moof", 0);
      
       AVStream* st = avformat_new_stream(ctx, codec->codec);
       if (!st) {
         return;
       }
      
       st->id = (ctx->nb_streams - 1);
       avcodec_parameters_from_context(st->codecpar, codec);
       st->time_base = codec->time_base;
       ioCtx->seekable = false;
      

      Second I implement the onWritePacket callback

       int MP4Formatter::onWritePacket(void *opaque, uint8_t* buf, int buf_size) {
         file.write((char*)buf, buf_size);
       }
      

      Third, on every packet from h264 file, I write it using av_interleaved_write_frame

       if (firstFrame) {
         AVDictionary *opts = NULL;
         av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov+default_base_moof", 0);
         if(!parseSPSPPS(data, length)) {
           return;
         }
         cout << "spslen " << spslen << " ppslen " << ppslen << endl;
         auto c = st->codecpar;
         // Extradata contains PPS & SPS for AVCC format
         int extradata_len = 8 + spslen + 1 + 2 + ppslen;
         c->extradata = (uint8_t*)av_mallocz(extradata_len);
         c->extradata_size = extradata_len;
         c->extradata[0] = 0x01;
         c->extradata[1] = sps[1];
         c->extradata[2] = sps[2];
         c->extradata[3] = sps[3];
         c->extradata[4] = 0xFC | 3;
         c->extradata[5] = 0xE0 | 1;
         int tmp = spslen;
         c->extradata[6] = (tmp >> 8) & 0x00ff;
         c->extradata[7] = tmp & 0x00ff;
         int i = 0;
         for (i=0; iextradata[8 + i] = sps[i];
         }
         c->extradata[8 + tmp] = 0x01;
         int tmp2 = ppslen;
         c->extradata[8 + tmp + 1] = (tmp2 >> 8) & 0x00ff;
         c->extradata[8 + tmp + 2] = tmp2 & 0x00ff;
         for (i=0; iextradata[8 + tmp + 3 + i] = pps[i];
         }
         int ret = avformat_write_header(ctx, &opts);
         if(ret < 0) {
           return;
         }
         firstFrame = false;
       }
       AVPacket pkt;
       av_init_packet(&pkt);
       pkt.buf = av_buffer_alloc(length);
       memcpy(pkt.buf->data, data, length);
       pkt.buf->size = length;
       pkt.data = pkt.buf->data;
       pkt.size = pkt.buf->size;
       pkt.pts = ts;
       pkt.dts = ts;
      
       if (keyFrame) {
         pkt.flags |= AV_PKT_FLAG_KEY;
       }
       else {
         pkt.flags = 0;
       }
      
       pkt.stream_index = st->id;
      
       av_interleaved_write_frame(ctx, &pkt);
       av_buffer_unref(&pkt.buf);
       av_packet_unref(&pkt);
      

    Can you guys take a look at my file to see what's wrong?

  • ffmpeg h264 hardware decode support in android

    24 février 2017, par king 王

    I try decode h264 in android with ffmpeg hardware decode much time, but no success, anyone can use ffmpeg hardware decode function in android?