我正在尝试使用命令行中的 ffmpeg 从我的 IP 摄像机流录制视频。
fmpeg -rtsp_transport tcp \
> -i rtsp://192.168.0.250/stream1 \
> -c copy \
> -map 0 \
> -f segment \
> -segment_time 60 \
> -segment_format mp4 \
> "/home/video/stream-%010d.mp4"
并得到以下输出:
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, rtsp, from 'rtsp://192.168.0.250/stream1':
Metadata:
title : Session streamed by "nessyMediaServer"
comment : h264
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 2048x1536 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Data: none
[segment @ 0x559e20000980] Opening '/home/video/stream-0000000000.mp4' for writing
[mp4 @ 0x559e1fffc180] Could not find tag for codec none in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Last message repeated 1 times
尝试了一些不同的选项,如 -c:v libx265 或 -c:v libx264,但不起作用,输出略有不同。但主要错误是相同的:
Could not find tag for codec none in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
然后我尝试改变输出格式:
ffmpeg -rtsp_transport tcp \
-i rtsp://192.168.0.250/stream1 \
-c copy \
-map 0 \
-f segment \
-segment_time 60 \
-segment_format avi \
"/home/video/stream-%010d.avi"
它开始录制视频(录制了 2 个损坏的视频文件)但出现错误:
fmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, rtsp, from 'rtsp://192.168.0.250/stream1':
Metadata:
title : Session streamed by "nessyMediaServer"
comment : h265
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt709), 2048x1536 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1: Data: none
[segment @ 0x562200721d80] Opening '/home/evgeniy/video/stream-0000000000.avi' for writing
Output #0, segment, to '/home/video/stream-%010d.avi':
Metadata:
title : Session streamed by "nessyMediaServer"
comment : h265
encoder : Lavf58.29.100
Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt709), 2048x1536 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Data: none
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[segment @ 0x562200721d80] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[segment @ 0x562200721d80] Non-monotonous DTS in output stream 0:0; previous: 202, current: 202; changing to 203. This may result in incorrect timestamps in the output file.
...
[segment @ 0x562200721d80] Non-monotonous DTS in output stream 0:0; previous: 748, current: 748; changing to 749. This may result in incorrect timestamps in the output file.
[segment @ 0x562200721d80] Opening '/home/video/stream-0000000001.avi' for writing
[avi @ 0x56220077d800] Too large number of skipped frames 5417887 > 6000001x
av_interleaved_write_frame(): Invalid argument
[avi @ 0x56220077d800] Too large number of skipped frames 5407879 > 60000
frame= 1505 fps= 25 q=-1.0 Lsize=N/A time=00:01:00.24 bitrate=N/A speed=1.01x
video:5314kB audio:0kB subtitle:0kB other streams:359kB global headers:0kB muxing overhead: unknown
Conversion failed!
我尝试过:添加一些不同的键(一次一个)-fflags +genpts
,,,,这些都不起作用。还尝试过输出视频文件-use_wallclock_as_timestamps 1
,但它们都已损坏。我还能尝试什么来从 rtsp 保存视频?-thread_queue_size 512
-vsync 0 -enc_time_base -1
-reset_timestamps 1
答案1
流#0:1 是未知数据,但 MP4 复用器不知道如何处理它。
-map 0
通过更改为 来仅映射视频-map 0:v
。- 或者
-map 0
通过添加来保留并省略数据流-map -0:d
。