Speed up video encoding - ffmpeg

My task is to create html5 compatible video from input video (.avi, .mov, .mp4, etc.). My understanding is that my output should be .webm or .mp4 (H264 video, aac audio).
I use ffmpeg for conversion and it takes a lot of time. I wonder if I could use ffprobe to test if input video is "H264" and "aac" and if so then maybe I could just copy video/audio into output without modifications.
I.e. I have next idea:
Get input video info using ffprobe:
ffprobe {input} -v quiet -show_entries stream=codec_name,codec_type -print_format json
The result would be JSON like this:
"streams": [
{codec_name="mjpeg",codec_type="video"},
{codec_name="aac",codec_type="audio"}
]
If JSON tells that video codec is h264 then I think I could just copy video stream. If JSON tells that audio codec is h264 aac then I think I could just copy audio stream.
JSON above tells that my audio is "aac". So I think I could just copy audio stream into ouput video but still needs video stream conversion. For the above example my ffmpeg command would be like:
ffmpeg -i {input} -c:v libx264 -c:a copy ouput.mp4
The question is if I could always use this idea to produce html5 compatible video and if this method will actually speed up video conversion.

The question is if I could always use this idea to produce html5 compatible video
Probably, but some caveats:
Your output may use H.264 High profile, but your target device may not support that (but that is not too likely now).
Ensure that the pixel format is yuv420p. If it is not then it may not play and you will have to re-encode with -vf format=yuv420p. You can check with pix_fmt in your -show_entries stream.
If the file is directly from a video camera, or some other device with inefficient encoding, then the file size may be excessively large for your viewer.
Add -movflags +faststart to your command so the video can begin playback before the file is completely downloaded.
and if this method will actually speed up video conversion.
Yes, because you're only stream copying (re-muxing) which is fast, and not re-encoding some/all streams which is slow.

Related

Converting to HLS VS MPEGTS

I am creating streamable audio by using ffmpeg like this:
ffmpeg -i test.mp3 -vn -ac 2 -acodec aac -f segment -segment_format mpegts -segment_time 10 -segment_list playlist.m3u8 playlist-%05d.ts
My goal was to create content in the HLS format and it seems to work (it is playable by hls.js). I just wonder about the segment_format which is mpegts, is that correct? By reading the answer here mpegts seems to be a different format than HLS. Which is it?
The ffmpeg script above is generating .ts-files for the chunks and an .m3u8-file for the playlist. Is it possible to play this playlist on all devices that supports m3u-playlist? What is the difference between old Winamp-m3u-playlists and the hls format?
Is the .ts files still in the same content type as the mp3?
mpegts seems to be a different format than HLS. Which is it?
It’s both. HLS is not a file type, it a collect of technologies used together to encode and deliver media over Http. One of the technologies is TS
Is it possible to play this playlist on all devices that supports m3u-playlist?
All devices? Probably not. Nobody can guarantee something to work on all devices. You need to test the devices you care about.
Is the .ts files still in the same content type as the mp3?
What do you mean by “content type”? Your ffmpeg command has a mp3 an input and a ts wrapped aac stream out. So no, I guess. Unless by content type you mean audio, then yes.

How I can convert any mp4 to adv8dvbt23.ts file?

I can download http://www.w6rz.net/adv8dvbt23.ts.
And there are many samples for dvbt sample ts files.
But, I want to convert my video file to TS file for dvbt.
First, I checked on google, but I cannot find any answer.
I think, this does not make sense, or, the way of thinking may have been wrong.
FFmpeg can used for this?
but, there is no any parmameter for Transmit mode, QAM / 64QAB, guard interval.
FFmpeg can used for this? but, there is no any parmameter for Transmit mode, QAM / 64QAB, guard interval.
As I explained already:
ffmpeg doesn't know anything about RF things like Constellation type; it is just a tool to transcode between different video formats. .ts is for "transport stream", and it's the video container format that DVB uses. The GNU Radio transmit flowgraphs on the other hand know nothing about video things – all they do is take the bits from a file. So that file needs to be in a format that the receiver would understand, and that's why I instructed you to use FFMPEG with the parameters you need. Since I don't know which bitrate you're planning on transmitting, I can't help you with how to use ffmpeg
So, you need to generate video data that your DVB-T receiver understands, but more importantly even, you need to put them in a container that ensures constant bitrate.
As pointed out in a different comment to your ham.stackexchange.com question about the topic, your prime source of examples would be GNU Radio's own gr-dtv module; when you look into gnuradio/gr-dtv/examples/README.dvbt, you'll find a link to https://github.com/drmpeg/dtv-utils , W6RZ's own tooling :)
There you'll find the tools necessary to calculate the exact stream bitrate you need your MPEG transport stream to have. Remember, a DVB-T transmitter has to transmit at a constant bits per second, so your video container must be constant-bitrate. That's why a transport stream pads the video data to achieve constant rate.
Then, you'll use ffmpeg to transcode your video and put into the transport stream container:
ffmpeg -re -i inputvideo.mpeg \
-vcodec mpeg2video \
-s 720x576 #resolution; this is a good choice, since most TVs will deal with it \
-r 25 #frames per second, use 25\
-flags cgop+ilme -sc_threshold 1000000000 #MPEG codec options\
-b:v 2M #Video *codec data* bit rate (defines video quality). Must be lower than stream bit rate, so < muxrate-(audio bitrate)\
-minrate:v 2M -maxrate:v 2M #enforce constant video bit rate\
-acodec mp2 -ac 2 -b:a 192k #audio codec, quality and bitrate\
-muxrate ${RATE FROM TOOL}
-f mpegts #specify you want a MPEG Transport Stream container as output\
outputfile.ts

