can i use -crf and -s option in one command with ffmpeg - ffmpeg

I want to create video streaming for phone. To do that i use ffmpeg to convert video into hls. For now i can convert video to hls using this command:
ffmpeg -y -i video.mp4 -profile:v
baseline -level 3.0 -crf 51 -start_number 0 -hls_time 10
-hls_list_size 0 -f hls video.m3u8.
I know i can reduce video image size by using this command:
ffmpeg -y -i video.mp4 -profile:v
baseline -level 3.0 -s 640x360 -r 20 -start_number 0 -hls_time 10
-hls_list_size 0 -f hls video.m3u8
can i use both -s and -crf in one command?
Because i'm streaming for phone. so size is my main concern.

Yes you can, crf stands for constant rate factor which is unrelated to the dimensions of your output. Generally speaking you’ll also get a conversion failed in your console when passing invalid flags.

Related

FFMPEG avoid_negative_ts makes video start not from keyframe

Let's say I want to cut part of the mp4 video and resize it from 1280x720 to 854x480.
My command looks like this:
ffmpeg -ss 45 -i source.mp4 -ss 10 -to 20 \
-acodec aac -ar 44100 -ac 2 -c:v libx264 \
-crf 26 -vf scale=854:480:force_original_aspect_ratio=decrease,pad=854:480:0:0,setsar=1/1,setdar=16/9 \
-video_track_timescale 29971 -pix_fmt yuv420p \
-map_metadata 0 -avoid_negative_ts 1 -y dest.mp4
The problem is, when I don't use option avoid_negative_ts, resulting video has some issues with time bases etc, therefore it cannot be later converted by other libs, for example Swift's AVFoundation.
But when I use this option - video does not start with keyframe.
By using ffprobe I see start_time=0.065997 or other times other than 0.
How can I use option avoid_negative_ts and have a video that starts with keyframe?

Quick conversion of mp4 to hls using ffmpeg

I need to convert huge video(around 2-4GB) using ffmpeg from mp4 to hls format.
The following takes very long to run, is there any quick conversion flag in ffmpeg.
ffmpeg -i ad1.mp4 -strict -2 -profile:v baseline -level 3.0 -start_number 0 -hls_list_size 0 -hls_segment_filename 'sample-%06d.ts' -f hls sample.m3u8
Assuming ffmpeg is using the x264 encoder, change the preset.
ffmpeg -i ad1.mp4 -strict -2 -preset:v veryfast -profile:v baseline ...
This should increase speed by 100% for moderate difference in bitrate. There are other presets like superfast but filesize will increase appreciably.

ffmpeg mp4 to hls restrict output chunk size instead of duration

I need to convert mp4 video hls format in which I want to limit the output size of each chunk. I am able to restrict the chunk size to duration but it is not mandatory instead I am interested in size.
I am using below command to convert.
ffmpeg -i sample.mp4 -strict -2 -preset:v veryfast -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_list_size 0 -force_key_frames expr:'gte(t,n_forced*5)' -hls_time 5 -hls_segment_filename 'sample-%06d.ts' -f hls sample.m3u8
How can I restrict the chunk size to max 500Kb?

Reducing FFMPEG h264 video stream latency

I'm using FFMPEG(h264) and I want to reduce latency as much as possible. Now it's about 700 ms and I can't really make it lower. I tried almost all, so maybe anyone has idea how to help me?
ffmpeg -f dshow -i video="screen-capture-recorder" -pix_fmt yuv420p -probesize 32 -r 100 -an -vcodec libx264 -crf 40 -preset ultrafast -tune zerolatency -threads 8 -thread_type slice -f mpegts udp://192.168.88.228:1234
The weird thing is I got this latency even on 127.0.0.1....
(on the other side I use just ffplay udp:// .......)
I would try to set -threads to 1 to disable multi-threaded decoding. Multi-threaded decoding introduces delay by adding a lag of 1 frame for each thread.
Works with a GoPro Hero 8 Black and Linux
ffmpeg -threads 1 -i 'udp://#0.0.0.0:8554?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format=yuv420p -f v4l2 /dev/video0

What command convert mjpeg IP camera streaming to mp4 file with lowest CPU usage?

like above question, I want find out what ffmpeg command can help me reduce cpu usage when running 50 IP camera (running same 50 command).
My ffmpeg command:
ffmpeg -f mjpeg -y -use_wallclock_as_timestamps 1 -i 'http://x.x.x.x:8090/test1?.mjpg' -r 3 -reconnect 1 -loglevel 16 -c:v mjpeg -an -qscale 10 -copyts '1.mp4'
50 command like that take my computer (4 core) 200% CPU
I want this computer can run for 150 camera, any advise?
=========================================================
using -c:v copy can make it faster but fize size is terrible
I try slow down frame rate by 3 with -r 3 or -framerate 3 to decrease file size but not succesful (because vcodec copy can't do that).
Have any option to force input frame rate by 3?
(sorry for my bad English)
by setting -c:v mjpeg you are decoding and re-encoding the stream. set -c:v copy to copy the data without re-encoding it.
ffmpeg -re -i 'rtsp://user:password#10.10.10.30/rtsp_tunnel' -pix_fmt yuv420p -c:v libx264 -preset ultrafast -profile baseline -crf 18 -f h264 udp://0.0.0.0:3001

Resources