Cannot retrieve duration of webm file using ffmpeg - ffmpeg

I am trying to retrieve the duration of a .webm video file that I recorded using the the video.js plugin (https://github.com/collab-project/videojs-record).
I am using ffmpeg to get the duration but it always return N/A:
ffprobe version 3.0.2-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2007-2016 the FFmpeg developers
built with gcc 5.3.1 (Debian 5.3.1-16) 20160424
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr --enable-frei0r --enable-libfribidi --disable-indev=sndio --disable-outdev=sndio --enable-librtmp --enable-libmfx --enable-libzimg --cc=gcc
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, matroska,webm, from '/home/demoss/public_html/source/bALRt9I697PVQh4zglou.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Stream #0:1(eng): Audio: opus, 48000 Hz, mono, fltp (default)
duration=N/A
I don't think the video is corrupted as it played in my VideoJS player without issues.
Any pointers as to why its not returning the duration would be greatly appreciated. I wouldn't mind using an alternative library as well
Thanks

If ffprobe/ffmpeg does not show the format or stream durations then you can fully decode the file to find the duration:
ffmpeg -i input.webm -f null -
...
frame= 2087 fps=0.0 q=-0.0 Lsize=N/A time=00:01:23.48 bitrate=N/A speed= 123x
Refer to time= in the second-to-last line in the output. In this example the file duration is 00:01:23.48.
Depending on the duration and complexity of your input this may take some time.
Also see FFmpeg Wiki: FFprobe Tips - Duration.

I was able to convert the webm to mp4 using the following command:
ffmpeg -fflags +genpts -i myfile.webm -r 24 mynew.mp4
I am not quite sure of how it works internally, but I hope the experts could expand on this.
Hope this helps someone

Related

how to conver a m4v(mpeg) codec raw video to a mp4 file which can be played?

I uses the following command that can extract the mpeg4 raw video file:
ffmpeg -i D:\mp4v-mp4\test\360.mov -vcodec copy -an -f rawvideo D:\mp4v-mp4\test\360CmdSplit_std.dat
but how can I convert the rawvideo file back to a playable mp4 file.
I have tried the follow cmd, but failed:
ffmpeg -y -f m4v -i D:\mp4v-mp4\test\360CmdSplit_std1.dat -vcodec copy D:\mp4v-mp4\test\tmp360.mp4
the first cmd(extract the raw mp4v video) is success,logs:
D:\install\ffmpeg-4.3.1-essentials_build\bin>ffmpeg.exe -i D:\mp4v-mp4\MOV\360(mp4v_aac).mov -vcodec copy -an -f rawvideo D:\mp4v-mp4\MOV\360mov_std.dat
ffmpeg version 4.3.1-essentials_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev1, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\mp4v-mp4\MOV\360(mp4v_aac).mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.17.101
Duration: 00:00:52.08, start: 0.000000, bitrate: 408 kb/s
Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 360x240 [SAR 1:1 DAR 3:2], 277 kb/s, 24 fps, 24 tbr, 12288 tbn, 24 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.22.101 mpeg4
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, rawvideo, to 'D:\mp4v-mp4\MOV\360mov_std.dat':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.45.100
Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 360x240 [SAR 1:1 DAR 3:2], q=2-31, 277 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.22.101 mpeg4
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 1250 fps=0.0 q=-1.0 Lsize= 1764kB time=00:00:52.08 bitrate= 277.5kbits/s speed=1.47e+03x
video:1764kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
convert the rawvideo file back to a playable mp4 file,failed:
D:\install\ffmpeg-4.3.1-essentials_build\bin>ffmpeg -y -f m4v -i D:\mp4v-mp4\MOV\360mov_std.dat -vcodec copy D:\mp4v-mp4\MOV\tmp360.mp4
ffmpeg version 4.3.1-essentials_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev1, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
[mpeg4 # 00000214e53d47c0] time_increment_bits 0 is invalid in relation to the current bitstream, this is likely caused by a missing VOL header
[mpeg4 # 00000214e53d47c0] time_increment_bits set to 5 bits, based on bitstream analysis
[mpeg4 # 00000214e53d47c0] time_increment_bits 4 is invalid in relation to the current bitstream, this is likely caused by a missing VOL header
[mpeg4 # 00000214e53d47c0] time_increment_bits set to 5 bits, based on bitstream analysis
[mpeg4 # 00000214e53d47c0] looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag
[m4v # 00000214e53cab40] decoding for stream 0 failed
[m4v # 00000214e53cab40] Could not find codec parameters for stream 0 (Video: mpeg4, yuv420p): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, m4v, from 'D:\mp4v-mp4\MOV\360mov_std.dat':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mpeg4, yuv420p, 25 fps, 25 tbr, 1200k tbn, 25 tbc
[mp4 # 00000214e543a840] dimensions not set
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 times

Generating timestamps in webm transport stream with ffmpeg

I am recording screen capture of my Electron app to a file, as suggested here: Save captured video to file in Electron
It works great, but the file is a “transport stream”. I can play it in Chrome browser, but can’t adjust the time slider.
The suggestion was to use ffmpeg to post-process the file. The simplest, straight-forward command I found is:
ffmpeg -fflags +genpts -i in.webm out.webm
I thought that this simply generates timestamps. However, the out.webm file is 15 times smaller than in.webm! I don’t see any change in the quality. The downside is - the processing takes about the same time as the duration of the video.
Two questions:
Is there any way I can speedup this “timestamping” process?
Can I record a video that is already 15 times smaller in size?
I specify maxFrameRate: 30 when calling webkitGetUserMedia().
Here is the output of that ffmpeg command:
vlad$ ffmpeg -fflags +genpts -i in.webm out.webm
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'in.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 2560x1416, SAR 1:1 DAR 320:177, 1k tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 # 0x7f85f2012600] v1.9.0
[libvpx-vp9 # 0x7f85f2012600] Neither bitrate nor constrained quality specified, using default CRF of 32
Output #0, webm, to 'out.webm':
Metadata:
encoder : Lavf58.45.100
Stream #0:0(eng): Video: vp9 (libvpx-vp9), yuv420p, 2560x1416 [SAR 1:1 DAR 320:177], q=-1--1, 1k fps, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
encoder : Lavc58.91.100 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 209 fps=5.8 q=0.0 Lsize= 881kB time=00:00:17.81 bitrate= 405.0kbits/s speed=0.494x
video:879kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.231567%
And here is the information on both files from ffprobe:
vlad$ ffprobe in.webm
ffprobe version 4.3.2 Copyright (c) 2007-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'in.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 2560x1416, SAR 1:1 DAR 320:177, 1k tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
and
vlad$ ffprobe out.webm
ffprobe version 4.3.2 Copyright (c) 2007-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'out.webm':
Metadata:
ENCODER : Lavf58.45.100
Duration: 00:00:17.82, start: 0.000000, bitrate: 405 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 2560x1416, SAR 1:1 DAR 320:177, 1k tbr, 1k tbn, 1k tbc (default)
Metadata:
ALPHA_MODE : 1
ENCODER : Lavc58.91.100 libvpx-vp9
DURATION : 00:00:17.815000000
I am fairly sure your FFmpeg processing isn't exactly what you think it is -- with your command line, particularly with absence of certain explicit switches, FFmpeg will transcode your video and audio at its own discretion, which is why your output file is much smaller -- the data have been re-compressed, with potentially loss of quality.
If you just want to generate the index necessary for the kind of seeking most players do, and avoid the undesired transcoding, the following command line will suffice:
ffmpeg -i <input-file> -codec copy <output-file>
On a minor note, do take into account that without an additional explicit switch to instruct it otherwise, FFmpeg infers the output container format from the output file name extension. I assume both your input and output are WebM, so there isn't any issue in your case. But even if they weren't, re-muxing media into another format of container doesn't have to result in quality loss.
As you can surmise from the command line above, just running FFmpeg without any explicit switch pertaining to "generation of frame time index", causes it to build the index anyway. It will do so with or without transcoding taking place.
P.S. There are some players, like [the now abandoned] MPC-HC, which are able to seek at least some transport streams. I expect it to be able to seek your kind of WebM media. I don't know the exact details on how it actually does the seeking, but if I would guess I'd say it simply does a linear search from some appropriate location in the media (or the very beginning) for a frame matching the time of seek. Much like looking for a row in a database table which doesn't have an index to help with the search predicate.

FFMPEG shows bitrate=N/A and doesn't send anything

I am trying to relay an stream from one rtsp url to another without recoding using this command:
ffmpeg
-rtsp_transport tcp
-fflags nobuffer
-re
-i rtsp://xxx.xxx.xxx.xxx:554/[stream_name]
-vcodec copy
-an
-f rtsp rtsp://yyy.yyy.yyy.yyy/[new_stream_name]
But FFMPEG doesn't stream anything and stats shows bitrate=N/A
This is the exact output that i get:
ffmpeg version 4.1.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libxml2 --enable-libxvid --enable-libzimg
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, rtsp, from
'rtsp://xxx.xxx.xxx.xxx:554/[stream_name]':
Metadata:
title : RTSP Session
Duration: N/A, start: 0.318111, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 944x1080, 22 fps, 22 tbr, 90k tbn, 180k tbc
Output #0, rtsp, to
'rtsp://yyy.yyy.yyy.yyy/[new_stream_name]':
Metadata:
title : RTSP Session
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (High), yuv420p(progressive), 944x1080, q=2-31, 22 fps, 22 tbr, 90k tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 113 fps= 32 q=-1.0 Lsize=N/A time=00:00:06.77 bitrate=N/A speed=1.92x
Although when i change output stream container to 'flv' and protocol to 'rtmp' it works.
Any help will be appreciated.
To have stream accessible you need to publish it to a streaming server that supports RTSP input (like Wowza SE) and that usually also involves publishing credentials like:
rtsp://user:password#yyy.yyy.yyy.yyy/[new_stream_name]
You can test re-streaming with this tool https://videonow.live/broadcast-ip-camera-or-stream/ that can also publish it in a HTML5 accessible format like HLS.

ffmpeg command gives error when used in python

When I run this command from the shell it works perfectly.
ffmpeg -nostdin -i /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi -ss 00:00:00 -vcodec h264 -vf fps=25 -to 00:6:43 /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi
But the same thing when I do in python it gives error:
import sys
import os
INPUT_DIR = sys.argv[1]
INPUT_VIDEO = sys.argv[2]
OUTPUT_PATH = sys.argv[3]
SOURCE = sys.argv[4]
DATE = sys.argv[5]
INPUT = INPUT_DIR+"sorted_result.txt"
COUNT=1
initial="00:00:00"
with open(INPUT,"r") as f:
for line in f.readlines():
OUT_DIR = OUTPUT_PATH+str(COUNT)
directory = os.path.abspath(OUT_DIR)
print('OUT DIR',OUT_DIR)
print('directory',directory)
try:
os.mkdir(directory)
except:
pass
cmd_1 = "ffmpeg -nostdin -i "+INPUT_VIDEO+" -ss " +initial+ " -vcodec h264 -vf fps=25 -to " +line+ " " +OUT_DIR+"/"+str(COUNT)+".avi"
os.system(cmd_1)
COUNT += 1
initial=line
I cant understand the problem:
The error is as follows:
ffmpeg version 4.0-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Trailing options were found on the commandline.
Input #0, avi, from '/data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi':
Metadata:
encoder : Lavf58.12.100
Duration: 01:00:50.23, start: 0.000000, bitrate: 1334 kb/s
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 512x288 [SAR 1:1 DAR 16:9], 1001 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 639 kb/s
At least one output file must be specified
sh: line 1: /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi: Permission denied
Please help.
This is some dummy text I am writing because it looks like stack overflow does not accept less description and more code. Please don't mind these sentences. I cant believe that I am still writing this and it is still requesting me to add some more description. I am still doing it. Don't know till what extent do I have to write. I hope this much is enough.
Got the error.
The input file contains timestamps each one on a new line so it was taking the '\n' character along with the timestamp in the ffmpeg command. Hence it considered -vcodec as a new command and resulted in error.

Use ffmpeg for incoming youtube HLS live stream and output to rtmp

I can't get ffmpeg to work with live streams from youtube. Normal non-live videos work just fine. But with live streams ffmpeg seems like it doesn't make enough requests for new segments. It basically downloads, say a 3 second segment, then nothing happens for 10 seconds or so, then it downloads a new segment, repeat...
ffmpeg -i '$(./youtube-dl -f best -g https://www.youtube.com/watch?v=emGI3UrzIMc)' -f flv rtmp://192.168.0.11/myapp/mystream
So what's the automagic command?
ffmpeg version:
ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (Rev1, Built by MSYS2 project)
configuration: --prefix=/mingw64 --target-os=mingw32 --arch=x86_64 --disable-debug --disable-static --enable-avresample --enable-dxva2 --enable-d3d11va --enable-fontconfig --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libcaca --enable-libcelt --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvpx --enable-libwebp --enable-openal --enable-libwavpack --enable-pic --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-static --enable-swresample --enable-version3 --enable-zlib --disable-doc
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
youtube-dl version: 2018.03.14
Following is the output of the command above. The <MY NOTE #> is added by me for description purposes.
At start execution goes smoothly. It then freezes for 10 or 15 sec at <MY NOTE 1>. It then downloads the part of the stream - <MY NOTE 2>, plays is, then freezes again for some seconds. Then downloads the next part - <MY NOTE 3>, plays it, freezes, and so on...
$ ffmpeg -i '$(./youtube-dl -f best -g https://www.youtube.com/watch?v=emGI3UrzIMc)' -f flv rtmp://192.168.0.11/myapp/mystream
ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (Rev1, Built by MSYS2 project)
configuration: --prefix=/mingw64 --target-os=mingw32 --arch=x86_64 --disable-debug --disable-static --enable-avresample --enable-dxva2 --enable-d3d11va --enable-fontconfig --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libcaca --enable-libcelt --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvpx --enable-libwebp --enable-openal --enable-libwavpack --enable-pic --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-static --enable-swresample --enable-version3 --enable-zlib --disable-doc
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[hls,applehttp # 00000287da404cc0] Opening 'https://r4---sn-cap1vv-nv4l.googlevideo.com/videoplayback/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8/sq/1308292/goap/clen%3D48852%3Blmt%3D1520930742662673/govp/clen%3D347004%3Blmt%3D1520930742662679/dur/2.000/file/seg.ts' for reading
Input #0, hls,applehttp, from 'https://manifest.googlevideo.com/api/manifest/hls_playlist/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/dover/10/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8':
Duration: N/A, start: 39603.798400, bitrate: N/A
Program 0
Metadata:
variant_bitrate : 0
Stream #0:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp
Metadata:
variant_bitrate : 0
Stream #0:1: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
Metadata:
variant_bitrate : 0
Stream mapping:
Stream #0:1 -> #0:0 (h264 (native) -> flv1 (flv))
Stream #0:0 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, flv, to 'rtmp://192.168.0.11/myapp/mystream':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 1k tbn, 30 tbc
Metadata:
variant_bitrate : 0
encoder : Lavc57.107.100 flv
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 48000 Hz, stereo, fltp
Metadata:
variant_bitrate : 0
<MY NOTE 1>encoder : Lavc57.107.100 libmp3lame
<MY NOTE 2>[hls,applehttp # 00000287da404cc0] Opening 'https://r4---sn-cap1vv-nv4l.googlevideo.com/videoplayback/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8/sq/1308293/goap/clen%3D48853%3Blmt%3D1520930742662680/govp/clen%3D404944%3Blmt%3D1520930742662686/dur/2.000/file/seg.ts' for reading
<MY NOTE 3>[hls,applehttp # 00000287da404cc0] Opening 'https://r4---sn-cap1vv-nv4l.googlevideo.com/videoplayback/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8/sq/1308294/goap/clen%3D48852%3Blmt%3D1520930742662688/govp/clen%3D403294%3Blmt%3D1520930742662693/dur/2.000/file/seg.ts' for reading
[hls,applehttp # 00000287da404cc0] Opening 'https://r4---sn-cap1vv-nv4l.googlevideo.com/videoplayback/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8/sq/1308295/goap/clen%3D48355%3Blmt%3D1520930742662695/govp/clen%3D358330%3Blmt%3D1520930742662700/dur/2.000/file/seg.ts' for reading
[hls,applehttp # 00000287da404cc0] Opening 'https://r4---sn-cap1vv-nv4l.googlevideo.com/videoplayback/id/emGI3UrzIMc.0/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-cap1vv-nv4l.googlevideo.com/ei/6jiqWt7SIJKD8gPimZTACA/playlist_type/DVR/gcr/bg/initcwndbps/10410/mm/32/mn/sn-cap1vv-nv4l/ms/lv/mv/m/pcm2cms/yes/pl/16/keepalive/yes/mt/1521105015/ip/130.204.135.162/ipbits/0/expire/1521126730/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,playlist_type,gcr,initcwndbps,mm,mn,ms,mv,pcm2cms,pl/signature/503304477BD05CCC71061344F8BB23195E152A32.512A84732C501AF08AC9340181A75D34C5B2FF77/key/dg_yt0/playlist/index.m3u8/sq/1308296/goap/clen%3D48852%3Blmt%3D1520930742662701/govp/clen%3D347658%3Blmt%3D1520930742662707/dur/2.000/file/seg.ts' for reading
frame= 225 fps=1.8 q=31.0 size= 947kB time=00:00:07.92 bitrate= 979.2kbits/s speed=0.0625x
And you don't have to output to a rtmp. Can be a local file - behavior is the same.
Try using the hls prefix. Example:
ffmpeg -i "hls+$(./youtube-dl -f best -g https://www.youtube.com/watch?v=emGI3UrzIMc)" -f flv rtmp://192.168.0.11/myapp/mystream

Resources