Http live stream video segmenting. non-Mac approach

Anyone knows a good way to use http live streaming tools on non-Mac platforms?
Can you tell me at least if there's good alternatives? I need mediafilesegmenter and mediastreamvalidator.
Or maybe anyone has a source code or something like that...
UPD: I've tried different segmenters, most of them are based on Carson's open-sourced segmenter. Now the difference between Apple's mediafilesegmenter and this one, that it takes only a transport stream, not just any video. And I need to segment h264 videos.
When I use ffmpeg to convert h26s to mpeg-ts I'm getting much bigger files in the end. Even if I try to preserve same audio codec (aac) it changes video codec form avc to mpeg-ts.
Damn I hate Apple. How can they propose that thing as a standard if they don't even provide workarounds for another platforms.
I still need to find a way to segment h264 videos, and keep in the segmented files avc and aac codecs.
If you're not specifying the video codec, and specifying an mpeg2 transport stream container, FFmpeg will default to MPEG2 video coding. If you already have MPEG4-AVC(h.264) encoded video and AAC audio, then you instruct FFmpeg to not re-encode the video and audio with these options: -vcodec copy -acodec copy
Your final command should be something like this:
ffmpeg -i inputfile -vcodec copy -acodec copy -f mpegts outputfile.ts
Then you can use one of the segmenter tools for segmenting and building the playlist. It's worth mentioning that new versions of FFmpeg support segmenting, but you still would need a program to create the playlist file.

What parameters or software is best to use to convert .MP4 to .FLV

I'm on Windows 7 and i have many .MP4 video that i want to convert on .flv. I have try ffmpeg and Free FLV converter, but each time the results are not what i'm looking for.
I want a video of same quality (or almost, looking good) and a more little size for the video, because right now, each time i have made a try, the video result is pretty bad and the video size just increase.
How can i have a good looking video, less in size and in .FLV ?
Thanks a lot !
First, see slhck's blog post on superuser for a good FFmpeg tutorial. FLV is a container format and can support several different video formats such as H.264 and audio formats such as AAC and MP3. The MP4 container can also support H.264 and AAC, so if your input uses these formats then you can simply "copy and paste" the video and audio from the mp4 to the flv. This will preserve the quality because there is no re-encoding. These two examples do the same thing, which is copying video and audio from the mp4 to the flv, but the ffmpeg syntax varies depending on your ffmpeg version. If one doesn't work then try the other:
ffmpeg -i input.mp4 -c copy output.flv
ffmpeg -i input.mp4 -vcodec copy -acodec copy output.flv
However, you did not supply any information about your input, so these examples may not work for you. To reduce the file size you will need to re-encode. The link I provided shows how to do that. Pay special attention to the Constant Rate Factor section.

FFmpeg: Changing output bitrate dynamically

I use ffmpeg to encode a video file to an mpeg transport stream (.ts), which is subsequently sent over network. If there is any network bandwidth fluctuation, I want to dynamically change the stream's bitrate.
My current solution involves restarting ffmpeg with a different bitrate as below
`ffmpeg -i input.avi -ss <resume point> -b:v <new bitrate> output.ts
Unfortunately, for certain i/p file formats, glitches get introduced in the video stream using the above approach. So I am looking for a solution where ffmpeg's output bitrate can be changed dynamically, possibly using signals

Resources