I have the following mp3 file
http://peterspace.de/speek.wav now I call this script
lame -b 128 --resample 44 speek.wav speek_resampled.mp3
lame --mp3input --resample 44 --decode -t speek_resampled.mp3
lame -r -s 44 speek_resampled.wav speek.new.mp3
but now the speek.new.mp3 plays to fast.. it seems that the raw pcm is not 44khz, but 22khz because
lame -r -s 22 speek_resampled.wav speek.new.mp3
gets a result witrh the right speed. Why isn't the raw format 44khz? even when i define "--resample 44" at decoding
the problem was that speek.wav is stereo, and in raw format this information was lost
Related
I tried to combine two video files with concat, blend and amx filter.
I've succeed two video when I used only video stream.
after then adding audio streams the code(filter script)
Ffmpeg didn't work.
two video crossfade(Good work)
ffmpeg -y -i "A.mp4" -i "B.mp4" -filter_complex
"[0:v]split[v000][v010];[1:v]split[v100][v110];[v000]trim=0:17[v001];
[v010]trim=17:27[v011t];[v011t]setpts=PTS-STARTPTS[v011];[v100]trim=0:10[v101];
[v110]trim=10:50[v111t];[v111t]setpts=PTS-STARTPTS[v111];[v101]
[v011]blend=all_expr='A*(if(gte(T,10),1,T/10))+B*(1-
(if(gte(T,10),1,T/10)))'[outv];[v001][outv][v111]
concat=n=3[outv2]" -vcodec libx264 -map [outv2] -t 50 d:\Output\1.mp4
1 + audio streams
ffmpeg -y -i "A.mp4" -i "B.mp4"
-filter_complex "[0:v]split[v000][v010];[1:v]split[v100][v110];[v000]trim=0:17[v001];[v010]trim=17:27[v011t];[v011t]setpts=PTS-STARTPTS[v011];[v100]trim=0:10[v101];[v110]trim=10:50[v111t];[v111t]setpts=PTS-STARTPTS[v111];[0:a]asplit[a000][a010];[1:a]asplit[a100][a110];[a000]atrim=0:17[a001];[v010]atrim=17:27[a011t];[a011t]asetpts=PTS-STARTPTS[a011];[a100]atrim=0:10[a101];[a110]atrim=10:50[a111t];[a111t]asetpts=PTS-STARTPTS[a111];[v101][v011]blend=all_expr='A*(if(gte(T,10),1,T/10))+B*(1-(if(gte(T,10),1,T/10)))'[outv];[a101][a011]amix=inputs=2:duration=first:dropout_transition=3[outa];[v001][outv][v111] [a001][outa][a111] concat=n=6:v=1:a=1:unsafe=1 [outv2][outa2]"
-vcodec libx264 -acodec aac -map [outv2] -map [outa2] -t 50 d:\Output\1.mp4
the Error message
Media type mismatch between the 'Parsed_blend_16' filter output pad 0 (video) and the 'Parsed_concat_18' filter input pad 1 (audio)
[AVFilterGraph # 026d3680] Cannot create the link blend:0 -> concat:1
Error initializing complex filters.
Invalid argument
How to fix it?
ps. I think the filter script is too complicated.
Could you let me know more easy way how to use crossfade with ffmpeg?
Solved If you want to use video and audio streams in a script at once you should write about video stream script after then do audio's.
"[0:v]split[v000][v010];[1:v]split[v100][v110];
[v000]trim=0:17[v001];[v010]trim=17:27[v011t];[v011t]setpts=PTS-STARTPTS[v011];
[v100]trim=0:10[v101];[v110]trim=10:50[v111t];[v111t]setpts=PTS-STARTPTS[v111];
[v101][v011]blend=all_expr='A*(if(gte(T,10),1,T/10))+B*(1-
(if(gte(T,10),1,T/10)))'[outv];
[v001][outv][v111] concat=n=3 [outv2];
[0:a]asplit[a000][a010];[1:a]asplit[a100][a110];[a000]atrim=0:17[a001];
[a010]atrim=17:27[a011t];[a011t]asetpts=PTS-STARTPTS[a011];
[a100]atrim=0:10[a101];[a110]atrim=10:50[a111t];
[a111t]asetpts=PTS-STARTPTS[a111];
[a101][a011]acrossfade=d=10[outa];
[a001][outa][a111] concat=n=3:v=0:a=1:unsafe=1 [outa2]"
I want to analyze a compressed video (h264).
I'm encoding using this command:
ffmpeg -i in_path -vf scale=340:256,setsar=1:1 -q:v 1 -c:v h264 -f
rawvideo out_path
now I want to see how the P&B frames look like, so I'm using this command in order extract only the b frames:
ffmpeg -ss 0 -i in_vid -t 2 -q:v 2 -vf
select="eq(pict_type\,PICT_TYPE_B)" -vsync 0 frameb%03d.jpg
The extraction went well, no errors, and the number of frames extracted makes since by theory.
But, I Don't know how to "show" the image, when I'm doing:
eog frameb001.jpg
I'm getting a normal picture and not what I expected from a B frame, now I understand why doing "eog" won't be good, but I have no idea how to "show" the frame so that it will be meaningful (saw some articles that use HSV to show the frame).
One more thing the fact that I got a meaningful image from the B frames, maybe the extraction wasn't good.
Any help will be great, Thanks a lot!
So easy and cool batch question. Sorry for this ultimate newbie question !
I've a folder which contains hundreds of videos like that:
Video001 - Introduction.avi
Video002 - History of Stack Overflow.avi
Video003 - Before Asking.avi
...
Video999 - Conclusion.avi
I need re-encode all of them with x264 codec. Ffmpeg is very slow so I tried to use HandBrake. There is a command line edition of HB and great default presents. I could write this command for converting only one file with "Normal" present:
HandBrakeCLI.exe -i "Video001 - Introduction.avi" -o "Video001 - Introduction.mp4" -Z Normal
My question: How can I convert all of them in folder and delete after conversion process? Thank you!
Note: If you think ffmpeg is better solution I can give my fav present. Handbrake says about Normal present:
Normal: -e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 -f mp4 --loose-anamorphic --modulus 2 -m --x264-preset veryfast --h264-profile main --h264-level 4.0
for %%f in (*.avi) do (
handbrakecli.exe -i "%%~nxf" -o "%%~nf.mp4" -Z Normal
del "%%~f"
)
For each avi file, call handbrake with the name and extension of input file and generate an output file with the name of the original file and .mp4 extension
I'm using ffmpeg to extract the audio from different video formats (flv, mp4) and convert it to mp3.
%~dp0ffmpeg.exe -i %1 -ar 44100 -ac 2 -ab 128k "%~dpn1.mp3"
This works just fine. However, in my input files, the audio bitrate varies, and I want to adjust the output bitrate accordingly. Even by extensive Google searching, I didn't find any hint how to just keep the original bitrate.
What I would need would be something like:
-ab copy
Which, of course, does not work.
Is there anything that will work?
P.S: As you might have figured from the formatting above, I'm using a windows batch file. There would be the hack to use %~dp0ffmpeg.exe -i, get the audio bitrate by grep and insert it in the command line. I just think there has to be an easier and more elegant way.
even though the original thread was looking for an answer without grepping anything, nate's script seems to be the most useful post. but it has some limitations, for example not all outputs give you a bitrate grepped, some turnout to give you just the result "default". here's a little more improved version of it.
#!/bin/env bash
ext=$1
for f in *.${ext}; do
x=${f%.*} ;
x=${x% - YouTube}; # I usually download some song covers from YouTube.
x=$x".mp3";
bit=`ffmpeg -i "${f}" 2>&1 | grep Audio | awk -F", " '{print $5}' | cut -d' ' -f1`
if [ -n "$bit" ]; then
ffmpeg -i "$f" -ab ${bit}k "$x"
else
ffmpeg -i "$f" "$x" # this is if we don't have an output from the grep line above, ffmpeg will keep the original quality, that is 192k for 192k
fi
done
Here is a bash script that will take a file extension and extract audio from any file with that extension, and of course maintain the bitrate. I can't claim the credit of the key piece of the code, as that goes to the gentleman that writes this blog.
#!/bin/bash
ext=$1
for file in *.${ext}; do
tmpfn=${file%.*} ; # get rid of file ext
tmpfn=$tmpfn".mp3"; # add mp3 file ext
# next line gets bitrate of audio from video using ffmpeg
bit=`ffmpeg -i "${file}" 2>&1 | grep Audio | awk -F", " '{print $5}' | cut -d' ' -f1`
# finally, convert to mp3 using proper bitrate
ffmpeg -i "$file" -ab ${bit}k "$tmpfn"
done
Just run it in the directory where you have the files like so:
$bash script.sh flv
where flv is the file extension. Hack it to make it do exactly as you wish or process multiple filetypes to your heart's content.
EDIT: Just a quick note for anyone on Ubuntu/debian/etc. Make sure you install the additional codec package or else it won't work, i.e. you must install ffmpeg and the extra libav codec package or you're gonna have a bad time. This should do the trick:
sudo apt-get ffmpeg libavcodec-extra-53
As LordNeckbeard states, using the same bitrate to encode in different formats isn't necessarily wise. However...
Here is a batch-file solution which captures the input file bitrate and uses that as a parameter for the encoding command line. This approach was hinted at by the original questioner. The mp3 output file is created in the same folder as the input file.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM Usage: scriptname.cmd "full-quoted-path-to-input-file"
REM Adjust FFMPEG_PATH variable value to match the path to your FFMPEG binary
SET FFMPEG_PATH=C:\Program Files\ffmpeg-20170807-1bef008-win64-static\bin
SET INPUT_FILE_FULL_PATH=%1
REM Get input file bitrate
FOR /F "tokens=5 delims==," %%i IN ('""%FFMPEG_PATH%\ffmpeg.exe" -i %INPUT_FILE_FULL_PATH% 2>&1 | find "Audio:""') DO (
FOR /F "tokens=1 delims==k" %%j IN ('ECHO %%i') DO (
SET BITRATE=%%j
SET BITRATE=!BITRATE: =!
ECHO Input file bitrate is !BITRATE! kb/s
)
)
REM Encode file using previously captured bitrate
"%FFMPEG_PATH%\ffmpeg.exe" -i %INPUT_FILE_FULL_PATH% -ar 44100 -ac 2 -ab !BITRATE!k "%~dpn1.mp3"
There is scope for tightening the code up, for example, a check to make sure at least one argument was provided, and that the BITRATE is not empty before beginning the encode, but as a rough and ready solution this should do fine.
Current version of ffmpeg (tested 2.1.4) recommends using "-qscale 0" to preserve quality. This worked for me on my mpeg4 video test file.
Try this option: -codec copy or -acodec copy for only audio.
Check this reference http://ffmpeg.org/ffmpeg.html#Stream-specifiers-1
Instead of
-ab copy
try
-sameq
%~dp0ffmpeg.exe -i %1 -sameq "%~dpn1.mp3"
how do I extract 12byte chunks from a binary file at certain positions within the file.
If I wanted to extract the first 12 bytes I could do something like
head -c12 file.bin>output
If I wanted to extract 12 bytes from byte61 I could do something like
head -c72 file.bin|tail -c12 >output
Is there a simpler way if I have something like 20 12byte chunks I need to extract
thanks
Use dd:
dd bs=1 seek=60 count=12 if=file.bin of=output
You can write a shell loop to substitute the numbers.
You could also consider using awk, Perl or Python, if there's a lot of them to do or it needs to be really fast.
Using xxd:
xxd -p -seek 3d -l 12 file.bin > output
3d means 61 in hexadecimal
Using hexdump:
hexdump -ve '16/1 "%0.2x " "\n"' -s 3d -n 12 file.bin > output