Answers.Body: <p>I am not sure I understand your question correctly but you can extract the video and audio stream, format them the way you want and then re-multiplex them all with <code>ffmpeg</code>. </p>
  
  <pre><code>ffmpeg -i input.mp4 -c:v copy -an video_only.mp4
  </code></pre>
  
  <p>The <code>-an</code> option is disabling the audio <code>-c:v copy</code> is copying your video stream to <code>video_only.mp4</code>.</p>
  
  <pre><code>ffmpeg -i input.mp4 -c:a copy -vn audio_only.mp4
  </code></pre>
  
  <p>Here you do the same but for the audio.</p>
  
  <p>Please note that 1 frame is different than 1 millisecond. The duration of your frame depends on the frame rate but usually is between 16,(6)ms for 60fps (1/60) content and 41,(6)ms for 24fps (1/24) You can have 1ms frame only if your video is 1000fps which I really doubt it is. The audio, on the other hand, has a normally 44100Hz or 48000Hz sampling rate, which means that the minimum sample duration with 48KHz is 2.08(3)E-5 seconds.</p>
  
  <p>When you are done you can multiplex the new video and new audio together by: </p>
  
  <pre><code>ffmpeg -i new_video.mp4 -i new_audio.mp4 -c copy audio_and_video.mp4
  </code></pre>
  
  <p>In order for this to work you need to have the same duration of both input streams though.</p>
  
  <p>You can also concatenate a static picture to the video file. You can create your image.mp4 file with: </p>
  
  <pre><code>ffmpeg -i &lt;static_picture.jpg&gt; -c:v libx264 -s 1920x1080 -r 50 -t 0.02 -pix_fmt yuv420p image.mp4
  </code></pre>
  
  <p>This will create an <code>image.mp4</code> video with a duration of 20 ms (1-frame) with a frame rate of 50, encoded with <code>libx264</code> and resolution 1920x1080 using pixel format YUV420p which you most likely need. </p>
  
  <p>Then you can concatenate both files by: </p>
  
  <pre><code>ffmpeg -i "concat:image.mp4|original_video.mp4" -c copy output.mp4
  </code></pre>
  
  <p>Make sure that the frame rate, resolution and pixel format of the <code>image.mp4</code> and <code>original_video.mp4</code> match otherwise it won't work. </p>
  
  <p>[EDIT 17.11.2019] Apparently in your case you need to use the concat filter which also will require re-encoding of the audio and video. So the commands are the following: </p>
  
  <pre><code>ffmpeg -i &lt;static_picture.jpg&gt; -f lavfi -i anullsrc -c:v libx264 -s 256x144 -r 25 -t 0.04 -pix_fmt yuv420p -c:a aac -ac 2 -ar 44100 -shortest &lt;image.mp4&gt;
  </code></pre>
  
  <p>This command will create one frame long video with an empty audio stream, presuming that the second video is having 25fps. Please note that in your question the ffmpeg output of your input file is 25fps (<code>tbr</code>) and not 30fps, as you have presumed. I am also setting the number of channels to two: <code>-ac 2</code> and the sample rate to 44.1KHz. The number of channels and the sample rate should match between both videos. More information about the <code>anullsrc</code> can be found here: <a href="https://trac.ffmpeg.org/wiki/Null" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Null</a>
  Then you can concatenate and encode the video with the following command:</p>
  
  <pre><code>ffmpeg -i &lt;image.mp4&gt; -i &lt;second_video.mp4&gt; -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=2:v=1:a=1[v][a]" -c:v libx264 -b:v 100k -map "[v]" -map "[a]" &lt;output.mp4&gt;
  </code></pre>
  
  <p>Here I am taking both the video and audio streams from both video files and I am merging them to the output file and setting the video encoding bitrate to 100Kbps, the bitrate of your original video is 96Kbps and I have let ffmpeg decide how to encode the audio. You can change that if you want by defining codec, number of channels, sample rate. More information about the concat filter could be found here: <a href="https://trac.ffmpeg.org/wiki/Concatenate" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Concatenate</a> </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T16:13:23.993Z
Answers.Text: "Make sure that the frame rate, resolution and pixel format match" How do I do this for a low-quality video 140p and a 30fps? Can you give an example of pixel format?
  
  I think all I need to do is to convert `pic.png` to `pic.mp4` then concatinate it with the video, right?
