title: Concatenate a video, image and audio using ffmpeg
body: <p>I am trying to concatenate a group of images with associated audio with a video clip at the start and front of the video. Whenever I concatenate the image with the associated audio it dosen't playback correctly in VLC media player and only displays the image for a frame before cutting to black and continually playing audio. I came across this github issue: <a href="https://github.com/kkroening/ffmpeg-python/issues/274" rel="nofollow noreferrer">https://github.com/kkroening/ffmpeg-python/issues/274</a> where the accepted solution was the one I implemented but one of the comments mentioned this issue of incorrect playback and error on youtube.</p>
  <pre><code>'''
  Generates a clip from an image and a wav file, helper function for export_video
  '''
  def generate_clip(img):
      transition_cond = os.path.exists(&quot;static/transitions/&quot; + img + &quot;.mp4&quot;)
      chart_path = os.path.exists(&quot;charts/&quot; + img + &quot;.png&quot;)
      if transition_cond:
          clip = ffmpeg.input(&quot;static/transitions/&quot; + img + &quot;.mp4&quot;)
      elif chart_path:
          clip = ffmpeg.input(&quot;charts/&quot; + img + &quot;.png&quot;)
      else:
          clip = ffmpeg.input(&quot;static/transitions/Transition.jpg&quot;)
      audio_clip = ffmpeg.input(&quot;audio/&quot; + img + &quot;.wav&quot;)
      clip = ffmpeg.concat(clip, audio_clip, v=1, a=1)
      clip = ffmpeg.filter(clip, &quot;setdar&quot;,&quot;16/9&quot;)
      return clip
  
  '''
  Combines the charts from charts/ and the audio from audio/ to generate one final video that will be uploaded to Youtube
  '''
  def export_video(CHARTS):
      clips = []
      intro = generate_clip(&quot;Intro&quot;)
      clips.append(intro)
  
      for key in CHARTS.keys():
          value = CHARTS.get(key)
          value.insert(0, key)
          subclip = []
          for img in value:
              subclip.append(generate_clip(img))
          concat_clip = ffmpeg.concat(*subclip)
          clips.append(concat_clip)
      
      outro = generate_clip(&quot;Outro&quot;)
      clips.append(outro)
  
      concat_clip = ffmpeg.concat(*clips)
      concat_clip.output(&quot;export/export.mp4&quot;).run(overwrite_output=True)
  </code></pre>