What does the argument -ab in ffmpeg mean? - ffmpeg

From someone I received a batch file that can do ffmpeg conversion using 2 command arguments. Let's say the file is called convert.sh and only contains this line:
ffmpeg -ss 0 -t 36000 -i "$1" -ar 8000 -ab 16K -ac 1 -y "$2"
I call it as follows:
sh convert.sh inputfile.wav outputfile.wav
In the ffmpeg documentation, I can find what all arguments mean, except for -ab. I guess 16K is its value. But I have no idea what it does. Anyone?

-ab argument means audio bitrate

-ar- set the audio sampling frequency
-ac- Set the number of audio channels
-ab- Set the audio bitrate
for more info visit this link

Related

usage of segment time in FFmpeg

I have a raw file that includes encoded data with g711 audio codec. FFMpeg decoded successfully the raw file. I want to split the wav file by time so I used segment_time option.
Here is my code:
ffmpeg -acodec pcm_alaw -f sln -i g711.raw -ar 8000 -acodec pcms16le -f segment -segment_time 10 g711.wav
This code worked without an error but I want to know that how many wav files created. Is there any chance to know that by adding an option to the code?
Thanks,
Here are 3 methods:
1. Look at the console output / log
It will output lines like:
[segment # 0x55a7f065c700] Opening 'output_003.wav' for writing
This is the last of such lines in this example, so there are 4 WAV files (it starts at 0 unless you use -segment_start_number).
2. Just list the WAV files
Linux example:
$ ls -m1 *.wav | wc -l
4
3. Use -segment_list
ffmpeg -acodec pcm_alaw -f sln -i g711.raw -ar 8000 -acodec pcm_s16le -f segment -segment_time 10 -segment_list list.txt output_%03d.wav
Example contents of list.txt:
output_000.wav
output_001.wav
output_002.wav
output_003.wav
See the segment muxer documentation for more info.

How to specify file type in ffmpeg (-f) for both the input and output?

I'm using ffmpeg to convert the stdin (pipe:0) to stdout (pipe:1).
My input format is "s16le" and my output format is "wav".
How do I specify the two different formats in an ffmpeg command?
I'm also using two different frequencies (-ar), input 44100Hz and output 22050Hz, how do I specify the two different frequencies in an ffmpeg command?
In FFmpeg, the parameters come before the input/output, for that specific input/output.
In your case, your command would look something like:
ffmpeg -sample_rate 44100 -f s16le -i - -ar 22050 -codec copy -f wav -
In this case, -ar 44100 and -f s16le apply to the input, since they came before the input.
-ar 22050, -codec copy, and -f wav apply to the output, since they were after the input but before the output.

FFmpeg how generate a sequence of videos with bash

i try to write an .sh that read a folder create a playlist of mp4 files and then generate an only big video with a sequence of all videos find in the folder, and encode it for dash:
printf "file '%s'\n" ./*.mp4 > playlist.sh
ffmpeg -f concat -safe 0 -i playlist.sh -c copy concat.mp4
Till now i follow the demux concat official guido to ffmpeg website.
Without result, also the following give me "more than 1000 frames duplicated between videos of the sequence"
ffmpeg -f concat -i playlist.sh -c:a aac -b:a 384k -ar 48000 -ac 2 -c:v libx264 -x264opts 'keyint=50:min-keyint=50:no-scenecut' -r 25 -b:v 2400k -maxrate 2400k -bufsize 1200k -vf "scale=-1:432 " out.mp4
Thanks a lot
Sry, cannot comment (yet)...
Your commands are correct, I could just concat some sample videos.
Do you always get the mentioned error, or also something else? And is the video working, or no video is created?
In most cases, the input video is incorrect. Wrong input format (not fitting to file extension) or worse like ending at wrong frame.
Perhaps you can make the video available?
PS: Needed to add -safe 0 to the second command to avoid error [concat # 0x7fbfd1000000] Unsafe file name './small.mp4'
Hint: Do not use file extension .sh for your list of video files. This extension is used for shell scripts, so it can be confusing. Just use .txt.
UPDATE #Massimo Vantaggio
We should not create new answers, but I cannot comment yours and I also don't know how to continue our discussion, so I edit my answer.
Your videos don't look very different. Can't see, what's wrong with the first one.
Perhaps you could use ffprobe -report input.mp4 to get more informations. Look for errors or warnings.
My assumption is still that the video was cut in a hard way (by conversion software), so keyframes are messed up or something else.
You can also try to first reencode your video with ffmpeg. After that, it should be complete compatible with ffmpeg ;)
Something like this:
ffmpeg -i small.mp4 -acodec aac -ab 192k -vcodec libx264 -vb 1024k -f mp4 output.mp4
Use -ab and -vb from your input video, or at least the bitrate from input. Quality will decrease a little bit and file size increase, but it should be okay.

Bad quality video after watermarking with ffmpeg

Can someone please tell me what I'm doing wrong?
I'm using the following arguments to watermark a video with ffmpeg from a c# app:
-i "video.AVI" -s 384x288 -vhook "vhook/imlib2.dll -x 0 -y 0 -i
"watermark.png"" -y "output.avi"
-sameq
The orginal file size is 233mb but the output is 60 odd mb. I thought using the -sameq argument would give me the same size and quality output.
Instead of -sameq try defining the bitrates manually with -ab and -vb.

encode video in reverse?

Does anyone know if it is possible to encode a video using ffmpeg in reverse? (So the resulting video plays in reverse?)
I think I can by generating images for each frame (so a folder of images labelled 1.jpg, 2.jpg etc), then write a script to change the image names, and then re-encode the ivdeo from these files.
Does anyone know of a quicker way?
This is an FLV video.
Thank you
No, it isn't possible using ffmpeg to encode a video in reverse without dumping it to images and then back again. There are a number of guides available online to show you how to do it, notably:
http://ubuntuforums.org/showthread.php?t=1353893
and
https://sites.google.com/site/linuxencoding/ffmpeg-tips
The latter of which follows:
Dump all video frames
$ ffmpeg -i input.mkv -an -qscale 1 %06d.jpg
Dump audio
$ ffmpeg -i input.mkv -vn -ac 2 audio.wav
Reverse audio
$ sox -V audio.wav backwards.wav reverse
Cat video frames in reverse order to FFmpeg as input
$ cat $(ls -r *jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -i backwards.wav -vcodec libx264 -vpre slow -crf 20 -threads 0 -acodec flac output.mkv
Use mencoder to deinterlace PAL dv and double the frame rate from 25 to 50, then pipe to FFmpeg.
$ mencoder input.dv -of rawvideo -ofps 50 -ovc raw -vf yadif=3,format=i420 -nosound -really-quiet -o - | ffmpeg -vsync 0 -f rawvideo -s 720x576 -r 50 -pix_fmt yuv420p -i - -vcodec libx264 -vpre slow -crf 20 -threads 0 video.mkv
I've created a script for this based on Andrew Stubbs' answer
https://gist.github.com/hfossli/6003302
Can be used like so
./ffmpeg_sox_reverse.sh -i Desktop/input.dv -o test.mp4
New Solution
A much simpler method exists now, simply use the command (adjusting input.mkv and reversed.mkv accordingly):
ffmpeg -i input.mkv -af areverse -vf reverse reversed.mkv
The -af areverse will reverse audio, and -vf reverse will reverse video. The video and audio will be in sync automatically in the output file reversed.mkv, no need to worry about the input frame rate or anything else.
On one video if I only specified the -vf reverse to reverse video (but not audio), the output file didn't play correctly in mkv format but did work if I changed it to mp4 output format (I don't think this use case of reversing video only but not audio is common, but if you do run into this issue you can try changing the output format). On large input videos that exceed the RAM available in your computer, this method may not work and you may need to chop up the input file or use the old solution below.
Old Solution
One issue is the frame rate can vary depending on the video, many answers depend on a specific frame rate (like "-r 25" for 25 frames per second). If the frame rate in the video is different, this will cause the reversed audio and video to go out of sync.
You can of course manually adjust the frame rate each time (you can get the frame rate by running ffmpeg -i video.mkv and look for the number in front of the fps, this is sometimes a decimal number like 23.98). But with some bash code you can easily extract the fps, store it in a variable, and automatically pass it to the programs.
Based on this I've created the following bash script to do that. Simply chmod +x it and run it ./make-reversed-video.sh input.mkv output.mkv. The code is as follows:
#!/bin/bash
#Partially based on https://nhs.io/reverse/, but with some modifications, including automatic extraction of the frame rate.
#Get parameters.
VIDEO_FILE=$1
OUTPUT_FILE=$2
TEMP_FOLDER=$3
echo Using input file: $VIDEO_FILE
echo Using output file: $OUTPUT_FILE
mkdir /tmp/create_reversed_video
#Get frame rate.
FRAME_RATE=$(ffmpeg -i "$VIDEO_FILE" 2>&1 | grep -o -P '[0-9\\. ]+fps' | grep -o -P '[0-9\\.]+')
echo The frame rate is: $FRAME_RATE
#Extract audio from video.
ffmpeg -i "$VIDEO_FILE" -vn -ac 2 /tmp/create_reversed_video/audio.wav
#Reverse the audio.
sox -V /tmp/create_reversed_video/audio.wav /tmp/create_reversed_video/backwards.wav reverse
#Extract each video frame as an image.
ffmpeg -i "$VIDEO_FILE" -an -qscale 1 /tmp/create_reversed_video/%06d.jpg
#Recombine into reversed video.
ls -1 /tmp/create_reversed_video/*.jpg | sort -r | xargs cat | ffmpeg -framerate $FRAME_RATE -f image2pipe -i - -i /tmp/create_reversed_video/backwards.wav "$OUTPUT_FILE"
#Delete temporary files.
rm -rf /tmp/create_reversed_video
I've tested it and it works well on my Ubuntu 18.04 machine on lots of videos (after installing the dependencies like sox). Please let me know if it works on other Linux distributions and versions.

Resources