|
| 1 | +# ffmpeg |
| 2 | + |
| 3 | +CLI front-end for the FFmpeg library. Can do tons of conversions and streaming. |
| 4 | + |
| 5 | +Tested on Ubuntu 15.10. |
| 6 | + |
| 7 | +List codecs: <http://stackoverflow.com/questions/3377300/what-are-all-codecs-supported-by-ffmpeg> |
| 8 | + |
| 9 | + ffmpeg -codecs |
| 10 | + |
| 11 | +## Extract raw streams |
| 12 | + |
| 13 | +### H264 |
| 14 | + |
| 15 | +- <http://stackoverflow.com/questions/10380045/is-there-any-easy-way-to-extract-h-264-raw-stream-in-annexb-format> |
| 16 | +- <http://stackoverflow.com/questions/19300350/extracting-h264-raw-video-stream-from-mp4-or-flv-with-ffmpeg-generate-an-invalid> |
| 17 | + |
| 18 | +Works: |
| 19 | + |
| 20 | + ffmpeg -i in.mp4 -vcodec copy -bsf h264_mp4toannexb -an -f h264 out.h264 |
| 21 | + |
| 22 | +VLC cannot open that output file, but `ffplay` can. TODO: is the `-bsf` really needed? |
| 23 | + |
| 24 | + ffmpeg -i in.mts -vcodec copy -an -f h264 out.h264 |
| 25 | + |
| 26 | +### AAC |
| 27 | + |
| 28 | +<http://superuser.com/questions/186465/extract-audio-aac-from-mp4> |
| 29 | + |
| 30 | + ffmpeg -i in.mp4 -c copy -map 0:a:0 out.aac |
| 31 | + |
| 32 | +## Webcam |
| 33 | + |
| 34 | +<https://trac.ffmpeg.org/wiki/Capture/Webcam> |
| 35 | + |
| 36 | +First install `v4l2`, then: |
| 37 | + |
| 38 | + ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 -f v8 output.mkv |
| 39 | + |
| 40 | +## ffplay |
| 41 | + |
| 42 | +Minimalistic video preview tool. |
| 43 | + |
| 44 | + ffplay video.mp4 |
| 45 | + |
| 46 | +No controls, no nothing, just a window with the video. |
| 47 | + |
| 48 | +Loop infinitely: |
| 49 | + |
| 50 | + ffplay -loop -1 video.mp4 |
| 51 | + |
| 52 | +## Stream |
| 53 | + |
| 54 | +<https://trac.ffmpeg.org/wiki/StreamingGuide> |
| 55 | + |
| 56 | +## ffserver |
| 57 | + |
| 58 | +<https://trac.ffmpeg.org/wiki/ffserver> |
| 59 | + |
| 60 | +TODO: what is the IO format: RTMP of HTTP? How is video sent over HTTP? |
| 61 | + |
| 62 | +Note: this project seems very unmaintained, and there are better ones out there. |
| 63 | + |
| 64 | +Server configuration file: |
| 65 | + |
| 66 | + /etc/ffserver.conf |
| 67 | + |
| 68 | +Use a custom one and show server debug: |
| 69 | + |
| 70 | + ffserver -d -f ~/ffserver.conf |
| 71 | + |
| 72 | +Start server: |
| 73 | + |
| 74 | + ffserver |
| 75 | + |
| 76 | +Send video to it. Must edit the `VideoFrameRate` to something larger than 3... <https://lists.ffmpeg.org/pipermail/ffmpeg-user/2016-January/030111.html>: |
| 77 | + |
| 78 | + ffmpeg -f v4l2 -s 320x240 -r 25 -i /dev/video0 -f alsa -ac 2 -i hw:1 http://localhost:8090/feed1.ffm |
| 79 | + |
| 80 | +Watch it. Must edit ACL inside `feed` <http://stackoverflow.com/a/13977181/895245> or else access denied: |
| 81 | + |
| 82 | + ffplay http://localhost:8090/test1.mpg |
| 83 | + |
| 84 | +TODO: video has a huge delay from starting up to playing, see: <https://trac.ffmpeg.org/wiki/StreamingGuide#Latency> |
| 85 | + |
| 86 | +A few URLs that can be accessed from the browser: |
| 87 | + |
| 88 | +- <http://localhost:8090/stat.html>: show server status |
| 89 | +- <http://localhost:8090/>: redirect to what is fixed at `<Redirect index.html>` of the config file |
| 90 | +- <http://localhost:8090/test1.mpg>: TODO what happens? Firefox sees a video file type, and redirects to a video app, then when I kill the server the video player plays all that has happened as if from a file. |
| 91 | + |
| 92 | +## udp protocol |
| 93 | + |
| 94 | +An FFmpeg invention it seems: <http://stackoverflow.com/questions/27930879/what-is-ffmpegs-udp-protocol> |
0 commit comments