Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

Aucun média correspondant à vos critères n’est disponible sur le site.

Sur d’autres sites (330)

  • FFMPEG C Library : Encoding h264 stream into Matroska .mkv container creates corrupt files

    16 mars, par Marvin Killing

    I want to use the FFMPEG C Library to create a Matroska Video .mkv file with only an h264 stream, but the resulting .mkv file comes out corrupt.

    


    The file cannot be played back with Windows Media Player, ffplay, or VLC, and when I try to ffprobe the resulting file, these are the error messages :

    


    [h264 @ 0000015060d8f5c0] No start code is found.
    Last message repeated 1 times
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0000015060d8f5c0] decode_slice_header error
[h264 @ 0000015060d8f5c0] no frame!
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0000015060d8f5c0] decode_slice_header error
[h264 @ 0000015060d8f5c0] no frame!
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
    Last message repeated 1 times
# [...]
# this continues for a long time


    


    I have followed the other troubleshooting steps for encoding h264 into Matroska, but none of them seemed to have done the trick for me :

    


    


    This is my C code :

    


    #include &#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;&#xA;int main(void) {&#xA;    char *out_file_path = "./video.mkv";&#xA;    AVFormatContext *format_context;&#xA;    AVStream *video_stream;&#xA;    AVCodecContext *codec_context;&#xA;&#xA;    avformat_alloc_output_context2(&amp;format_context, NULL, NULL, out_file_path);&#xA;&#xA;    const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);&#xA;    video_stream = avformat_new_stream(format_context, NULL);&#xA;&#xA;    codec_context = avcodec_alloc_context3(codec);&#xA;    av_opt_set(codec_context->priv_data, "preset", "superfast", 0);&#xA;    av_opt_set(codec_context->priv_data, "crf", "22", 0);&#xA;&#xA;    codec_context->width = 1920;&#xA;    codec_context->height = 1080;&#xA;    codec_context->time_base = av_make_q(1, 30);&#xA;    codec_context->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;&#xA;    if (strncmp("./video.mkv", out_file_path, 11) == 0) {&#xA;      printf("Writing .mkv...\n");&#xA;      codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;      codec_context->extradata = (uint8_t*)av_mallocz(1024 * 1024);&#xA;      codec_context->extradata_size = 1024 * 1024;&#xA;    } else {&#xA;      printf("Writing .mp4...\n");&#xA;    }&#xA;&#xA;    // XXX avcodec_parameters_from_context is potentially superfluous (?)&#xA;    int ret = avcodec_parameters_from_context(video_stream->codecpar, codec_context);&#xA;&#xA;    ret = avcodec_open2(codec_context, codec, NULL);&#xA;&#xA;    avio_open(&amp;format_context->pb, out_file_path, AVIO_FLAG_WRITE);&#xA;&#xA;    ret = avformat_write_header(format_context, NULL);&#xA;&#xA;    // create a black input frame&#xA;    AVFrame *input_frame = av_frame_alloc();&#xA;    input_frame->width = 1920;&#xA;    input_frame->height = 1080;&#xA;    input_frame->format = AV_PIX_FMT_YUV420P;&#xA;    ret = av_image_alloc(input_frame->data, input_frame->linesize, input_frame->width, input_frame->height, input_frame->format, 32);&#xA;    ptrdiff_t linesize[4] = { input_frame->linesize[0], input_frame->linesize[1], input_frame->linesize[2], input_frame->linesize[3] };&#xA;    ret = av_image_fill_black(input_frame->data, linesize, input_frame->format, 0, 1920, 1080);&#xA;&#xA;    // write 2 seconds of video, all black&#xA;    for (size_t current_pts = 0; current_pts &lt; 60; current_pts&#x2B;&#x2B;) {&#xA;      input_frame->pts = av_rescale_q(current_pts, av_make_q(1, 30), codec_context->time_base);;&#xA;&#xA;      ret = avcodec_send_frame(codec_context, input_frame);&#xA;&#xA;      AVPacket* packet = av_packet_alloc();&#xA;&#xA;      while (1) {&#xA;          ret = avcodec_receive_packet(codec_context, packet);&#xA;          if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;              break;&#xA;          } else if (ret &lt; 0) {&#xA;              printf("avcodec_receive_packet failed");&#xA;          } else {&#xA;              av_packet_rescale_ts(packet, codec_context->time_base, video_stream->time_base);&#xA;              ret = av_interleaved_write_frame(format_context, packet);&#xA;          }&#xA;      }&#xA;&#xA;      av_packet_free(&amp;packet);&#xA;    }&#xA;&#xA;    av_frame_free(&amp;input_frame);&#xA;&#xA;    // flush encoder&#xA;    avcodec_send_frame(codec_context, NULL);&#xA;    AVPacket *flush_packet = av_packet_alloc();&#xA;    while (avcodec_receive_packet(codec_context, flush_packet) != AVERROR_EOF) {&#xA;        //int ret = av_interleaved_write_frame(format_context_, packet);&#xA;        av_packet_rescale_ts(flush_packet, codec_context->time_base, video_stream->time_base);&#xA;        ret = av_write_frame(format_context, flush_packet);&#xA;    }&#xA;    av_packet_free(&amp;flush_packet);&#xA;&#xA;    ret = av_write_trailer(format_context);&#xA;    ret = avio_close(format_context->pb);&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    The error handling is stripped out, but it does not raise any errors.

    &#xA;

    This code works when I write into an mp4 file, but creates a corrupt file when writing into .mkv. You can change the output container format to mp4 by setting&#xA;char *out_file_path = "./video.mp4";

    &#xA;

    You can compile this by running

    &#xA;

    clang -I$(FFMPEG_DIR)/include -L$(FFMPEG_DIR)/lib -lavformat -lavcodec -lavutil main.c -o makemkv&#xA;

    &#xA;

    The output I’m getting while the above code is running :

    &#xA;

    Writing .mkv...&#xA;[libx264 @ 0x139804c40] using cpu capabilities: ARMv8 NEON&#xA;[libx264 @ 0x139804c40] profile High, level 4.0, 4:2:0, 8-bit&#xA;[libx264 @ 0x139804c40] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x3 me=dia subme=1 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=15 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=22.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 pb_ratio=1.30 aq=1:1.00&#xA;

    &#xA;

    When I use the ffmpeg CLI, I can create a working .mkv from my working .mp4 like this :

    &#xA;

    ffmpeg -i video.mp4 -c:v copy created-with-ffmpeg-cli.mkv&#xA;

    &#xA;

    I have uploaded the resulting video files here : https://drive.google.com/drive/folders/1FS-0fBAwKBbO-tyxC0VrFqcCyyqd0BR_?usp=sharing

    &#xA;

  • FFMPEG : FATAL error, file duration too long for timebase ?

    26 février, par clx

    I want to add a subtitle track on a ProRes files with ffmpeg command on Windows :

    &#xA;

    ffmpeg.exe  -i "X:\Test\Tokyo01.mov" -i "X:\Test\SubtitleEN.srt" -f mov -c:v copy -c:a copy -c:s mov_text -map 0:v -map 0:a -map "1:0" "-metadata:s:s:0" "language=EN" "-metadata:s:s:0" "handler_name=English"  "-metadata:s:s:0" "title=English" -y "X:\Test\Tokyo01_WithSub.mov" &#xA;

    &#xA;

    I have a fatal error at the end :

    &#xA;

    ...&#xA;FATAL error, file duration too long for timebase, this file will not be1737.7kbits/s speed=0.979x&#xA;playable with QuickTime. Choose a different timebase with -video_track_timescale or a different container format&#xA;...&#xA;

    &#xA;

    Source file looks good with FFProbe :

    &#xA;

    &#xA;[STREAM]&#xA;index=0&#xA;codec_name=prores&#xA;codec_long_name=Apple ProRes (iCodec Pro)&#xA;profile=HQ&#xA;codec_type=video&#xA;codec_time_base=15139/363340&#xA;codec_tag_string=apch&#xA;codec_tag=0x68637061&#xA;width=3996&#xA;height=2160&#xA;coded_width=3996&#xA;coded_height=2160&#xA;closed_captions=0&#xA;has_b_frames=0&#xA;sample_aspect_ratio=N/A&#xA;display_aspect_ratio=N/A&#xA;pix_fmt=yuv422p10le&#xA;level=-99&#xA;color_range=tv&#xA;color_space=unknown&#xA;color_transfer=unknown&#xA;color_primaries=unknown&#xA;chroma_location=unspecified&#xA;field_order=unknown&#xA;timecode=N/A&#xA;refs=1&#xA;id=N/A&#xA;r_frame_rate=24/1&#xA;avg_frame_rate=363340/15139&#xA;time_base=1/90000&#xA;start_pts=0&#xA;start_time=0.000000&#xA;duration_ts=340627500&#xA;duration=3784.750000&#xA;bit_rate=656235296&#xA;max_bit_rate=N/A&#xA;bits_per_raw_sample=10&#xA;nb_frames=90835&#xA;

    &#xA;

    The complete FFmpeg return console :

    &#xA;

    ffmpeg version 2023-09-04-git-f8503b4c33-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint&#xA;  libavutil      58. 19.100 / 58. 19.100&#xA;  libavcodec     60. 25.100 / 60. 25.100&#xA;  libavformat    60. 11.100 / 60. 11.100&#xA;  libavdevice    60.  2.101 / 60.  2.101&#xA;  libavfilter     9. 11.100 /  9. 11.100&#xA;  libswscale      7.  3.100 /  7.  3.100&#xA;  libswresample   4. 11.100 /  4. 11.100&#xA;  libpostproc    57.  2.100 / 57.  2.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;X:\Test\Tokyo01.mov&#x27;:&#xA;  Metadata:&#xA;    major_brand     : qt&#xA;    minor_version   : 512&#xA;    compatible_brands: qt&#xA;    encoder         : Lavf58.76.100&#xA;  Duration: 01:03:04.79, start: 0.000000, bitrate: 663143 kb/s&#xA;  Stream #0:0[0x1]: Video: prores (HQ) (apch / 0x68637061), yuv422p10le, 3996x2160, 656235 kb/s, 24 fps, 24 tbr, 90k tbn (default)&#xA;    Metadata:&#xA;      handler_name    : VideoHandler&#xA;      vendor_id       : FFMP&#xA;  Stream #0:1[0x2]: Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 5.1, s32 (24 bit), 6912 kb/s (default)&#xA;    Metadata:&#xA;      handler_name    : SoundHandler&#xA;      vendor_id       : [0][0][0][0]&#xA;[srt @ 000001bc0ec608c0] UTF16 is automatically converted to UTF8, do not specify a character encoding&#xA;Input #1, srt, from &#x27;X:\Test\SubtitleEN.srt&#x27;:&#xA;  Duration: N/A, bitrate: N/A&#xA;  Stream #1:0: Subtitle: subrip&#xA;Output #0, mov, to &#x27;X:\Test\Tokyo01_WithSub.mov&#x27;:&#xA;  Metadata:&#xA;    major_brand     : qt&#xA;    minor_version   : 512&#xA;    compatible_brands: qt&#xA;    encoder         : Lavf60.11.100&#xA;  Stream #0:0: Video: prores (HQ) (apch / 0x68637061), yuv422p10le, 3996x2160, q=2-31, 656235 kb/s, 24 fps, 24 tbr, 90k tbn (default)&#xA;    Metadata:&#xA;      handler_name    : VideoHandler&#xA;      vendor_id       : FFMP&#xA;  Stream #0:1: Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 5.1, s32 (24 bit), 6912 kb/s (default)&#xA;    Metadata:&#xA;      handler_name    : SoundHandler&#xA;      vendor_id       : [0][0][0][0]&#xA;  Stream #0:2(EN): Subtitle: mov_text (text / 0x74786574)&#xA;    Metadata:&#xA;      handler_name    : English&#xA;      title           : English&#xA;      encoder         : Lavc60.25.100 mov_text&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (copy)&#xA;  Stream #0:1 -> #0:1 (copy)&#xA;  Stream #1:0 -> #0:2 (subrip (srt) -> mov_text (native))&#xA;Press [q] to stop, [?] for help&#xA;FATAL error, file duration too long for timebase, this file will not be1737.7kbits/s speed=0.979x&#xA;playable with QuickTime. Choose a different timebase with -video_track_timescale or a different container format&#xA;[out#0/mov @ 000001bc0e847340] video:303184287kB audio:3193418kB subtitle:9kB other streams:0kB global headers:0kB muxing overhead: 0.000585%&#xA;frame=90834 fps= 23 q=-1.0 Lsize=306379507kB time=01:03:04.77 bitrate=663147.3kbits/s speed=0.979x&#xA;&#xA;

    &#xA;

    I don't find documentation for mentionned command "-video_track_timescale" to change timescale (here 1/90000 ).&#xA;I don't understand the problem ??

    &#xA;

  • How to merge special ts files to mp4 ? [closed]

    21 février, par mikezang

    I have some ts files and I want to merge them to mp4, I used command as below, some of ts can be merged without any problems.

    &#xA;

    ffmpeg -i &#x27;concat:01.ts|02.ts|03.ts|&#x27; -c copy -bsf:a aac_adtstoasc 01.mp4&#xA;

    &#xA;

    Then I found for some ts files, I got error as below when I used the same command above, what can I do to merge these ts files ?

    &#xA;

    ffmpeg version 2023-11-13-git-67a2571a55-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint&#xA;  libavutil      58. 32.100 / 58. 32.100&#xA;  libavcodec     60. 33.100 / 60. 33.100&#xA;  libavformat    60. 17.100 / 60. 17.100&#xA;  libavdevice    60.  4.100 / 60.  4.100&#xA;  libavfilter     9. 13.100 /  9. 13.100&#xA;  libswscale      7.  6.100 /  7.  6.100&#xA;  libswresample   4. 13.100 /  4. 13.100&#xA;  libpostproc    57.  4.100 / 57.  4.100&#xA;[png @ 0000028b191c1cc0] inflate returned error -3&#xA;Input #0, png_pipe, from &#x27;concat:001.ts|002.ts|003.ts&#x27;:&#xA;  Duration: N/A, bitrate: N/A&#xA;  Stream #0:0: Video: png, pal8(pc, gbr/unknown/unknown), 800x800, 25 fps, 25 tbr, 25 tbn&#xA;Output #0, mp4, to &#x27;01.mp4&#x27;:&#xA;  Metadata:&#xA;    encoder         : Lavf60.17.100&#xA;  Stream #0:0: Video: png (mp4v / 0x7634706D), pal8(pc, gbr/unknown/unknown), 800x800, q=2-31, 25 fps, 25 tbr, 12800 tbn&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (copy)&#xA;Press [q] to stop, [?] for help&#xA;[out#0/mp4 @ 0000028b19260cc0] video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown&#xA;[out#0/mp4 @ 0000028b19260cc0] Output file is empty, nothing was encoded&#xA;

    &#xA;

    The successful ts file by ffprobe :

    &#xA;

    Input #0, mpegts, from &#x27;001.ts&#x27;:&#xA;  Duration: 00:00:12.04, start: 0.038000, bitrate: 942 kb/s&#xA;  Program 1&#xA;  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn&#xA;  Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 97 kb/s&#xA;

    &#xA;

    The failed ts file by ffprobe :

    &#xA;

    [png @ 000001e9016fe940] inflate returned error -3&#xA;Input #0, png_pipe, from &#x27;001.ts&#x27;:&#xA;  Duration: N/A, bitrate: N/A&#xA;  Stream #0:0: Video: png, pal8(pc, gbr/unknown/unknown), 800x800, 25 fps, 25 tbr, 25 tbn&#xA;

    &#xA;