Body: <p>this is my first post (<em>on video.stackexchange.com</em>).</p>
  
  <p>I need some explanation regarding to re-encoding a <strong>single</strong> .ts chunk and then use <code>cat</code> command.</p>
  
  <p>I'll explain my scenario.</p>
  
  <p>I've a  lot of <code>.ts</code> chunks that all together create a smooth video. Tested.</p>
  
  <p>To create a single video I use the classic linux <code>cat</code> command, and everything works a treat.</p>
  
  <p><strong>BUT</strong></p>
  
  <p>These "<em>lot of <code>.ts</code> chunks</em>" reside on a web-hosting where, obviously, it is not possible to install ffmpeg, <strong>but I can use <code>cat</code></strong> command (through PHP's <code>shell_exec</code>).</p>
  
  <hr>
  
  <p><strong>My goal</strong> 
  is to apply an audio/video fade-in on first chunk (and so far I've done it with <code>-vf "fade=t=in:st=0.1:d=1"</code> and <code>-af "afade=t=in:st=0.1:d=1"</code>) on my local machine and then, after uploaded the "faded chunk" on remote web-hosting, <code>cat</code> the faded chunk + remaing chunks.</p>
  
  <hr>
  
  <p><strong>My actual results</strong> </p>
  
  <p>My concatenated-chunks-video has a frame-gap at the end of the "faded chunk" and the beginning of the next chunk. After this, plays smoothly.</p>
  
  <hr>
  
  <p><strong>CLI</strong></p>
  
  <pre><code>ffmpeg -i /path/to/first_chunk.ts -vf "fade=t=in:st=0.1:d=1, format=yuv420p" -af "afade=t=in:st=0.1:d=1" -c:v libx264 -b:v 5099.998K -profile:v main -level:v 4.0 -c:a aac -b:a 279000 -strict experimental -y /path/to/first_chunk_fade_in.ts
  
  cat /path/to/first_chunk_fade_in.ts /path/to/2nd_chunk.ts /path/to/3rd_chunk.ts /path/to/4th_chunk.ts /path/to/5th_chunk.ts &gt; /path/to/merged.ts
  </code></pre>
  
  <p>Note:</p>
  
  <p>All <code>-c:v</code>, <code>-b:v</code>, <code>-profile:v</code>, <code>-level:v</code>, <code>-c:a</code>, <code>-b:a</code> values were recovered and / or calculated from the original chunk using <code>ffprobe</code></p>
  
  <hr>
  
  <p>Any ideas? Or do I have to re-encode the whole file?</p>
  
  <p>Many thanks</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T18:52:45.947Z
Comments.Text: Add -copyts and check.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T18:56:45.033Z
Comments.Text: I try immediately....
Comments.UserDisplayName: Oscar Zarrus
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T19:10:35.093Z
Comments.Text: With -copyts I lose the fade
Comments.UserDisplayName: Oscar Zarrus
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T19:48:33.623Z
Comments.Text: Instead of `st`, use the start frame and sample options instead.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T21:45:46.387Z
Comments.Text: same thing. Ok for fade but gap remains. I believe, however, that problem is not attributable to the video stream, but rather to the audio track. I explain to you. I open the merged file with VLC. 
  Starting from the beginning of the stream, if I PLAY, there's the gap, but if I make a frame-by-frame (shortcut "e" on VLC), no gap occurs and everything runs smoothly. Since VLC does not handle audio on the frame-by-frame (the video becomes mute), I think it's the audio track "in some way" carries with it the video track trying to "put it in sync", creating this little hop in the junction point.
Comments.UserDisplayName: Oscar Zarrus
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T21:45:54.007Z
Comments.Text: I also tried to disable the audio fade and leave the video track with `-c:a copy`.
  
  What I'm sure of is that the audio track, once the chunk is encoded, doesn't start at 0 like the original chunk, but after a few ms
Comments.UserDisplayName: Oscar Zarrus
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-11T05:01:10.357Z
Comments.Text: Explain what you mean by gap.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-11T07:07:42.227Z
Comments.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/92296/discussion-between-oscar-zarrus-and-gyan).
Comments.UserDisplayName: Oscar Zarrus
Tags: <ffmpeg><mpeg-dash>
Title: FFmpeg: apply audio/video fade-in on the first TS chunk, then "cat" all chunks produces a frame loss
UserDisplayName: Oscar Zarrus
ThreadText: # FFmpeg: apply audio/video fade-in on the first TS chunk, then "cat" all chunks produces a frame loss
  
  (Asked by: username_0 on 2019-04-10)
  
  this is my first post (*on video.stackexchange.com*).
  
  I need some explanation regarding to re-encoding a **single** .ts chunk and then use `cat` command.
  
  I'll explain my scenario.
  
  I've a lot of `.ts` chunks that all together create a smooth video. Tested.
  
  To create a single video I use the classic linux `cat` command, and everything works a treat.
  
  **BUT**
  
  These "*lot of `.ts` chunks*" reside on a web-hosting where, obviously, it is not possible to install ffmpeg, **but I can use `cat`** command (through PHP's `shell_exec`).
  
  ---
  
  **My goal**
  is to apply an audio/video fade-in on first chunk (and so far I've done it with `-vf "fade=t=in:st=0.1:d=1"` and `-af "afade=t=in:st=0.1:d=1"`) on my local machine and then, after uploaded the "faded chunk" on remote web-hosting, `cat` the faded chunk + remaing chunks.
  
  ---
  
  **My actual results**
  
  My concatenated-chunks-video has a frame-gap at the end of the "faded chunk" and the beginning of the next chunk. After this, plays smoothly.
  
  ---
  
  **CLI**
  
  ```
  ffmpeg -i /path/to/first_chunk.ts -vf "fade=t=in:st=0.1:d=1, format=yuv420p" -af "afade=t=in:st=0.1:d=1" -c:v libx264 -b:v 5099.998K -profile:v main -level:v 4.0 -c:a aac -b:a 279000 -strict experimental -y /path/to/first_chunk_fade_in.ts
  
  cat /path/to/first_chunk_fade_in.ts /path/to/2nd_chunk.ts /path/to/3rd_chunk.ts /path/to/4th_chunk.ts /path/to/5th_chunk.ts > /path/to/merged.ts
  
  ```
  
  Note:
  
  All `-c:v`, `-b:v`, `-profile:v`, `-level:v`, `-c:a`, `-b:a` values were recovered and / or calculated from the original chunk using `ffprobe`
  
  ---
  
  Any ideas? Or do I have to re-encode the whole file?
  
  Many thanks
  
  **Tags:** ffmpeg, mpeg-dash
  
  > **Comments:**
  > **username_1**: Add -copyts and check.  
  > **username_0**: I try immediately....  
  > **username_0**: With -copyts I lose the fade  
  > **username_1**: Instead of `st`, use the start frame and sample options instead.  
  > **username_0**: same thing. Ok for fade but gap remains. I believe, however, that problem is not attributable to the video stream, but rather to the audio track. I explain to you. I open the merged file with VLC.  Starting from the beginning of the stream, if I PLAY, there's the gap, but if I make a frame-by-frame (shortcut "e" on VLC), no gap occurs and everything runs smoothly. Since VLC does not handle audio on the frame-by-frame (the video becomes mute), I think it's the audio track "in some way" carries with it the video track trying to "put it in sync", creating this little hop in the junction point.  
  > **username_0**: I also tried to disable the audio fade and leave the video track with `-c:a copy`.  What I'm sure of is that the audio track, once the chunk is encoded, doesn't start at 0 like the original chunk, but after a few ms  
  > **username_1**: Explain what you mean by gap.  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/92296/discussion-between-username_0-and-username_1).  
  
  ---
  
  ## 0 answers
  
  