Newest 'ffmpeg' Questions - Stack Overflow

Articles published on the website

  • ffmpeg error: Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory

    6 March, by Syed Uddin

    I have the following files in the Convert_video_to_HLS folder on my Desktop:

    • input
    • output
    • video.key

    The command I'm running is:

    bash ./Desktop/Convert_video_to_HLS/ ./Desktop/Convert_video_to_HLS/input ./Desktop/Convert_video_to_HLS/ ./Desktop/Convert_video_to_HLS/video.key ./Desktop/Convert_video_to_HLS/output

    The contents of

    echo $DIR
    # List all mp4 files on folder
    MP4_DIRS=$(find $DIR -type f | grep -E "\.mp4$")
    mkdir -p $OUTPUT
    for addr in $MP4_DIRS
    FILE=$(basename $addr .mp4)
    mkdir -p $OUTPUT/$FILE
    ffmpeg -i $addr -codec: copy -start_number 0 -hls_time 20 -hls_list_size 0 -hls_key_info_file $DIR_KEY_INFO -f hls $OUTPUT/$FILE/$FILE.m3u8

    The error message i get is:

    [hls @ 0x7fd654012400] Opening './Desktop/Convert_video_to_HLS/' for reading
    [hls muxer @ 0x7fd65401c600] error opening key info file ./Desktop/Convert_video_to_HLS/
    Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
    Stream mapping:
      Stream #0:1 -> #0:0 (copy)
      Stream #0:0 -> #0:1 (copy)
        Last message repeated 1 times

    Help appreciated. FYI I'm new to bash script and following a tutorial so a breakdown would be appreciated.

    Update: I have placed the files in my root directory and run the following command, and it seems to work.

    bash ./ ./input ./ ./video.key ./output

    Therefore, for some reason, the folder directory is not being referenced correctly.

  • Image overlay on video between two time using mobile-ffmpeg android

    6 March, by Saeid Honardan

    I am trying to add image overlay on video using "mobile-ffmpeg-full-gpl:4.4" library but faced following error:

    Error when evaluating the expression 'between(t' for enable' error.

    I have a class that create overlay filter for adding image:

    class ImageFilter {
    static String getFilter(String input, String output, ArrayList listImage, int order){
        String filter="";
        for (int i=0; icode>

    FFMPEG Command used:

    -loop 1 -i /storage/emulated/0/OP_Video_Editor/.temp/background.png -ss 0.0 -t 21.18 -i /storage/emulated/0/OP_Video_Editor/.temp/1614097633623.mp4 -i /storage/emulated/0/OP_Video_Editor/.resource/sticker_i02.png -filter_complex [1:v]crop=640:360:0:0[crop];[crop]scale=1280:720[v_scale];color=black:1280x720,fps=30[bgr0];[bgr0][0:v]overlay[bgr];[bgr][v_scale]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1[v1];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.0[a1];[v1][a1]concat=n=1:v=1:a=1[v][a];[a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.0[a0];[a0]amix=inputs=1:duration=longest:dropout_transition=1[outAudio];[2:v]scale=333:333,rotate=-0.0:c=none:ow=rotw(-0.0):oh=roth(-0.0)[ov2];[v][ov2]overlay=333.33334:333.33334:enable=between(t,0.0,10.0)[inText] -map [inText] -map [outAudio] -format yuva420p -preset ultrafast -video_track_timescale 90k -b:v 2000k -c:v libx264 -bufsize 64k -c:a aac -bsf aac_adtstoasc -strict -2 -y /storage/emulated/0/videoExport/videoplayback_22_21_28_18_44_10.mp4 

    Also my log when I run program is:

    '2021-03-03 17:26:32.165 11664-11830/com.hecorat.azplugin2 E/mobile-ffmpeg: [overlay @ 0xdc5f3b80] [Eval @ 0xc5bd6b70] Missing ")" or too many args in "between(t"
    2021-03-03 17:26:32.167 11664-11830/com.hecorat.azplugin2 E/mobile-ffmpeg: [overlay @ 0xdc5f3b80] Error when evaluating the expression "between(t" for enable'

    How can I resolve this error?


    With guiding @slhck; I replace

    enable=between(t,"+image.startInTimeLineSec +","
            +image.endInTimeLineSec +")


    enable=between(t\\,"+image.startInTimeLineSec +"\\,"
            +image.endInTimeLineSec +")

    and it works.

  • FFMPEG - stream download + resize + HVEC convert in one statement?

    6 March, by Armitage2k

    I have a collection of 30 to 60 minutes PORTRAIT videos which I download via the below ffmpeg statement. That part works fine, but given that the resolution of the videos is quite high, it results in approx. 1,3 GB mp4 files.

    Once downloaded, I usually convert the video to 720p resolution which brings it down to approx. 500 MB per video, and then run another HVEC x265 compression which alas results in 250MB - 350MB sizes.

    Since its quite tedious to do all this manually, I was wondering if there is a FFMPEG statement / command I can use that achieves all of this in one go while downloading?

    Below the commands I currently use.

    Thank you

    Download: ffmpeg -i -c copy -bsf:a aac_adtstoasc L2_60min_vinyasa_vicky.mp4

    Convert: ffmpeg -i INPUT.mp4 -c:v libx265 -c:a copy -x265-params crf=25 OUTPUT.mkv

  • How to concatenate two MP4 files using FFmpeg?

    6 March, by Mark L

    I'm trying to concatenate two mp4 files using ffmpeg. I need this to be an automatic process hence why I chose ffmpeg. I'm converting the two files into .ts files and then concatenating them and then trying to encode that concatenated .ts file. The files are h264 and aac encoded and I'm hoping to keep the quality the same or as close to original as possible.

    ffmpeg -i part1.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part1.ts
    ffmpeg -i part2.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part2.ts
    cat part1.ts part2.ts > parts.ts
    ffmpeg -y -i parts.ts -acodec copy -ar 44100 -ab 96k -coder ac -vbsf h264_mp4toannexb parts.mp4

    Unfortunately I'm getting the following error message coming back from ffmpeg during encoding:

    [h264 @ 0x1012600]sps_id out of range
    [h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
    [h264 @ 0x1012600]sps_id out of range
    [h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
    [NULL @ 0x101d600]error, non monotone timestamps 13779431 >= 13779431kbits/s    
    av_interleaved_write_frame(): Error while opening file

    This happens about half way through encoding which makes me think that you can't concat two .ts files together and have it work.

  • ffmpeg concat multiple FHD videos, but output is HD

    6 March, by Zawazawa

    I'm trying to combine multiple 1920x1080 videos(.MTS) with concat option, but output resolution is 1280x720.

    How can I combine multiple videos with keeping resolution?

    Script is below.

    ffmpeg -safe 0 -f concat -i content_dir.txt -c:v copy -c:a copy -map 0:v -map 0:a output.MTS

    and the content of input text is below

    file '1.MTS'
    file '2.MTS'
    file '3.MTS'
    file '4.MTS'

    the information of source videos is below.

    video codec h264_nvenc
    audio codec ac3

    the output of command prompt is below.

    Input #0, concat, from 'E:\VideoMaker3\tmp_videos_o3_1\content_dir.txt':
      Duration: N/A, start: 0.000000, bitrate: 192 kb/s
        Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 15 fps, 15 tbr, 90k tbn, 30 tbc
        Stream #0:1(eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s

    Thank you.