0

I'm trying to generate video files that follow a "prototype" file as much as possible (frame rate, dimensions, container format, codecs, etc.) but show a black screen with silent audio. Here's one command line that works fine, and produces a 3-second-long file:

ffmpeg -f lavfi -i color=c=black:s=3840x2160:r=25/1 -c:v h264 -f lavfi -i anullsrc=cl=mono:r=48000 -c:a pcm_s16be -t 3 out.mov

Sometimes, the prototype file has codecs that ffmpeg can read but not write, like pcm_bluray. So instead of trying to use the same codec as the prototype, I omit this parameter and let ffmpeg pick a default:

ffmpeg -f lavfi -i color=c=black:s=3840x2160:r=25/1 -c:v h264 -f lavfi -i anullsrc=cl=mono:r=48000 -t 3 out.mov

To my surprise, I get a file that's 3.022s long. What's interesting is that both the streams are 3.0s long, but container duration is longer:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",

            "time_base": "1/12800",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 38400,
            "duration": "3.000000",

            "nb_frames": "75",
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",

            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 144000,
            "duration": "3.000000",
        }
    ],
    "format": {
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "3.022000",
    }
}
ffmpeg version 4.0.2-2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8 (Ubuntu 8.2.0-7ubuntu1)
1

Specify a PCM codec. The default codec is AAC, which has a priming sample that format in ffprobe accounts for, but stream won't, since the demuxer will have discarded it before sending it to the decoder for analysis.

P.S. your syntax is wrong - it should be ffmpeg -f lavfi -i color=c=black:s=3840x2160:r=25/1 -f lavfi -i anullsrc=cl=mono:r=48000 -c:v h264 -c:a pcm_s16be -t 3 out.mov

Options before an input are applied to the input. You've gotten away with it because -c:v h264 sets the video decoder for the following input. However, since it is an audio-only input, the effect is inert. And the default codec for MOV happens to be H264, so the outcome is what you desired.

  • Ouch. Thank you for pointing out the argument-order problem. – iter Apr 15 at 13:05
  • So if I play the file out, it will still play for 3.0s, correct? So if I want an accurate duration for a file with AAC streams, do I need to sum up the durations and start times of individual streams instead of relying on the container? – iter Apr 15 at 13:49
  • 1
    Which file? The one with AAC or PCM? – Gyan Apr 15 at 14:22
  • MOV with AAC. With PCM, all durations agree, so there's no question. – iter Apr 15 at 14:35
  • 1
    If your player's decoder knows to skip the priming sample, then 3.0s else 3.022s – Gyan Apr 15 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.