Answers.Body: <p>This is fairly straightforward if you save to a streaming format like <a href="https://en.wikipedia.org/wiki/Flash_Video" rel="nofollow noreferrer">Flash Video (FLV)</a> or <a href="https://en.wikipedia.org/wiki/MPEG_transport_stream" rel="nofollow noreferrer">MPEG-Transport Stream (MPEG-TS)</a>.</p>
  
  <p>Let's say this is your full feed capture command</p>
  
  <pre><code>ffmpeg -i source {-transcoding options} localfile.flv
  </code></pre>
  
  <p>You can then run</p>
  
  <pre><code>ffmpeg -ss 6:12 -i localfile.flv -t 1:05 -c copy extract.mp4
  </code></pre>
  
  <p>Ideally, the stream should be past 7:17 or close to it when you run the latter command. Note that since the 2nd command doesn't transcode, inpoint seek isn't precise. The extract will start from the nearest keyframe earlier to the specified inpoint.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-04-06T09:22:59.907Z
Answers.LastActivityDate: 2018-06-13T09:38:06.323Z
Answers.LastEditDate: 2018-06-13T09:38:06.323Z
Answers.UserDisplayName: Gyan
Body: <p>A client wants me to write some software, perhaps <strong>ffmpeg</strong> wrapped in scripting, which will monitor a streaming video feed, and copy clips from it in near real-time, delivering them as self-contained video files. It is not acceptable for me to wait for the feed to finish, and the video to be completely stored as a local file, before I copy the clips. On the other hand, I can take say tens of seconds after the end time of the clip before delivering it. Can I do this without building a video processing suite from scratch? Do I need to require that the streaming video feed be a certain format?</p>
  
  <p>So say the video feed is of a 1-hour live event. At some point, maybe 5 minutes in, my software may get the command, "clip from 4 minutes 30 seconds to 6 minutes 0 seconds, save as file X.mpg". I have to tap into the video feed, copy 90 seconds of video, and store it as file X.mpg, by about 7 minutes in.  The actual times are more flexible, I just want to emphasise that I must be able to tap into the streaming feed in progress, I can't wait for a static video file.</p>
  
  <p>I don't even know if streaming video formats permit this kind of operation. If a receiver writes the feed to disc, will the beginning of the file be legal syntax which a normal tool like <strong>ffmpeg</strong> can parse?  </p>
  
  <p>I don't know details of encoding formats, but I understand that they store key frames every so often, and intermediate video frames are stored as differences from the key frame and/or preceding frames. Is it important to know when the key frames are added?  Can normal tools parse video past the most recent key frame to the frame just being written, or would the data in the stored file be still be in some temporary state, and thus not yet parseable?</p>
  
  <p>Or, is copying video clips from streaming video a difficult task which requires more sophisticated software than <strong>ffmpeg</strong> or the like, wrapped with scripts?</p>
  
  <p>Advice on specific formats, and tool chains which make this possible are welcome.</p>
  
Tags: <video><ffmpeg><editing><streaming>
Title: How can I extract clips from a streaming video feed in near real-time?
UserDisplayName: Jim DeLaHunt
ThreadText: # How can I extract clips from a streaming video feed in near real-time?
  
  (Asked by: username_0 on 2018-04-06)
  
  A client wants me to write some software, perhaps **ffmpeg** wrapped in scripting, which will monitor a streaming video feed, and copy clips from it in near real-time, delivering them as self-contained video files. It is not acceptable for me to wait for the feed to finish, and the video to be completely stored as a local file, before I copy the clips. On the other hand, I can take say tens of seconds after the end time of the clip before delivering it. Can I do this without building a video processing suite from scratch? Do I need to require that the streaming video feed be a certain format?
  
  So say the video feed is of a 1-hour live event. At some point, maybe 5 minutes in, my software may get the command, "clip from 4 minutes 30 seconds to 6 minutes 0 seconds, save as file X.mpg". I have to tap into the video feed, copy 90 seconds of video, and store it as file X.mpg, by about 7 minutes in. The actual times are more flexible, I just want to emphasise that I must be able to tap into the streaming feed in progress, I can't wait for a static video file.
  
  I don't even know if streaming video formats permit this kind of operation. If a receiver writes the feed to disc, will the beginning of the file be legal syntax which a normal tool like **ffmpeg** can parse?
  
  I don't know details of encoding formats, but I understand that they store key frames every so often, and intermediate video frames are stored as differences from the key frame and/or preceding frames. Is it important to know when the key frames are added? Can normal tools parse video past the most recent key frame to the frame just being written, or would the data in the stored file be still be in some temporary state, and thus not yet parseable?
  
  Or, is copying video clips from streaming video a difficult task which requires more sophisticated software than **ffmpeg** or the like, wrapped with scripts?
  
  Advice on specific formats, and tool chains which make this possible are welcome.
  
  **Tags:** video, ffmpeg, editing, streaming
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-06. Score: 1
  
  This is fairly straightforward if you save to a streaming format like [Flash Video (FLV)](https://en.wikipedia.org/wiki/Flash_Video) or [MPEG-Transport Stream (MPEG-TS)](https://en.wikipedia.org/wiki/MPEG_transport_stream).
  
  Let's say this is your full feed capture command
  
  ```
  ffmpeg -i source {-transcoding options} localfile.flv
  
  ```
  
  You can then run
  
  ```
  ffmpeg -ss 6:12 -i localfile.flv -t 1:05 -c copy extract.mp4
  
  ```
  
  Ideally, the stream should be past 7:17 or close to it when you run the latter command. Note that since the 2nd command doesn't transcode, inpoint seek isn't precise. The extract will start from the nearest keyframe earlier to the specified inpoint.
  
  
  ---
  
  