FFMPEG is a library and series of command line tools for manipulating video format files.
Useful for:
Your solid state drives contain the FFMPEG library and command line tools already installed.
I compiled this library from source at https://www.ffmpeg.org/
To extract still images from a video encoded at 30 frames per second:
ffmpeg -i input.mp4 -vf fps=30 out%d.png
To create a video from a series of still images (starting at frame 1) using an MJPEG codec in an MPEG4 container at 30 frames per second:
ffmpeg -r 30 -start_number 1 -f image2 -i input_image_%d.ppm -vcodec mjpeg -qscale 1 video.avi
To create a video from a series of still images (starting at frame 1) using an H.264 codec in an MPEG4 container at 30 frames per second:
ffmpeg -r 30 -start_number 1 -f image2 -i input_image_%d.png -c:v libx264 output.mp4
To extract metadata information (number of frames) from an input_video:
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 video.avi
Example output from above command:
104
To extract metadata information (number of frames) from an input_video:
ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 video.avi
Example output from above command:
30/1
To extract metadata information (frame resolution) from an input_video:
ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width video.avi
Example output from above command:
streams_stream_0_width=720
streams_stream_0_height=1280
To invoke the ffmpeg or ffprobe commands above within a C program, you will need to use fork() and exec() functions.
fork() is used to launch a child process. When a program executes the fork() function, the operating system creates a new child process independent of the parent process that invoked it.
The exec() command tells the operating system to execute the process specified by exec. The program that launches the exec() command will terminate as the new process specified in the exec() function is executed.
Named pipes are a form of inter-process communication (IPC). A named pipe acts enables you to redirect output from one process (such as standard out) to a second process.
Using the fork() function, you can create a named pipe between the parent and child processes. This would enable the parent and child process to communicate with each other.
The named pipe, along with fork() and exec() enables you to execute and capture the output from ffmpeg or ffprobe. You could then parse this output to extract applicable information to store in your database.
An alternative method to using named pipes, fork(), and exec() is to use the popen() command.
The popen() function automatically forks a child processes then invokes a command shell to execute the command specified in popen(). The output from the command executed is then passed back through a named pipe to the parent process that launched popen().
Spring 2016, CS-161:
Lectures
Assignments:
Programs: