Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • UserWarning : x bytes wanted but 0 bytes read at frame index y (out of a total z frames), at time q sec. Using the last valid frame instead

    9 juillet, par Wiz

    I have a script which subclips a larger video and then stitches needed parts together using concatenate and write video file in moviepy. But the problem is everytime i run the script i get the video but the audio is off sync, usually the audio starts normally, but over time becomes delayed. I suspect it is because i want to concatenate around 220 smaller mp4 videos into one big mp4 video, but every smaller clips receives the error:'UserWarning: In file test.mp4, 1555200 bytes wanted but 0 bytes read at frame index y (out of a total y+1 frames), at time x sec. Using the last valid frame instead.'

    I use moviepy v2

    MY CODE (it doesnt produce any strict errors, but does give the aformentioned UserWarning when writing video_unsilenced.mp4):

    n = 0
    
    cuts = []
    input_paths = []
    vc = []
    os.makedirs(r"ShortsBot\SUBCLIPS")
    for timer in range(len(startsilence)-1):
       w = VideoFileClip(r"ShortsBot\output\cropped_video.mp4").subclipped(endsilence[n],(startsilence[n+1]+0.5))
       w.write_videofile(r"ShortsBot\SUBCLIPS\video" + str(n) + ".mp4")
       a = VideoFileClip(r"ShortsBot\SUBCLIPS\video" + str(n) + ".mp4")
       vc.append(a)
       n+=1
    
    output_fname = "video_unsilenced.mp4"
    clip = mpy.concatenate_videoclips(clips=vc, method= 'compose')
    clip.write_videofile(filename=output_fname, fps=30)
    _ = [a.close() for a in vc]
    

    Because moviepy is shaving off a frame or two for every video clip and at the same time writing the audio of the concatenated clip normally (without shaving off the audio that is in the missing frames), the video and audio slowly become out of sync.And the more clips i want to concatenate, the more the audio becomes out of sync, basically confirming my suspicion that it is because moviepy is using the last valid frame and writing the audio normally. The question i have is how can i fix this?

    EDIT: Full error message (although this error message appears after every clip that needs to be concatenated, usually, just like in this error message, its one or two frames that are invalid): C:\Users\user\miniconda3\envs\myenv\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py:190: UserWarning: In file C:\Users\user\Desktop\File\Subclips\video317.mp4, 1555200 bytes wanted but 0 bytes read at frame index 99 (out of a total 100 frames), at time 3.30/3.34 sec. Using the last valid frame instead.

  • FFMPEG : Track Extraction (-c copy) does not work [closed]

    8 juillet, par Justus

    Extract Audio without reencoding

    My ffmpeg command looks like this:

    ffmpeg -hide_banner -y -i test.mp4 -map 0 -c:a copy test1.mp3 
    

    It should:

    • Extract Audio Tracks(Currently only one!) from a given Video File
    • Write the data(very fast). No reencoding. <- This is the broken part

    Here is the ffmpeg output:

    [mp3 @ 0000026cac583cc0] Invalid audio stream. Exactly one MP3 audio stream is required.
    [out#0/mp3 @ 0000026cad12ae80] Could not write header (incorrect codec parameters ?): Invalid argument
    Invalid argument
    

    I tried(nothing is working)

    • -map 0
    • -map 0:1 etc.

    everytime i get invalid argument

    What do i wrong?

  • No such filter in ffmpeg

    8 juillet, par sneha desai

    I am trying to create the slideshow with below command.

    Here is the command I have executed:

     ffmpeg
    -loop 1 -t 1 -i /sdcard/input0.png 
    -loop 1 -t 1 -i /sdcard/input1.png 
    -loop 1 -t 1 -i /sdcard/input2.png 
    -loop 1 -t 1 -i /sdcard/input3.png 
    -loop 1 -t 1 -i /sdcard/input4.png 
    -filter_complex 
    "[0:v]trim=duration=15,fade=t=out:st=14.5:d=0.5[v0]; 
     [1:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v1]; 
     [2:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v2]; 
     [3:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v3]; 
     [4:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v4]; 
     [v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" /sdcard/out.mp4
    

    on execution of this command it gives error something like:

     onFailure: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
      built with gcc 4.8 (GCC)
      configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
      libavutil      55. 17.103 / 55. 17.103
      libavcodec     57. 24.102 / 57. 24.102
      libavformat    57. 25.100 / 57. 25.100
      libavdevice    57.  0.101 / 57.  0.101
      libavfilter     6. 31.100 /  6. 31.100
      libswscale      4.  0.100 /  4.  0.100
      libswresample   2.  0.101 /  2.  0.101
      libpostproc    54.  0.100 / 54.  0.100
    [mjpeg @ 0x4362af10] Changing bps to 8
    Input #0, image2, from '/sdcard/img0001.jpg':
      Duration: 00:00:00.04, start: 0.000000, bitrate: 2410 kb/s
        Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 259x194 [SAR 1:1 DAR 259:194], 25 fps, 25 tbr, 25 tbn, 25 tbc
    [mjpeg @ 0x436300a0] Changing bps to 8
    Input #1, image2, from '/sdcard/img0002.jpg':
      Duration: 00:00:00.04, start: 0.000000, bitrate: 2053 kb/s
        Stream #1:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 290x174 [SAR 1:1 DAR 5:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
    [mjpeg @ 0x436383a0] Changing bps to 8
    Input #2, image2, from '/sdcard/img0003.jpg':
      Duration: 00:00:00.04, start: 0.000000, bitrate: 3791 kb/s
        Stream #2:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 300x168 [SAR 1:1 DAR 25:14], 25 fps, 25 tbr, 25 tbn, 25 tbc
    [mjpeg @ 0x43648f50] Changing bps to 8
    Input #3, image2, from '/sdcard/img0004.jpg':
      Duration: 00:00:00.04, start: 0.000000, bitrate: 1796 kb/s
        Stream #3:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 259x194 [SAR 1:1 DAR 259:194], 25 fps, 25 tbr, 25 tbn, 25 tbc
    [mjpeg @ 0x437b4070] Changing bps to 8
    Input #4, image2, from '/sdcard/img0005.jpg':
      Duration: 00:00:00.04, start: 0.000000, bitrate: 1083 kb/s
        Stream #4:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 212x160 [SAR 1:1 DAR 53:40], 25 fps, 25 tbr, 25 tbn, 25 tbc
    [AVFilterGraph @ 0x4393c960] No such filter: '"'
    Error initializing complex filters.
    Invalid argument
    

    and i used this demo https://github.com/WritingMinds/ffmpeg-android-java

  • Why does increasing video bitrate with ffmpeg not improve quality

    8 juillet, par zahntheo

    I downloaded a video from YouTube Shorts for testing. The original video has the following metadata for the video stream:

    [STREAM]
    index=0
    codec_name=av1
    codec_long_name=Alliance for Open Media AV1
    profile=Main
    codec_type=video
    codec_tag_string=av01
    codec_tag=0x31307661
    width=608
    height=1080
    coded_width=608
    coded_height=1080
    closed_captions=0
    film_grain=0
    has_b_frames=0
    sample_aspect_ratio=N/A
    display_aspect_ratio=N/A
    pix_fmt=yuv420p
    level=4
    color_range=tv
    color_space=bt709
    color_transfer=bt709
    color_primaries=bt709
    chroma_location=unspecified
    field_order=unknown
    refs=1
    id=0x1
    r_frame_rate=30/1
    avg_frame_rate=30/1
    time_base=1/15360
    start_pts=0
    start_time=0.000000
    duration_ts=386560
    duration=25.166667
    bit_rate=611232
    max_bit_rate=N/A
    bits_per_raw_sample=N/A
    nb_frames=755
    nb_read_frames=N/A
    nb_read_packets=N/A
    extradata_size=20
    DISPOSITION:default=1
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    DISPOSITION:non_diegetic=0
    DISPOSITION:captions=0
    DISPOSITION:descriptions=0
    DISPOSITION:metadata=0
    DISPOSITION:dependent=0
    DISPOSITION:still_image=0
    DISPOSITION:multilayer=0
    TAG:language=und
    TAG:handler_name=ISO Media file produced by Google Inc.
    TAG:vendor_id=[0][0][0][0]
    [/STREAM]
    [STREAM]
    index=1
    codec_name=aac
    codec_long_name=AAC (Advanced Audio Coding)
    profile=LC
    codec_type=audio
    codec_tag_string=mp4a
    codec_tag=0x6134706d
    sample_fmt=fltp
    sample_rate=44100
    channels=2
    channel_layout=stereo
    bits_per_sample=0
    initial_padding=0
    id=0x2
    r_frame_rate=0/0
    avg_frame_rate=0/0
    time_base=1/44100
    start_pts=0
    start_time=0.000000
    duration_ts=1112064
    duration=25.216871
    bit_rate=128237
    max_bit_rate=N/A
    bits_per_raw_sample=N/A
    nb_frames=1086
    nb_read_frames=N/A
    nb_read_packets=N/A
    extradata_size=16
    DISPOSITION:default=1
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0
    DISPOSITION:timed_thumbnails=0
    DISPOSITION:non_diegetic=0
    DISPOSITION:captions=0
    DISPOSITION:descriptions=0
    DISPOSITION:metadata=0
    DISPOSITION:dependent=0
    DISPOSITION:still_image=0
    DISPOSITION:multilayer=0
    TAG:language=und
    TAG:handler_name=ISO Media file produced by Google Inc.
    TAG:vendor_id=[0][0][0][0]
    [/STREAM]
    [FORMAT]
    filename=video_77_medium.mp4
    nb_streams=2
    nb_programs=0
    nb_stream_groups=0
    format_name=mov,mp4,m4a,3gp,3g2,mj2
    format_long_name=QuickTime / MOV
    start_time=0.000000
    duration=25.216871
    size=2349871
    bit_rate=745491
    probe_score=100
    TAG:major_brand=isom
    TAG:minor_version=512
    TAG:compatible_brands=isomav01iso2mp41
    TAG:encoder=Lavf61.7.100
    [/FORMAT]
    

    I want to re-encode this video with higher bitrates (1.5 Mbps, 4 Mbps, and 8 Mbps) using ffmpeg to get better quality.

    I used this command for 8 Mbps:

    ffmpeg -i video_77_medium.mp4 -c:v libx264 -b:v 8000k -minrate 8000k -maxrate 8000k -bufsize 16000k -preset slow -c:a aac -b:a 128k -y video_77_medium_8Mbps.mp4
    
    

    However, the output video file size increased significantly, but I cannot see any noticeable improvement in visual quality compared to the original. The bitrate probe of the output confirms that the bitrate is indeed higher.

    What could be the reason that the quality looks almost the same despite a higher bitrate?

    Is there a better way to re-encode videos from AV1 to H.264 at different bitrates so that I can visually observe quality differences?

    Additional info:

    • The source video codec is AV1, the output codec is H.264.

    • The original video's bitrate is around 611 kbps.

    • The output files are encoded with fixed bitrate (using minrate, maxrate, bufsize).

    • I want to produce versions that show clear quality differences for comparison.

  • How to add a time limit for ffmpeg multiple outputting download ? [closed]

    8 juillet, par Nycelia

    I've been trying to get multiple outputs with different duration of segments from a playlist url using ffmpeg. Example: 120 seconds of a live stream. One output must download 8 times 15 seconds segments. Other output must download 4 times 30 seconds segments. Both outputs will have the same content, but with different durations. It works fine when I use a single output, but with 2 outputs, it's not limited to 120 seconds. Instead it just keeps downloading.

    Note: I know I could get a single output and divide it into segments later, but I need this approach.

    ffmpeg -t 120 -i  -c copy -f segment -segment_time 15 -reset_timestamps 1 -strftime 1 "15sec_%Y-%m-%d_%H-%M-%S.mp4" -c copy -f segment -segment_time 30 -reset_timestamps 1 -strftime 1 "30sec_%Y-%m-%d_%H-%M-%S.mp4"