How to extract duration time from ffmpeg output?
ffmpeg is writing that information to stderr
, not stdout
. Try this:
ffmpeg -i file.mp4 2>&1 | grep Duration | sed 's/Duration: \(.*\), start/\1/g'
Notice the redirection of stderr
to stdout
: 2>&1
EDIT:
Your sed
statement isn't working either. Try this:
ffmpeg -i file.mp4 2>&1 | grep Duration | awk '{print $2}' | tr -d ,
Using ffmpeg to obtain video durations in python
There is no need to iterate though the output of FFprobe
. There is one simple command which returns only the duration of the input file:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 <input_video>
You can use the following method instead to get the duration:
def get_length(input_video):
result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', input_video], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return float(result.stdout)
How to find duration of a video file using mediainfo in seconds or other formats?
Use the following commands:
i) To get the duration of video stream:
$ mediainfo --Inform="Video;%Duration%" [inputfile]
ii) To get the duration of the media file:
$ mediainfo --Inform="General;%Duration%" [inputfile]
iii) To get the duration of audio stream only:
$ mediainfo --Inform="Audio;%Duration%" [inputfile]
iv) To get values of more than one parameter:
$ mediainfo --Inform="Video;%Width%,%Height%,%BitRate%,%FrameRate%" [inputfile]
Output would be something like this:
1280,720,3000000,30.0
How to get video duration in seconds?
2383 is correct. There are 60 seconds in a minute, not 100. 43/60 = .71
https://www.google.com/#q=39+minutes+43.08+seconds+in+seconds
How to get the real, actual duration of an MP3 file (VBR or CBR) server-side
I finally found a proper solution to this problem using sox - which returns the correct information.
sox file.mp3 -n stat
Samples read: 19321344
Length (seconds): 219.062857
Scaled by: 2147483647.0
Maximum amplitude: 1.000000
Minimum amplitude: -1.000000
Midline amplitude: -0.000000
Mean norm: 0.141787
Mean amplitude: 0.000060
RMS amplitude: 0.191376
Maximum delta: 0.947598
Minimum delta: 0.000000
Mean delta: 0.086211
RMS delta: 0.115971
Rough frequency: 4253
Volume adjustment: 1.000
Length (seconds): 219.062857
Related Topics
How to Display Number to Two Decimal Places in Bash Function
How to Kill a Process Running on Particular Port in Linux
"Unable to Find Remote Helper For 'Https'" During Git Clone
How to Get Docker Linux Container Information from Within the Container Itself
How to Instruct Cron to Execute a Job Every Second Week
Return Value of Sed For No Match
How to Only Get File Name With Linux 'Find'
Linux and I/O Completion Ports
How Is the System Call in Linux Implemented
Convert String to Hexadecimal on Command Line
Glibc Scanf Segmentation Faults When Called from a Function That Doesn't Align Rsp
./Configure: /Bin/Sh^M: Bad Interpreter
How to Parse Xml Using Shellscript
What Is Better "Int 0X80" or "Syscall" in 32-Bit Code on Linux
What Are the Return Values of System Calls in Assembly
What Is the Maximum Size of a Linux Environment Variable Value