Recording and watching a stream simultaneously

Issues involving a Windows version of FFmpeg. Do not post general usage questions here.
jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Recording and watching a stream simultaneously

Postby jackb » Fri Mar 03, 2017 3:34 pm

Hi,

I grab a video stream (H.264/AVC) with this command:

Code: Select all

ffmpeg.exe -i %streamURL% -c copy -bsf:a aac_adtstoasc %filename%


This works fine, but I would like to watch the video simultaneously, i.e. with ffplay.

Is this possible?

Thanks for any hint.

jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Re: Recording and watching a stream simultaneously

Postby jackb » Wed Mar 08, 2017 9:40 am

Meanwhile I found something that works:

Code: Select all

ffmpeg -i %streamURL% -c copy -f mpegts udp://224.0.0.1:1234/ -c copy %filename%

ffplay udp://224.0.0.1:1234

not sure whether -f mpegts is the right option for H.264, but -f mp4 doesn't work.
ffplay shows many "MV errors in P frame", but the video seems to be ok.

llogan
Posts: 309
Joined: Fri Mar 14, 2014 3:29 am

Re: Recording and watching a stream simultaneously

Postby llogan » Wed Mar 08, 2017 7:51 pm

What is the actual output file name? You only listed %filename%.

jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Re: Recording and watching a stream simultaneously

Postby jackb » Thu Mar 09, 2017 10:21 am

%filename% is the name of the output file.

llogan
Posts: 309
Joined: Fri Mar 14, 2014 3:29 am

Re: Recording and watching a stream simultaneously

Postby llogan » Thu Mar 09, 2017 6:24 pm

Let me ask the question differently then. What muxer and encoder(s) are you using? If you are unsure then provide the complete console output from the ffmpeg command. Please copy and paste the text instead of making an image of the text.

jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Re: Recording and watching a stream simultaneously

Postby jackb » Fri Mar 10, 2017 9:42 am

The console output is this:

Code: Select all

ffmpeg -i "http://..." -c copy -f mpegts udp://224.0.0.1:1234/
-c copy outputfile.mp4
ffmpeg version N-83507-g8fa18e0 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --e
nable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --
enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-li
bfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug -
-enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enabl
e-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li
bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolam
e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable
-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 47.100 / 55. 47.100
  libavcodec     57. 80.100 / 57. 80.100
  libavformat    57. 66.102 / 57. 66.102
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 73.100 /  6. 73.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
[NULL @ 0000000000505ae0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] non-existing PPS 0 referenced
[h264 @ 00000000005089a0] decode_slice_header error
[h264 @ 00000000005089a0] no frame!
Input #0, hls,applehttp, from 'http://...':
  Duration: N/A, start: 21198.278611, bitrate: N/A
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470b
g), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, flt
p
    Metadata:
      variant_bitrate : 0
    Stream #0:2: Data: timed_id3 (ID3  / 0x20334449)
    Metadata:
      variant_bitrate : 0
Output #0, mpegts, to 'udp://224.0.0.1:1234/':
  Metadata:
    encoder         : Lavf57.66.102
    Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470b
g), 852x480 [SAR 640:639 DAR 16:9], q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, flt
p
    Metadata:
      variant_bitrate : 0
Output #1, mp4, to 'outputfile.mp4':
  Metadata:
    encoder         : Lavf57.66.102
    Stream #1:0: Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p(tv, bt470b
g), 852x480 [SAR 640:639 DAR 16:9], q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
    Metadata:
      variant_bitrate : 0
    Stream #1:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, flt
p
    Metadata:
      variant_bitrate : 0
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:0 -> #1:0 (copy)
  Stream #0:1 -> #1:1 (copy)
Press [q] to stop, [?] for help
frame=  325 fps=0.0 q=-1.0 q=-1.0 size=    2539kB time=00:00:13.23 bitrate=1571.
frame=  605 fps=604 q=-1.0 q=-1.0 size=    4763kB time=00:00:24.42 bitrate=1597.
frame=  751 fps= 75 q=-1.0 q=-1.0 size=    5913kB time=00:00:30.26 bitrate=1600.
frame= 1001 fps= 50 q=-1.0 q=-1.0 size=    7926kB time=00:00:40.26 bitrate=1612.
frame= 1249 fps= 61 q=-1.0 q=-1.0 size=    9901kB time=00:00:50.20 bitrate=1615.
frame= 1249 fps= 33 q=-1.0 q=-1.0 size=    9901kB time=00:00:50.22 bitrate=1614.
frame= 1501 fps= 39 q=-1.0 q=-1.0 size=   11917kB time=00:01:00.26 bitrate=1620.
frame= 1751 fps= 36 q=-1.0 q=-1.0 size=   13901kB time=00:01:10.26 bitrate=1620.
8kbits/s speed=1.46x


After some testing this seems to work for me. The output file can be played with all my players.

However the udp stream can only be played well with FFplay. Other players like MPC-BE, SMPlayer or VLC open the stream, but fail to play it smoothly. This may be a question of player configuration. Or is there an option for FFmpeg to provide the stream better usable for other players?

llogan
Posts: 309
Joined: Fri Mar 14, 2014 3:29 am

Re: Recording and watching a stream simultaneously

Postby llogan » Fri Mar 10, 2017 7:43 pm

Why not just view the input?

Code: Select all

ffplay "http://..."

If that's not an option then do you require that the output for the player must be a network stream?

jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Re: Recording and watching a stream simultaneously

Postby jackb » Mon Mar 13, 2017 11:40 am

llogan wrote:Why not just view the input?

Code: Select all

ffplay "http://..."

I want to write an app for watching live streams and with the option to record/watch a stream at the same time. The best tool I found for this is VLC player. Especially the output file can be accessed instantly by other programs, time shift is possible. But VLC player has a very high CPU load compared to FFmpeg, and therefore I would prefer FFmpeg if possible.

The solution

Code: Select all

ffmpeg -i %streamURL% -c copy -f mpegts udp://224.0.0.1:1234/ -c copy %filename%

ffplay udp://224.0.0.1:1234

works, but FFplay is very basic, I miss: always on top, keep aspect ratio on resize, hide title bar, move window by dragging any point of the window. This can be enhanced by e.g. AutoHotkey, but the result is not as good as if natively supportet.

llogan wrote:If that's not an option then do you require that the output for the player must be a network stream?

Is there an alternative?

It would help, if there would be an option to force FFmpeg to write the stream to disk in a way that allows other programs to play it instantly.

jackb
Posts: 6
Joined: Fri Mar 03, 2017 3:25 pm

Re: Recording and watching a stream simultaneously

Postby jackb » Wed Mar 15, 2017 9:04 am

Now I found, with the option

Code: Select all

-movflags frag_keyframe
the stream is written to disk in a way that allows other programs to play it instantly.

And the high CPU usage while streaming in VLC player I mentioned is a bug in the current version, which is fixed in the latest nightly builds.

So, it looks like I have a solution. Thanks for your attention.


Return to “Usage Issues”

Who is online

Users browsing this forum: No registered users and 1 guest