Answers.Body: <p>Directly converting <code>mp3</code> was yielding incorrect times. So pre-converting to <code>aac</code> and then doing a loss-less copy to <code>mp4</code> fixed it. I currently use the following:</p>
  <pre><code>for i in *.mp3;
  do (
    ffmpeg -i &quot;$i&quot; -b:a 256k &quot;${i%.*}.aac&quot;;
    ffmpeg -r 0.01 -i image.jpg
           -i &quot;${i%.*}.aac&quot; -c:a copy -shortest -max_interleave_delta 500M
           -c:v libx265 -x265-params lossless=1 -pix_fmt yuvj420p -vf &quot;loop=-1:1&quot;
           -movflags faststart &quot;${i%.*}.mp4&quot;);
  done
  </code></pre>
  <ul>
  <li><p><code>-r 0.01</code>: Sets a very low framerate (0.01 frames per second), making it essentially a static image video. This feels so hacky, I'd love to get your input if there's a better/proper way to do this!</p>
  </li>
  <li><p><code>-i image.jpg</code>: Specifies the input image file that has resolution of 7680x4320.</p>
  </li>
  <li><p><code>-i &quot;${i%.*}.aac&quot;</code>: Takes the previously generated AAC audio file.</p>
  </li>
  <li><p><code>-c:a copy</code>: Copies the audio stream without re-encoding (saving time).</p>
  </li>
  <li><p><code>-shortest</code>: Makes the output video end when the shortest input (image or audio) ends.</p>
  </li>
  <li><p><code>-max_interleave_delta 500M</code>: Improves compatibility for streaming by limiting audio/video gaps.</p>
  </li>
  <li><p><code>-c:v libx265</code>: Uses the x265 (HEVC) video encoder for efficient compression. I wanted to use <code>hevc_toolbox</code> since I'm on an <code>arm64</code> MacOS machine but it doesn't seem to support similar parameters. <em><strong>If you know a hack to use that for still images, please share!</strong></em></p>
  </li>
  <li><p><code>-x265-params lossless=1</code>: Sets x265 encoding to lossless mode for high-quality output.</p>
  </li>
  <li><p><code>-pix_fmt yuvj420p</code>: Sets a common color format for compatibility. Even though <code>, using [this format fixes/avoids][1] the </code>deprecated pixel format used, make sure you did set range correctly` warning that you get.</p>
  </li>
  <li><p><code>-vf &quot;loop=-1:1&quot;</code>: Loops the image indefinitely (-1 means unlimited, size is 1 frame).</p>
  </li>
  <li><p><code>-movflags faststart</code>: Optimizes the video file for web streaming.</p>
  </li>
  <li><p><code>&quot;${i%.*}.mp4&quot;</code>: Replaces the &quot;.mp3&quot; extension with &quot;.mp4&quot;, creating an MP4 video file as output.</p>
  </li>
  </ul>
  <p>The resultant file works in Youtube, but doesn't work well in Infuse, VLC, Quicktime or Finder's QuickLook. Dunno how to fix that.</p>
  <p>Next goal is to do a royalty-free version of this with <code>av1</code>/<code>vp9</code> and <code>Opus</code>. And to add subtitle files</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-21T00:34:34.303Z
Answers.LastActivityDate: 2024-02-21T00:34:34.303Z
Answers.UserDisplayName: MyPreciousss
Body: <p>I want to make a video using a cover image and an audio file with the audio file as the length. What's the most optimal modern way to do this with new codecs and high resolutions?</p>
  <p>Reason why I want 4K/8K: The deployment display is an 8K panel and a lower resolution yields sub-par experience.</p>
  <p>Here's the command I tried:
  <code>ffmpeg -r 0.01 -loop 1 -i image.jpg -i audio.mp3 -c:v hevc_toolbox -c:a aac  -b:a 196k -pix_fmt yuv420p -shortest out.mp4</code></p>
  <p>But the output was inconsistent and usually 1.5-2x the length of the audio file even with <code>-shortest</code></p>
  <p>Relevant Past Research:</p>
  <ol start="0">
  <li><p>ffmpeg has a long-standing still-open bug about this issue where it can't approximate timing of the output correctly: trac.ffmpeg.org/ticket/5456</p>
  </li>
  <li><p><a href="https://superuser.com/questions/1041816/combine-one-image-one-audio-file-to-make-one-video-using-ffmpeg">https://superuser.com/questions/1041816/combine-one-image-one-audio-file-to-make-one-video-using-ffmpeg</a> but it doesn't cover it</p>
  </li>
  </ol>
  <p>And a lot of Reddit posts with h264/1080p instructions that were not fully applicable here.</p>
  <blockquote>
  <p>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)</p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-21T04:33:47.580Z
Comments.Text: What was the original full command you tried? And which ffmpeg version?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-21T16:49:57.807Z
Comments.Text: added the command
Comments.UserDisplayName: MyPreciousss
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-22T04:27:11.110Z
Comments.Text: And version? ...
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-27T06:48:22.440Z
Comments.Text: oops, added version
Comments.UserDisplayName: MyPreciousss
Tags: <ffmpeg><hevc><h265><vp9><av1>
Title: Creating an 8K/4K video in ffmpeg from single image frame leads to video longer than audio
UserDisplayName: MyPreciousss
ThreadText: # Creating an 8K/4K video in ffmpeg from single image frame leads to video longer than audio
  
  (Asked by: username_0 on 2024-02-21)
  
  I want to make a video using a cover image and an audio file with the audio file as the length. What's the most optimal modern way to do this with new codecs and high resolutions?
  
  Reason why I want 4K/8K: The deployment display is an 8K panel and a lower resolution yields sub-par experience.
  
  Here's the command I tried:
  `ffmpeg -r 0.01 -loop 1 -i image.jpg -i audio.mp3 -c:v hevc_toolbox -c:a aac -b:a 196k -pix_fmt yuv420p -shortest out.mp4`
  
  But the output was inconsistent and usually 1.5-2x the length of the audio file even with `-shortest`
  
  Relevant Past Research:
  
  0. ffmpeg has a long-standing still-open bug about this issue where it can't approximate timing of the output correctly: trac.ffmpeg.org/ticket/5456
  1. <https://superuser.com/questions/1041816/combine-one-image-one-audio-file-to-make-one-video-using-ffmpeg> but it doesn't cover it
  
  And a lot of Reddit posts with h264/1080p instructions that were not fully applicable here.
  
  > 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)
  
  **Tags:** ffmpeg, hevc, h265, vp9, av1
  
  > **Comments:**
  > **username_1**: What was the original full command you tried? And which ffmpeg version?  
  > **username_0**: added the command  
  > **username_1**: And version? ...  
  > **username_0**: oops, added version  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-02-21. Score: 0
  
  Directly converting `mp3` was yielding incorrect times. So pre-converting to `aac` and then doing a loss-less copy to `mp4` fixed it. I currently use the following:
  
  ```
  for i in *.mp3;
  do (
    ffmpeg -i "$i" -b:a 256k "${i%.*}.aac";
    ffmpeg -r 0.01 -i image.jpg
           -i "${i%.*}.aac" -c:a copy -shortest -max_interleave_delta 500M
           -c:v libx265 -x265-params lossless=1 -pix_fmt yuvj420p -vf "loop=-1:1"
           -movflags faststart "${i%.*}.mp4");
  done
  
  ```
  
  * `-r 0.01`: Sets a very low framerate (0.01 frames per second), making it essentially a static image video. This feels so hacky, I'd love to get your input if there's a better/proper way to do this!
  * `-i image.jpg`: Specifies the input image file that has resolution of 7680x4320.
  * `-i "${i%.*}.aac"`: Takes the previously generated AAC audio file.
  * `-c:a copy`: Copies the audio stream without re-encoding (saving time).
  * `-shortest`: Makes the output video end when the shortest input (image or audio) ends.
  * `-max_interleave_delta 500M`: Improves compatibility for streaming by limiting audio/video gaps.
  * `-c:v libx265`: Uses the x265 (HEVC) video encoder for efficient compression. I wanted to use `hevc_toolbox` since I'm on an `arm64` MacOS machine but it doesn't seem to support similar parameters. ***If you know a hack to use that for still images, please share!***
  * `-x265-params lossless=1`: Sets x265 encoding to lossless mode for high-quality output.
  * `-pix_fmt yuvj420p`: Sets a common color format for compatibility. Even though `, using [this format fixes/avoids][1] the` deprecated pixel format used, make sure you did set range correctly` warning that you get.
  * `-vf "loop=-1:1"`: Loops the image indefinitely (-1 means unlimited, size is 1 frame).
  * `-movflags faststart`: Optimizes the video file for web streaming.
  * `"${i%.*}.mp4"`: Replaces the ".mp3" extension with ".mp4", creating an MP4 video file as output.
  
  The resultant file works in Youtube, but doesn't work well in Infuse, VLC, Quicktime or Finder's QuickLook. Dunno how to fix that.
  
  Next goal is to do a royalty-free version of this with `av1`/`vp9` and `Opus`. And to add subtitle files
  
  
  ---
  
  