ffmpeg http slower than downloading first - ffmpeg

When trying to get a clip of a video from a remote source
Input source:
ffprobe version 3.3.2-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2007-2017 the FFmpeg developers
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://website.com/video.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2017-07-13T15:44:58.000000Z
Duration: 00:57:32.42, start: 0.000000, bitrate: 1939 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 720x480 [SAR 10:11 DAR 15:11], 1745 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc (default)
Metadata:
creation_time : 2017-07-13T15:44:58.000000Z
handler_name : Mainconcept MP4 Video Media Handler
encoder : AVC Coding
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
Metadata:
creation_time : 2017-07-13T15:44:58.000000Z
handler_name : Mainconcept MP4 Sound Media Handler
Current command:
ffmpeg version 3.3.2-static
ffmpeg.linux -threads 2 -y -ss 3273 -i "http://website.com/video.mp4" -an -movflags +faststart -preset veryfast -codec copy /outputfolder/trimmed_video.mp4
This 5m35.102s to create a 45mb 2min file.
If I download the file using wget it takes 28s and using ffmpeg only takes 0.243s
If I add -vn OR -an to the output portion of the command it completes the trim in about 2.101s. Meaning it's faster to download the two stream and merge them myself.
Can anyone explain this behaviour and why my first command takes so long when on a lot of other video files it's very fast?

Videos where the command completed fast were optimized for streaming by youtube.
User uploaded media was not optimized.
Running ffmpeg with -movflags +faststart on the files fixed the issues server side.

Related

How to trim webm video while preserving transparency

I want to trim a transparent webm video using ffmpeg. Here's the ffprobe result for that video:
Input #0, matroska,webm, from 'template.webm':
Metadata:
ENCODER : Lavf58.29.100
Duration: 00:00:05.24, start: -0.002000, bitrate: 2856 kb/s
Stream #0:0: Video: vp8, yuv420p(progressive), 1573x900, SAR 1:1 DAR 1573:900, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Metadata:
ALPHA_MODE : 1
ENCODER : Lavc58.54.100 libvpx
DURATION : 00:00:05.240000000
Stream #0:1: Audio: opus, 48000 Hz, mono, fltp
Metadata:
ENCODER : Lavc58.54.100 libopus
DURATION : 00:00:05.241000000
I tried
ffmpeg -i template.webm -ss 1 -to 3 -c copy trimmed.webm
but the trimmed video doesn't start (or sometimes end) at the exact times defined in the command so I tried re-encoding the video using libvpx
ffmpeg -i template.webm -ss 1 -to 3 -c:v libvpx -c:a copy -crf 30 -b:v 0 trimmed.webm
It solved the timing issue but this results in loss of transparency of output video. Here's the ffprobe:
Input #0, matroska,webm, from 'trimmed.webm':
Metadata:
ENCODER : Lavf57.83.100
Duration: 00:00:02.00, start: -0.001000, bitrate: 1395 kb/s
Stream #0:0: Video: vp8, yuv420p(progressive), 1573x900, SAR 1:1 DAR 1573:900, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Metadata:
ALPHA_MODE : 1
ENCODER : Lavc57.107.100 libvpx
DURATION : 00:00:02.000000000
Stream #0:1: Audio: opus, 48000 Hz, mono, fltp
Metadata:
ENCODER : Lavc58.54.100 libopus
DURATION : 00:00:02.001000000
How should I trim the video while preserving the transparency? Moreover, a fast solution will be extremely helpful.
The native, built-in FFmpeg VP8 decoder does not yet support alpha/transparency. Use libvpx to decode:
ffmpeg -c:v libvpx -i template.webm -ss 1 -to 3 -c:v libvpx -c:a copy -crf 30 -b:v 0 trimmed.webm
If you get Transparency encoding with auto_alt_ref does not work error then add the -auto-alt-ref 0 output option or change -c:v libvpx output option to -c:v libvpx-vp9.

Create image with audio and concate to another video