Answers.UserDisplayName: Youssof
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T23:10:58.950Z
Answers.Text: The concat protocol is not recommended for MP4 (the second video will likely not play). Use the concat demuxer instead.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T23:13:55.787Z
Answers.Text: @YoussofH. It is not trivial, but it is possible (disregarding any possible issues from such a short duration requirement). You need to match all of the attributes. Updating your question with the complete log of `ffmpeg -i input` will show the information needed to provide an answer for rote usage.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T09:03:14.403Z
Answers.Text: As @llogan said the concat protocol is not the solution here. Although I tried 3 different concatinations from a previos post but none worked although when I used demuxer the videos were merged but had no sound sadly. Any hints?
Answers.UserDisplayName: Youssof
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T11:05:17.983Z
Answers.Text: please post your whole line in the main topic as well as the output of `ffprobe -hide_banner -i <output.mp4>` where `<output.mp4> is the name of your merged file.
Answers.UserDisplayName: Georgi Stoyanov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-16T02:23:01.027Z
Answers.Text: Did you check my edit? If not please do.
Answers.UserDisplayName: Youssof
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-17T18:57:12.350Z
Answers.Text: Please check the edit in my original answer to see the commands for concatenating both files. I have tested it on my machine and it works well.
Answers.UserDisplayName: Georgi Stoyanov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T15:58:23.027Z
Answers.LastActivityDate: 2019-11-17T18:56:15.017Z
Answers.LastEditDate: 2019-11-17T18:56:15.017Z
Answers.UserDisplayName: Georgi Stoyanov
Body: <p>I need to add an image (1 frame maybe) for one millisecond at the start of the mp4 video.</p>
  
  <p>The final video should contain audio in the AAC system.</p>
  
  <p>I expect no delay in the audio while the video plays. I would like to have silence at first for one millisecond to avoid lagging video.</p>
  
  <blockquote>
    <p>OS: Linux/Debian</p>
  </blockquote>
  
  <p><strong>Edit:</strong></p>
  
  <p>I converted the first image to an mp4 video with <code>ffmpeg -i &lt;static_picture.jpg&gt; -c:v libx264 -s 256x144 -r 30 -t 0.03 -pix_fmt yuv420p image.mp4</code></p>
  
  <p>I merged the two videos by <strong><a href="https://stackoverflow.com/a/11175851/4061346">concat demuxer</a></strong> but the video submitted has no sound.</p>
  
  <p>The result of <code>ffprobe -hide_banner -i Video.mp4</code> is:</p>
  
  <pre><code>Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Video.mp4':
    Metadata:
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf58.20.100
    Duration: 00:03:52.40, start: 0.000000, bitrate: 96 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 256x144 [SAR 1:1 DAR 16:9], 94 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      Metadata:
        handler_name    : VideoHandler
  </code></pre>
  
Tags: <ffmpeg>
Title: FFMPEG add image at beginning of MP4 as first frame
UserDisplayName: Youssof
ThreadText: # FFMPEG add image at beginning of MP4 as first frame
  
  (Asked by: username_0 on 2019-11-12)
  
  I need to add an image (1 frame maybe) for one millisecond at the start of the mp4 video.
  
  The final video should contain audio in the AAC system.
  
  I expect no delay in the audio while the video plays. I would like to have silence at first for one millisecond to avoid lagging video.
  
  > OS: Linux/Debian
  
  **Edit:**
  
  I converted the first image to an mp4 video with `ffmpeg -i <static_picture.jpg> -c:v libx264 -s 256x144 -r 30 -t 0.03 -pix_fmt yuv420p image.mp4`
  
  I merged the two videos by **[concat demuxer](https://stackoverflow.com/a/11175851/4061346)** but the video submitted has no sound.
  
  The result of `ffprobe -hide_banner -i Video.mp4` is:
  
  ```
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Video.mp4':
    Metadata:
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf58.20.100
    Duration: 00:03:52.40, start: 0.000000, bitrate: 96 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 256x144 [SAR 1:1 DAR 16:9], 94 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      Metadata:
        handler_name    : VideoHandler
  
  ```
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-12. Score: 3
  
  I am not sure I understand your question correctly but you can extract the video and audio stream, format them the way you want and then re-multiplex them all with `ffmpeg`.
  
  ```
  ffmpeg -i input.mp4 -c:v copy -an video_only.mp4
  
  ```
  
  The `-an` option is disabling the audio `-c:v copy` is copying your video stream to `video_only.mp4`.
  
  ```
  ffmpeg -i input.mp4 -c:a copy -vn audio_only.mp4
  
  ```
  
  Here you do the same but for the audio.
  
  Please note that 1 frame is different than 1 millisecond. The duration of your frame depends on the frame rate but usually is between 16,(6)ms for 60fps (1/60) content and 41,(6)ms for 24fps (1/24) You can have 1ms frame only if your video is 1000fps which I really doubt it is. The audio, on the other hand, has a normally 44100Hz or 48000Hz sampling rate, which means that the minimum sample duration with 48KHz is 2.08(3)E-5 seconds.
  
  When you are done you can multiplex the new video and new audio together by:
  
  ```
  ffmpeg -i new_video.mp4 -i new_audio.mp4 -c copy audio_and_video.mp4
  
  ```
  
  In order for this to work you need to have the same duration of both input streams though.
  
  You can also concatenate a static picture to the video file. You can create your image.mp4 file with:
  
  ```
  ffmpeg -i <static_picture.jpg> -c:v libx264 -s 1920x1080 -r 50 -t 0.02 -pix_fmt yuv420p image.mp4
  
  ```
  
  This will create an `image.mp4` video with a duration of 20 ms (1-frame) with a frame rate of 50, encoded with `libx264` and resolution 1920x1080 using pixel format YUV420p which you most likely need.
  
  Then you can concatenate both files by:
  
  ```
  ffmpeg -i "concat:image.mp4|original_video.mp4" -c copy output.mp4
  
  ```
  
  Make sure that the frame rate, resolution and pixel format of the `image.mp4` and `original_video.mp4` match otherwise it won't work.
  
  [EDIT 17.11.2019] Apparently in your case you need to use the concat filter which also will require re-encoding of the audio and video. So the commands are the following:
  
  ```
  ffmpeg -i <static_picture.jpg> -f lavfi -i anullsrc -c:v libx264 -s 256x144 -r 25 -t 0.04 -pix_fmt yuv420p -c:a aac -ac 2 -ar 44100 -shortest <image.mp4>
  
  ```
  
  This command will create one frame long video with an empty audio stream, presuming that the second video is having 25fps. Please note that in your question the ffmpeg output of your input file is 25fps (`tbr`) and not 30fps, as you have presumed. I am also setting the number of channels to two: `-ac 2` and the sample rate to 44.1KHz. The number of channels and the sample rate should match between both videos. More information about the `anullsrc` can be found here: <https://trac.ffmpeg.org/wiki/Null>
  Then you can concatenate and encode the video with the following command:
  
  ```
  ffmpeg -i <image.mp4> -i <second_video.mp4> -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=2:v=1:a=1[v][a]" -c:v libx264 -b:v 100k -map "[v]" -map "[a]" <output.mp4>
  
  ```
  
  Here I am taking both the video and audio streams from both video files and I am merging them to the output file and setting the video encoding bitrate to 100Kbps, the bitrate of your original video is 96Kbps and I have let ffmpeg decide how to encode the audio. You can change that if you want by defining codec, number of channels, sample rate. More information about the concat filter could be found here: <https://trac.ffmpeg.org/wiki/Concatenate>
  
  > **Comments:**
  > **username_0**: "Make sure that the frame rate, resolution and pixel format match" How do I do this for a low-quality video 140p and a 30fps? Can you give an example of pixel format?  I think all I need to do is to convert `pic.png` to `pic.mp4` then concatinate it with the video, right?  
  > **username_2**: The concat protocol is not recommended for MP4 (the second video will likely not play). Use the concat demuxer instead.  
  > **username_2**: @YoussofH. It is not trivial, but it is possible (disregarding any possible issues from such a short duration requirement). You need to match all of the attributes. Updating your question with the complete log of `ffmpeg -i input` will show the information needed to provide an answer for rote usage.  
  > **username_0**: As @username_2 said the concat protocol is not the solution here. Although I tried 3 different concatinations from a previos post but none worked although when I used demuxer the videos were merged but had no sound sadly. Any hints?  
  > **username_1**: please post your whole line in the main topic as well as the output of `ffprobe -hide_banner -i <output.mp4>` where `<output.mp4> is the name of your merged file.  
  > **username_0**: Did you check my edit? If not please do.  
  > **username_1**: Please check the edit in my original answer to see the commands for concatenating both files. I have tested it on my machine and it works well.  
  
  ---
  
  