Recherche avancée

Médias (91)

Sur d’autres sites (333)

  • webm video - it can not be copy to cut a correct time part for ffmpeg command(without re-encode) [closed]

    15 mars, par DanielHsu

    Command Goal :

    


      

    1. fast copy video's part
    2. 


    3. no re-encode with libvpx
    4. 


    


    Linux command below :
ffmpeg -ss 00:01:00 -to 00:02:00 -i input.webm -c copy output.webm

    


    command's process details :

    


    ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers   built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)   configuration:
--enable-libvpx   libavutil      58. 29.100 / 58. 29.100   libavcodec     60. 31.102 / 60. 31.102   libavformat    60. 16.100 / 60. 16.100   libavdevice    60.  3.100 / 60.  3.100   libavfilter     9. 12.100 / 
9. 12.100   libswscale      7.  5.100 /  7.  5.100   libswresample   4. 12.100 /  4. 12.100 Input #0, matroska,webm, from 'input.webm':   Metadata:
    title           : FFmpeg
    ENCODER         : Lavf58.29.100   Duration: 00:06:04.43, start: 0.000000, bitrate: 2487 kb/s   Stream #0:0: Video: vp8, yuv420p(tv, bt470bg/unknown/unknown, progressive), 1280x720, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn (default)
    Metadata:
      DURATION        : 00:06:04.432000000 Output #0, webm, to 'output.webm':   Metadata:
    title           : FFmpeg
    encoder         : Lavf60.16.100   Stream #0:0: Video: vp8, yuv420p(tv, bt470bg/unknown/unknown, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1k tbr, 1k tbn (default)
    Metadata:
      DURATION        : 00:06:04.432000000 Stream mapping:   Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help [out#0/webm @ 0x5609ee9bb840] video:35912kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.069370% size=   35937kB time=00:00:59.96 bitrate=4909.2kbits/s speed= 211x


    


    command usage's result :
output.webm always start from input.webm's 00:00:00 to end input.webm's 00:01:00
(it should be start from input.webm's 00:01:00 to end input.webm's 00:02:00 )

    


    input.webm format details from mediainfo tool :

    


    


    General Count : 331 Count of stream
of this kind : 1 Kind of stream
    
 : General Kind of stream : General Stream
identifier : 0 Count of video streams
    
 : 1 Video_Format_List : VP8
Video_Format_WithHint_List : VP8 Codecs Video
    
 : VP8 Complete name :
pure_film/65ea641a4075c92236151349_video.webm Folder name
    
 : pure_film File name extension :
65ea641a4075c92236151349_video.webm File name
    
 : 65ea641a4075c92236151349_video File extension
    
 : webm Format : WebM Format
    
 : WebM Format/Url :
http://www.webmproject.org/ Format/Extensions usually used :
webm Commercial name : WebM Format version
    
 : Version 2 Internet media type : video/webm File
size : 113301943 File size
    
 : 108 MiB File size : 108 MiB File size
 : 108 MiB File size : 108 MiB File size
 : 108.1 MiB Duration : 364432 Duration
 : 6 min 4 s Duration : 6 min 4 s 432
ms Duration : 6 min 4 s Duration
    
 : 00:06:04.432 Duration : 00:06:04.432
Overall bit rate : 2487201 Overall bit rate
    
 : 2 487 kb/s Stream size : 4801069 Stream
size : 4.58 MiB (4%) Stream size
    
 : 5 MiB Stream size : 4.6 MiB Stream size
 : 4.58 MiB Stream size : 4.579 MiB Stream
size : 4.58 MiB (4%) Proportion of this
stream : 0.04237 IsStreamable
    
 : Yes Title : FFmpeg Movie name
    
 : FFmpeg File last modification date : UTC 2024-03-08
01:41:47 File last modification date (local) : 2024-03-08
09:41:47 Writing application : Lavf58.29.100
Writing application : Lavf58.29.100 Writing
library : Lavf58.29.100 Writing library
    
 : Lavf58.29.100

    


    Video Count : 377 Count of stream
of this kind : 1 Kind of stream
    
 : Video Kind of stream : Video Stream
identifier : 0 StreamOrder
    
 : 0 ID : 1 ID
    
 : 1 Unique ID : 1 Format
    
 : VP8 Format : VP8 Format/Url
    
 : http://www.webmproject.org/ Commercial name
    
 : VP8 Codec ID : V_VP8 Codec ID/Url
    
 : http://www.webmproject.org/ Duration
    
 : 364432.000000 Duration : 6 min 4 s
Duration : 6 min 4 s 432 ms Duration
    
 : 6 min 4 s Duration : 00:06:04.432
Duration : 00:06:04.432 Bit rate
    
 : 2381808 Bit rate : 2 382 kb/s Width
 : 1280 Width : 1 280 pixels Height
 : 720 Height : 720 pixels Pixel
aspect ratio : 1.000 Display aspect ratio
    
 : 1.778 Display aspect ratio : 16:9 Frame rate
mode : VFR Frame rate mode
    
 : Variable Color space : YUV Compression
mode : Lossy Compression mode
    
 : Lossy Delay : 0 Delay
    
 : 00:00:00.000 Delay, origin : Container
Delay, origin : Container Stream size
    
 : 108500874 Stream size : 103 MiB (96%)
Stream size : 103 MiB Stream size
    
 : 103 MiB Stream size : 103 MiB Stream
size : 103.5 MiB Stream size
    
 : 103 MiB (96%) Proportion of this stream : 0.95763
Default : Yes Default
    
 : Yes Forced : No Forced
    
 : No colour_description_present : Yes
colour_description_present_Source : Container Color range
    
 : Limited colour_range_Source : Container Matrix
coefficients : BT.470 System B/G
matrix_coefficients_Source : Container

    


    


    How to make the output.webm be in correct time range(00:01:00 00:02:00) ????

    


  • 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;