I have a m3u8 vod video on my server. It's working correctly. Now I want to create a smaller size for mobile devices.
Need to create a 480p m3u8 file.
I've tried this code but it's not worked.
ffmpeg -i HD.m3u8 -vf scale=842:-1 -c:a copy -start_number 0 -hls_time 8 -hls_list_size 0 -f hls ./SM.m3u8
And here is my error code:
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[hls,applehttp # 0x55a16f22a880] Opening 'HD0.ts' for reading
Input #0, hls,applehttp, from 'HD.m3u8':
Duration: 02:05:08.29, start: 1.460111, bitrate: 0 kb/s
Program 0
Metadata:
variant_bitrate : 0
Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1920x800 [SAR 1:1 DAR 12:5], 24 fps, 24 tbr, 90k tbn, 48 tbc
Metadata:
variant_bitrate : 0
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp
Metadata:
variant_bitrate : 0
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 # 0x55a16f267880] height not divisible by 2 (842x351)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
Is it possible to convert it from a m3u8 file or do I need the original mp4 file for this?
H.264 4:2:0 sampled video has to have even dimensions, so it should be -vf scale=842:-2.
Also, for -hls_time 8, you have to ensure keyframes exist every 8 seconds. Add -force_key_frames expr:gte(t,n_forced*8)
Related
I have a UVC camera /dev/video1. The Camera will be always on. but I only care about the last 1 min data stream.
after searching online I got a ffmpeg cmd:
./ffmpeg -f v4l2 -input_format mjpeg -video_size 320x240 -i /dev/video1 -c copy -f segment -segment_time 60 -segment_wrap 2 output.mkv
However I got a error and here is the result
libavutil 56. 56.100 / 56. 56.100
libavcodec 58. 97.100 / 58. 97.100
libavformat 58. 49.100 / 58. 49.100
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, matroska,webm, from '/sdcard/Movies/output.mkv':
Metadata:
ENCODER : Lavf58.49.100
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 320x240, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
[matroska # 0x3899e10] Invalid segment filename template 'output.mkv'
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
You're using the segment muxer, which expects to write multiple files. So it expects the filename to have a format specifier for the serial number. The simplest one is %d which will be replaced by a number without padding.
ffmpeg -f v4l2 -input_format mjpeg -video_size 320x240 -i /dev/video1 -c copy -f segment -segment_time 60 -segment_wrap 2 output%d.mkv
I have a MJPEG stream and I'm trying to use ffmpeg to take it as an input and stream it to an rtmp server at a defined framerate.
I have already tried this as a command:
ffmpeg -f mjpeg -r 60 -i http://localhost:3030/ -f flv -vcodec flv rtmp://localhost/live/test
While ffmpeg looks like it is sending something...
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, mjpeg, from 'http://localhost:3030/':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 60 tbr, 1200k tbn, 60 tbc
[tcp # 0x7f95f9401ec0] Connection to tcp://localhost:1935 failed (Connection refused), trying next address
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> flv1 (flv))
Press [q] to stop, [?] for help
[swscaler # 0x7f95fa033e00] deprecated pixel format used, make sure you did set range correctly
Output #0, flv, to 'rtmp://localhost/live/test':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 60 fps, 1k tbn, 60 tbc
Metadata:
encoder : Lavc58.18.100 flv
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 20 fps=3.2 q=31.0 size= 194kB time=00:00:00.31 bitrate=4999.6kbits/s speed=0.0512x
I cannot preview the stream through VLC. Weirdly enough, if I let VLC try to load the url (rtmp://localhost/live/test) and then close ffmpeg, VLC will actually show the video stream for a few frames and then stop again.
Help on how to achieve this would be much appreciated.
The duration of source video and subtracted wav audio is different , why?
I'm recorgnizing subtitle from audio, and I need to add subtitle back to video. So I want the duration of audio and video the same.
ffmpeg -i http://cdn.live.360.cn/huikan_news/vod-media/_XW_203286B417B7C6466B3B_20160627185953.m3u8 -vn test.wav -y
My CLI:
[zhangpengcheng#mobiledev03v ifly]$ ffprobe http://cdn.live.360.cn/huikan_news/vod-media/_XW_203286B417B7C6466B3B_20160627185953.m3u8 2>&1 | grep Duration
Duration: 00:06:51.99, start: 1.400000, bitrate: 0 kb/s
[zhangpengcheng#mobiledev03v ifly]$ ffmpeg -i http://cdn.live.360.cn/huikan_news/vod-media/_XW_203286B417B7C6466B3B_20160627185953.m3u8 -vn test.wav -y
ffmpeg version 3.1.3 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
configuration: --prefix=./build/ --enable-shared --enable-static --enable-libx264 --enable-avisynth --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libopencv --enable-librtmp --enable-gpl --enable-nonfree
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, hls,applehttp, from 'http://cdn.live.360.cn/huikan_news/vod-media/_XW_203286B417B7C6466B3B_20160627185953.m3u8':
Duration: 00:06:51.99, start: 1.400000, bitrate: 0 kb/s
Program 0
Metadata:
variant_bitrate : 0
Stream #0:0: Video: h264 (Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m/bt709/bt709), 668x376, 15 tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 65 kb/s
[wav # 0x10182e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, wav, to 'test.wav':
Metadata:
ISFT : Lavf57.41.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Metadata:
encoder : Lavc57.48.101 pcm_s16le
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size= 31904kB time=00:06:51.84 bitrate= 634.6kbits/s speed= 146x
video:0kB audio:31904kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000239%
[zhangpengcheng#mobiledev03v ifly]$ ffprobe test.wav 2>&1 | grep Duration
Duration: 00:06:10.40, bitrate: 705 kb/s
Looks like there are gaps in the original audio.
Use
ffmpeg -i http://cdn.live.360.cn/huikan_news/vod-media/_XW_203286B417B7C6466B3B_20160627185953.m3u8 -af aresample=async=1 -vn test.wav -y
The audio filter will fill in the gaps.
While I am trying to convert wav file to wma file size is becomes much larger than original source file:
input.wav - 11M
output.wma - 16M
Is there any way to reduce file size of output file?
Command and output:
$ ffmpeg -i input.wav -c copy output.wma
ffmpeg version N-80797-g8b4d6cc Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.1.1 (GCC) 20160501
configuration: --enable-gpl
libavutil 55. 27.100 / 55. 27.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 40.101 / 57. 40.101
libavdevice 57. 0.102 / 57. 0.102
libavfilter 6. 46.102 / 6. 46.102
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'input.wav':
Metadata:
encoder : Lavf57.40.101
Duration: 00:01:00.00, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
Output #0, asf, to 'output.wma':
Metadata:
WM/EncodingSettings: Lavf57.40.101
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 16150kB time=00:01:00.00 bitrate=2205.1kbits/s speed=1.9e+03x
video:0kB audio:10336kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 56.255745%
WMA is crappy. Try changing the packet size. From FFmpeg ASF muxer documentation:
-packet_size
Set the muxer packet size. By tuning this setting you
may reduce data fragmentation or muxer overhead depending on your
source. Default value is 3200, minimum is 100, maximum is 64k.
Example:
ffmpeg -i input.wav -c copy -packet_size 65536 output_64k.wma
File sizes:
input.wav - 11M
output_64k.wma - 11M
output_default.wma - 16M
I have two video streams from which I'd like to take one frame of each, both of them are RTSP. I'm using the same FFMPEG instruction for both of them but changing the URL of the stream, the first one works but the second one throws the error:
method SETUP failed: 455 Method Not Valid In This State
Can anyone tell me what could be the reason for this error and how to solve it?
WORKING
ffmpeg -ss 1 -i rtsp://streamreader:trudat55#69.84.126.216:88/videoMain -an -vcodec mjpeg -vframes 1 -aspect 16:9 -q:v 2 -y test.jpg
ffmpeg version 2.8.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --enable-gpl --enable-avresample --enable-libopencore-amrnb --enable-libx264 --enable-libxvid --enable-postproc --enable-version3 --enable-shared --enable-pic --extra-ldexeflags=-pie
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[rtsp # 0x55a60a0a7420] UDP timeout, retrying with TCP
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://streamreader:password#69.84.126.216:88/videoMain':
Metadata:
title : IP Camera Video
comment : videoMain
Duration: N/A, start: 0.200044, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p, 640x480, 50 tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s
[swscaler # 0x55a60a102460] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'test.jpg':
Metadata:
title : IP Camera Video
comment : videoMain
encoder : Lavf56.40.101
Stream #0:0: Video: mjpeg, yuvj420p(pc), 640x480 [SAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 50 fps, 50 tbn, 50 tbc
Metadata:
encoder : Lavc56.60.100 mjpeg
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame= 1 fps=0.5 q=2.0 Lsize=N/A time=00:00:00.02 bitrate=N/A dup=1 drop=1
video:66kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
NOT WORKING
ffmpeg -ss 1 -i rtsp://camaras.corredorautomotriz.cl:554/live.sdp -an -vcodec mjpeg -vframes 1 -aspect 16:9 -q:v 2 -y test.jpg
ffmpeg version 2.8.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --enable-gpl --enable-avresample --enable-libopencore-amrnb --enable-libx264 --enable-libxvid --enable-postproc --enable-version3 --enable-shared --enable-pic --extra-ldexeflags=-pie
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[rtsp # 0x55b98f2de420] UDP timeout, retrying with TCP
[rtsp # 0x55b98f2de420] method SETUP failed: 455 Method Not Valid In This State
[rtsp # 0x55b98f2de420] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown)): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, rtsp, from 'rtsp://camaras.corredorautomotriz.cl:554/live.sdp':
Metadata:
title : RTSP server
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 90k tbr, 90k tbn, 90k tbc
Stream #0:1: Data: none
Output #0, image2, to 'test.jpg':
Output file #0 does not contain any stream
I found that if I specify that the protocol is TCP with the instruction -rtsp_transport tcp then i don't get an error:
ffmpeg -ss 5 -rtsp_transport tcp -i rtsp://camaras.corredorautomotriz.cl:554/live.sdp -s 640x480 -aspect 16:9 -b:v 800k -r 24 video.flv
But I would still like to know the reason and solution of the problem I got before, because I am not sure I can use this parameter. Anyone knows?
Thanks
As I see in your output, ffmpeg failed to determine input stream type in the second case (rtsp://camaras.corredorautomotriz.cl:554/live.sdp).
I checked it, and it got me mpeg4:
Input #0, rtsp, from 'rtsp://camaras.corredorautomotriz.cl:554/live.sdp':
Metadata:
title : RTSP server
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 720x480 [SAR 1:1 DAR 3:2], 30 tbr, 30k tbn
Thus possibly you compiled ffmpeg without mpeg4 decoder (or with broken decoder).