I am interested in scaling a video to a larger size without applying any filter or anything. The output video should look very pixelated. How do I do this in FFMPEG?
On the suggestion of Ronald S. Bultje, I am using the neighbor flag. I have also decided to use the rawvideo codec to avoid compression.
The current command I am running is
ffmpeg -i vid.avi -s 800x800 -sws_flags neighbor -sws_dither none -vcodec rawvideo vid2.avi
The command line output of that command is
ffmpeg version 2.7 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray --enable-lzma --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --disable-indev=jack --disable-outdev=xv --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-vda --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, avi, from 'vid.avi':
Duration: 00:00:25.00, start: 0.000000, bitrate: 226 kb/s
Stream #0:0: Video: rawvideo, pal8, 80x80, 206 kb/s, 4 fps, 4 tbr, 4 tbn, 4 tbc
File 'vid2.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to 'vid2.avi':
Metadata:
ISFT : Lavf56.36.100
Stream #0:0: Video: rawvideo, pal8, 800x800, q=2-31, 200 kb/s, 4 fps, 4 tbn, 4 tbc
Metadata:
encoder : Lavc56.41.100 rawvideo
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
frame= 100 fps=0.0 q=0.0 Lsize= 62608kB time=00:00:25.00 bitrate=20515.4kbits/s
video:62600kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.012614%
ffmpeg -i infile -vf scale=WIDTH:HEIGHT:flags=neighbor outfile
or
ffmpeg -i infile -s WIDTHxHEIGHT -sws_flags neighbor outfile
The critical part here is flags or -sws_flags, which selects the filter (and other scaling-related flags). The default filter value is bicublin (IIRC), which means a bicubic luma and bilinear chroma filter. Nearest-neighbour will do what you're asking for.
See scaler options for a list other scaling algorithms.
You can rich your goal maybe with scale-down and then scale-up like:
ffmpeg -i in.mp4 -vf scale=iw/4:ih/4,scale=4*iw:4*ih:flags=neighbor out.mp4
The 4 you can modify to your needs.
Related
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.
I'm trying to capture a screenshot from a udp stream using ffmpeg in a Ubuntu 14.04 System.
Following is the command
ffmpeg -y -i udp_ip -vframes 1 -q:v 1 test.png
But the image captured is of very poor resolution and I observed a lag while taking the screenshot.
Please suggest a best tool or a way to take a screenshot in the fastest way and also of the best image resolution possible.
edit:
log files
ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
[mpeg2video # 0x390cc60] Invalid frame dimensions 0x0.
Last message repeated 7 times
Input #0, mpegts, from 'udp://#xxx.xx.xx.xx:xxxx':
Duration: N/A, start: 144.130744, bitrate: 4128 kb/s
Program 1
Metadata:
service_name : Program-1
service_provider: Encoder
Stream #0:0[0x42]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 4000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x43]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'player.png':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: png, rgb24, 720x576 [SAR 16:15 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc57.89.100 png
frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=1 drop=1 speed=0.729x
video:777kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Since, this seems to be an issue of aspect ratio, and not quality, per se, use
ffmpeg -y -i udp_ip -vf scale=iw*sar:ih,setsar=1 -vframes 1 -q:v 1 test.png
The scale filter rescales the video to square pixels. The SAR filter isn't strictly necessary but in case the PNG muxer writes that data, better to reset it.
i m trying to use kinect to capture video for video/image processing purposes
i found there is an script in libfreenect/build/bin folder named fakenect-record can do this for me
when i use it,it start capturing rgb and depth data in ppm and pgm format(both are images) and also it has an option (-ffmpeg) witch make an avi file of video but the problem is when I that it it fails and says this error :
Depth Mode: {256, 1, {0}, 614400, 640, 480, 11, 5, 30, 1}
Video Mode: {256, 1, {0}, 921600, 640, 480, 24, 0, 30, 1}
[Stream 70] Expected 1748 data bytes, but got 948
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-depth.avi
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-rgb.avi
ffmpeg version N-76045-g97be5d4ffmpeg version N-76045-g97be5d4 Copyright (c) 2000-2015 the FFmpeg developers Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 55. 4.100 / 55. 4.100
libavutil 55. 4.100 / 55. 4.100
libavcodec 57. 6.100 / 57. 6.100
libavcodec 57. 6.100 / 57. 6.100
libavformat 57. 4.100 / 57. 4.100
libavformat 57. 4.100 / 57. 4.100
libavdevice 57. 0.100 / 57. 0.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 11.100 / 6. 11.100
libavfilter 6. 11.100 / 6. 11.100
libavresample 3. 0. 0 / 3. 0. 0
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libswscale 4. 0.100 / 4. 0.100
libpostproc 54. 0.100 / 54. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
Segmentation fault (core dumped)
root#thispc-sns:~/Documents/libfreenect/build/bin/Untitled Folder# Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, start: 0.000000, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Output #0, avi, to 'sadra-depth.avi':
Output #0, avi, to 'sadra-rgb.avi':
Metadata:
ISFT : Metadata:
ISFT : Lavf57.4.100Lavf57.4.100
Stream #0:0 Stream #0:0: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s, , 20 fps, 20 fps, 20 tbn, 20 tbn, 20 tbc20 tbc
Metadata:
Metadata:
encoder : Lavc57.6.100 msmpeg4 encoder : Lavc57.6.100 msmpeg4
Stream mapping:
Stream #0:0 -> #0:0Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> msmpeg4v3 (msmpeg4))
(rawvideo (native) -> msmpeg4v3 (msmpeg4))
***[rawvideo # 0x2a31ce0] Invalid buffer size, packet size 483328 < expected frame_size 921600
Error while decoding stream #0:0: Invalid argument
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00*** bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00 bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Conversion failed!
Run the following script on your machine, if you've installed opencv as well:
import freenect
import cv2
import numpy as np
from functions import *
def nothing(x):
pass
kernel = np.ones((5, 5), np.uint8)
def pretty_depth(depth):
np.clip(depth, 0, 2**10 - 1, depth)
depth >>= 2
depth = depth.astype(np.uint8)
return depth
while 1:
dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
cv2.imshow('Video', dst)
if cv2.waitKey(1) & 0xFF == ord('b'):
break
Do you see a disparity map from your kinect ?
So I simply try out to get the stream and convert it into a rawvideo and create a new webcam with v4l2.
ffmpeg -i "rtmp://XX.XX.XXX.XXX/XXXXXXXXXXXX/test" -vcodec rawvideo -y -f v4l2 /dev/video2
It is working a long time and then I got this:
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, flv, from 'rtmp://XX.XX.XXX.XXX/XXXXXXXXXXXX/test':
Metadata:
fileSize : 0
audiochannels : 2
encoder : obs-output module (libobs version 0.10.1-67-g94edb7f)
Duration: 00:00:00.00, start: 1774.608000, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(tv, bt709), 1920x1080, 2560 kb/s, 30.30 fps, 30 tbr, 1k tbn, 60 tbc
Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 196 kb/s
[v4l2 # 0x7f7326cb4480] Unable to open V4L2 device '/dev/video2'
Output #0, v4l2, to '/dev/video2':
Metadata:
fileSize : 0
audiochannels : 2
encoder : Lavf56.36.100
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc
Metadata:
encoder : Lavc56.41.100 rawvideo
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
To create virtual video devices you need to install and enable v4l2loopback. The "No such file or directory" message means you didn't enable the device.
sudo modprobe v4l2loopback video_nr=2
This will create the /dev/video2 device.
Update: in response to umläute's comment make sure the v4l2loopback module is persistent, just in case your server reboots. Uptime can be very long.
Example for CentOS: Persistent Module Loading
I'm using this command for ffmpeg:
ffmpeg -i 1.h264 -i ass1.ass -map 0 -map 1 -c copy test.mkv
The h264 file is 30 fps... the mkv plays at 25fps so it runs slow
The h264 come off my hd webcam. If i change the frame rate on the camera to 25 it works fine and 15fps wilk play at high speed. I can force the frame rate? Every if i need a different command line tool to change it that is acceptable. But if i could fix it form ffmpeg that would be ideal. I'm running the commands from vb.net.
command output
C:\Record\Normal\2013-06-27>c:\ffmpeg\bin\ffmpeg -i 1.h264 -i ass1.ass -map 0 -
map 1 -c copy test.mkv
ffmpeg version N-54207-ge59fb3f Copyright (c) 2000-2013 the FFmpeg developers
built on Jun 25 2013 21:55:00 with gcc 4.7.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
libavutil 52. 37.101 / 52. 37.101
libavcodec 55. 17.100 / 55. 17.100
libavformat 55. 10.100 / 55. 10.100
libavdevice 55. 2.100 / 55. 2.100
libavfilter 3. 77.101 / 3. 77.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Input #0, h264, from '1.h264':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p, 1920x1088 [SAR 1:1 DAR 30:17],
25 fps, 25 tbr, 1200k tbn, 50 tbc
Input #1, ass, from 'ass1.ass':
Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: ssa
File 'test.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'test.mkv':
Metadata:
encoder : Lavf55.10.100
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv420p, 1920x1088 [SAR 1:1 DA
R 30:17], q=2-31, 25 fps, 1k tbn, 1200k tbc
Stream #0:1: Subtitle: ssa
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 144 fps=0.0 q=-1.0 Lsize= 2451kB time=00:00:05.72 bitrate=3509.6kbits
/s
video:2447kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.125529%
Eg. To force the frame rate of the output file to 24 fps (-r):
ffmpeg -i input.avi -r 24 output.avi