Please help me understand! I spent a lot of time...:( Thank you!
I'm stuck with a problem. I have a stream with damaged video and normal audio. And 2nd video, continued, with normal video and audio. I want to attach a picture to the beginning of an undamaged video with normal audio from damaged video without re-encoding the normal video.
I try this one:
ffmpeg -hide_banner -loop 1 -framerate 50 -t 3478 -i image.jpg -t 3478 -i audio.mp3 -i video.mp4 -filter_complex "[0:0] [1:0] [2:0] [2:1] concat=n=2:v=1:a=1" output.mp4
But it converts normal video.
Mediainfo from normal video:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:56:31.61, start: 0.000000, bitrate: 3726 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3594 kb/s, 27.46 fps, 50 tbr, 50k tbn, 100 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler

FFMPEG add text frames to the start of video

I have some videos either in mp4 or webm format, and I'd like to use ffmpeg to add 4 seconds to the start of each video to display some text in the center with no sound.
Some other requirements:
try to avoid re-encoding the video
need to maintain the quality (resolution, bitrate, etc)
(optional) to make the text fade in/out
I am new to ffmpeg and any help will be appreciated.
thanks in advance
Example ffprobe information for mp4 below:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.33.100
Duration: 00:00:03.84, start: 0.042667, bitrate: 1117 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1021 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 140 kb/s (default)
Metadata:
handler_name : SoundHandler
Example webm
Input #0, matroska,webm, from 'input.webm':
Metadata:
encoder : Lavf55.33.100
Duration: 00:00:03.80, start: 0.000000, bitrate: 1060 kb/s
Stream #0:0(eng): Video: vp8, yuv420p, 1280x720, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Stream #0:1(eng): Audio: vorbis, 48000 Hz, stereo, fltp (default)
Screenshot from joined.mp4
Screenshot for step 3 console
You'll have to generate a 4 second video with dummy audio matching the parameters of the existing video, including timebase, and then use the concat demuxer with streamcopy.
For the sample files shown in Q:
Step 1 Generate text video
ffmpeg -f lavfi -r 30 -i color=black:1280x720 -f lavfi -i anullsrc -vf "drawtext=fontfile='/path/to/font.ttf':fontcolor=FFFFFF:fontsize=50:text='Your text':x='(main_w-text_w)/2':y='(main_h-text_h)/2',fade=t=in:st=0:d=1,fade=t=out:st=3:d=1" -c:v libx264 -b:v 1000k -pix_fmt yuv420p -video_track_timescale 15360 -c:a aac -ar 48000 -ac 2 -sample_fmt fltp -t 4 intro.mp4
For WebM, replace -c:v libx264 with -c:v libvpx, -c:a aac with -c:a libvorbis and intro.mp4 with intro.webm. You may remove the -video_track_timescale 15360 since WebMs tend to use a single timescale, that I've seen.
Step 2 Prepare concat file, say, list.txt
file 'intro.mp4'
file 'input.mp4'
Step 3 Concat
ffmpeg -f concat -i list.txt -c copy -fflags +genpts joined.mp4
The variables important here are video size 1280x720, frame rate -r 30, -pix_fmt yuv420p, sample rate -ar 48000, format -sample_fmt fltp, channel layout -ac 2 and of course, codecs.
Short answer is that you cannot encode new data as mp4 or webm and insert it at the front of the video stream. Those formats simply do not work like that. Both of these encoding formats are lossy, so if you decode and encode them again then additional information will be lost/changed by the second encoding. You could do something else, but what you are trying to do will not work.

HTML5 Video OGV conversion on Mac

When I try recording a screencast with Quicktime or Screenflow and then converting to .ogv for use on the web, I get this error many times:
$ ffmpeg2theora test.mov
[audioresample # 0x7fa903800ee0] Audio sample format conversion failed
The resulting test.ogv file does not play in VLC. I can use ffmpeg to successfully convert mov to mp4. Are there only certain audio types that ffmpeg2theora supports? ffmpeg2theora version 0.29
More output:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2013-08-26 20:50:37
Duration: 00:00:07.00, start: 0.000000, bitrate: 1458 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 90 kb/s
Metadata:
creation_time : 2013-08-26 20:50:37
handler_name : Apple Alias Data Handler
Stream #0:1(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1200, 1362 kb/s, 30 fps, 30 tbr, 3k tbn, 6k tbc
Metadata:
creation_time : 2013-08-26 20:50:37
handler_name : Apple Alias Data Handler
brew remove ffmpeg
brew install --with-theora --with-libvorbis ffmpeg
ffmpeg -i test.mov -c:v libtheora -c:a libvorbis -q:v 10 -q:a 10 test.ogv
You may be specifically interested in ffmpeg solution, but the Miro Video Convertor is another free OS X option that works great for converting mov to ogg.

Demux audio (AMR_WB) and video(H264) from mp4 file using ffmpeg

I want to demux audio (AMR_WB) and video(H264) from an mp4 file. I need to write a program which does this using ffmpeg libraries.
In demuxing.c file which is there in FFMPEG examples i was able to get only the raw formats as the output.
Can i somehow modify that code to get H264 and AMR_WB in encoded format from the mp4 file?
Run ffmpeg twice , each time specify that just 1 track be copy to output.
Example on diff mp4 will provide most of the idea which u will need to adapt to your specific track types for the respective video/audio in your container...
MP4 example : demux h264 and aac tracks to separate outputs (tout1, tout2 )
Whats in input?
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'phoneCam_20120902_112701.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2012-09-02 18:27:14
Duration: 00:00:12.65, start: 0.000000, bitrate: 8011 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 7707 kb/s, SAR 65536:65536 DAR 16:9, 28.64 fps, 29.83 tbr, 90k tbn, 180k tbc
Metadata:
creation_time : 2012-09-02 18:27:14
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, s16, 96 kb/s
Pass 1, just get the Vid
ffmpeg -i phoneCam_20120902_112701.mp4 -map 0:0 -c copy tout1.mp4
Pass2 just get the aud
ffmpeg -i phoneCam_20120902_112701.mp4 -map 0:1 -c aac -ar 48000 -ab
48000 -strict -2 tout2.3gp
In your program, just run ffmpeg from the CLI or call main() in ffmpeg.c

Resources