How to change audio frame rate in FFMPEG? - ffmpeg

I am trying to change audio frame from 43.066 FPS (1024 SPF) to 23.438 FPS (2048 SPF) but no luck.
code tried :
ffmpeg -i 1.mp4 -b:v 2000k -vcodec libx264 -x265-params keyint=50:scenecut=0 -preset fast -pix_fmt yuv420p -profile:v main -level 3.1 -r 25 -s:v 1280x720 -ac 2 -c:a aac -b:a 128k -ar 48000 -aframes 23.438 HD2_500_500.mp4
Error :
Expected int64 for frames:a

You can change the audio speed using the ​atempo audio filter. The filter accepts exactly one parameter, the audio tempo. If not specified then the filter will assume nominal 1.0 tempo. Tempo must be in the [0.5, 100.0] range.
Here a simple example on how to speed down the audio by half:
ffmpeg -i 1.mp4 -filter:a "atempo=0.5" -vn HD2_500_500.mp4

Related

FFmpeg: Get better encoding out of my function

I needed some assistance on my task.
I am using FFmpeg to burn time and the channel name onto the video.
My goal is to record a stream that is html5 compatible with the following settings:
Video wrapper MP4
Video codec H.264
Bitrate 1Mbps
Audio codec AAC
Audio bitrate 128Kbps
And GPU encoding.
This is what I am using:
ffmpeg -hwaccel cuvid -y -i {udp} -vf "drawtext=fontfile=calibrib.tff:fontsize=25:text='{ChannelName} %{localtime}': x=10: y=10: fontcolor=white: box=1: boxcolor=0x000000" -pix_fmt yuv420p -vsync 1 -c:v h264_nvenc -r 25 -threads 0 -b:v 1M -profile:v main -minrate 1M -maxrate 1M -bufsize 10M -sc_threshold 0 -c:a aac -b:a 128k -ac 2 -ar 44100 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -bsf:v h264_mp4toannexb -t 00:30:00 {output}\{ChannelName}\{ChannelName}_{year}_{monthno}_{day}__{Hours}_{Minutes}_{Seconds}.mp4
{ChannelName}_{year}_{monthno}_{day}__{Hours}_{Minutes}_{Seconds} are all variable holding information.
{udp} holds the UDP stream link.
I have done it this way as I have multiple UDP stream recording.
Although this works, is there a better way for me to do this keeping in the -vf as I need the time and channel name.
Currently, this uses between 0.8% to 1.9% GPU on my Quadro P4000. I don't want to use more than this as I have more than 30 streams.
Here are some of the suggestion
-profile:v use Constrained Baseline Profile or Baseline Profile - as most of the Browser or HTML will support.
Check How many parallel instances of the Encoder you can run on GPU - Quadro P4000, remaining you can run on cpu.
Based on the resolution & fps you can decide the video bitrate of encoding range min & max bitrate. (-b:v 1M -minrate 1M -maxrate 1M) - refer : https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
-sc_threshold (FFmpeg)
Adjusts the sensitivity of x264's scenecut detection. Rarely needs to be adjusted. Recommended default: 40

ffmpeg erases the last part of audio in the video file

I use following encoding option.
ffmpeg -i input.wmv -movflags faststart -c:v libx264 -profile:v baseline -acodec aac -ac 2 -ar 48000 -strict -2 /root/output.mp4;
But sometimes last 5~30 seconds audio is erased.
Total video duration is about 3 mins.
what do you think the problem is?
Is this related to computer performance? I use quadcore, 4G ram.

How to optimize RTMP AAC transcoding with (or without) FFMPEG?

I do use NginxRTMP to generate HLS.
Problem is that HLS has not sound (since it needs AAC)
I try to trancode my RTMP sound to AAC sound with FFMPEG
exec_push ffmpeg -i rtmp://localhost/src/$name -vcodec libx264 -threads 0 -vprofile baseline -preset ultrafast -s 800x600 -acodec libfaac -ar 44100 -f flv rtmp://localhost/hls/$name
Problem: it takes 25% of CPU per stream.
Any idea on how to optimize that ?

Video codec specs through ffmpeg (not being achieved)

The specs for the video format are the following:
Aspect Ratio: 1:1
H.264 video compression, high profile, square pixels, fixed frame rate, progressive scan
.mp4 container with leading mov atom, no edit lists
Audio: Stereo AAC audio compression, 128kbps +
Reading through posts and ffmpeg documentation I came up with the following (yeah, I run it on a Windows PC):
ffmpeg.exe -r 30 -i input.webm -vf scale=iw*sar:ih -c:v libx264 -preset slow -profile:v high -c:a aac -strict experimental -ar 44100 -aspect 1:1 output.mp4
But when the video is played within the app that asks for this specification, it only displays black moving pixels, all broken, but you an hear the audio.
I don't really know what else to change on the command, and I have no idea in regards to the ...with leading mov atom specification.
Thanks.
EDIT:
I've tried #Mulvya's answer:
ffmpeg.exe -i input.webm -vf scale=iw*sar:ih,setsar=1 -c:v libx264 -preset slow -profile:v high -pix_fmt yuv420p -r 30 -c:a aac -strict experimental -ar 44100 -ac 2 -b:a 128k -movflags +faststart output.mp4
But the effect is the same once given to the app:
This is the information that ffmpeg spews about the input.webm file:
Use
ffmpeg.exe -i input.webm -vf scale=iw*sar:ih,setsar=1 -c:v libx264 -preset slow -profile:v high -pix_fmt yuv420p -r 30 -c:a aac -strict experimental -ar 44100 -ac 2 -b:a 128k -movflags +faststart output.mp4
Depending on how strict the app is, you may need to check the precise framerate. Use -r 30000/1001 for 29.97. The -movflags +faststart moves the moov atom to the front of the file.
Based on info I found elsewhere, this seems to be what Instagram requires:
ffmpeg.exe -i input.webm -vf scale=640:640,setsar=1 -c:v libx264 -preset slow -profile:v main -level 3.1 -pix_fmt yuv420p -r 30000/1001 -c:a aac -strict experimental -ar 44100 -ac 1 -b:a 64k -t 15 -movflags +faststart output.mp4

Encoding YUV to mP4 With qp to get max quality

I am trying to encode my YUV420 Raw format file into mp4. Here is the ffmpeg command
ffmpeg -f s16le -ar 44100 -ac 1 -i "0.a" -f rawvideo -pix_fmt yuv420p -s 480x480 -r 30 -i "0.v" -vcodec libx264 -profile:v baseline -preset ultrafast -qp 0 -b:v 1024k -g 30 -acodec libfdk_aac -ar 44100 -ac 1 -b:a 64k -f mp4 -movflags faststart "1438947231095.mp4"
If i remove qp = 0; it works however the quality is very low not sure why. If i put qp = 0 it doesn't work, What is wrong?
Getting this error
Error while opening encoder for output stream #0:0 - maybe incorrect parameters
The baseline profile doesn't support lossless H.264. You must use the High 4:4:4 Predictive profile instead:
-profile:v high444

Resources