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 (329)

  • FFMPEG : how to create a "title slide" for 3 seconds before a video [closed]

    15 mars, par ashay

    I'm trying to make a lecture video to put online. I have the video itself, and I have a title slide that I'd like to play for 3 seconds before the main video.

    


    I tried using ffmpeg to (1) create a 3 second long video from the title slide and (2) concat the two videos together.

    


    I'm having issues concatenating the videos together — when I do so, the resulting video is much longer than it should be. When I look online, others have similar problems — and this seems to occur when the parameters of the two videos do not match perfectly.

    


    I'd prefer to do this without re-encoding the main video — and it seems this should be possible because I should be able to control what parameters are set for the "lecture slide video".

    


    Here are the commands I've run.
The main video has framerate 25, resolution 1920x1080, and an audio stream at #0:0 and a video stream at #0:1 (according to ffmpeg -i [video].

    


    To create the video of the title slide, I ran ffmpeg -framerate 25 -i lec01_title.png -t 3 -c:v libx264 -x265-params lossless=1 -pix_fmt yuvj420p -vf scale=1920:1080 lec01_title.mp4 -f lavfi -i anullsrc -c:a aac -shortest.
Then to reorder the streams to match the main video, I ran ffmpeg -i lec01_title.mp4 -map 0:a -map 0:v -c:v copy -c:a copy lec01_title_matched.mp4.

    


    Then to concatenate the two files together, I created a text file "concat_list" with :
file 'lec01_title_matched.mp4' file 'lec01.mp4', and ran the command ffmpeg -f concat -safe 0 -i concat_list.txt -c copy -movflags +faststart output.mp4.

    


    The main video is 53 minutes long, but the final output video after concatenating is 1 hour and 43 minutes long.

    


    I'm looking for advice for how to create the "lecture title video" properly to match the parameters of the second video so that I can concatenate them without problems.

    


    Here's the output of ffmpeg -i lec01.mp4 :

    


    ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.1.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  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
  libpostproc    57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dcai_lec01.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : 2-190-wideshot
    encoder         : Lavf60.16.100
  Duration: 00:47:39.08, start: 0.000000, bitrate: 1435 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 96000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 1298 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.31.102 libx264


    


    Described above in detail.

    


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