Have adapted FFmpeg sample muxing.c under Windows 7 to write MP4 files from video camera RGB data.
Using muxing.c default bit_rate=400000.
Am not setting global_quality.
Resultant MP4 is poor quality, highly pixelated.
Original raw images in video camera are sharp.
What values should I use for bit_rate? Do I have to also set rc_max_rate?
What values should I use for global_quality? Do I have to set any flags to enable use of global_quality?
Is bit_rate versus global_quality an either/or situation? Or can both be useful in adjusting quality?
Thanks for your time.
Related
Is there any tool or script for batch converting animated webp images?
I want to create animated thumbnails from my animated webp images:
resize image size
reduce quality (lossy compression)
reduce frame rate
I tried tools like ImageMagick, but they cannot change the frame rate.
If you just want to change the framerate, the webpmux tool from Google (available as the webp package on your Linux OS) can do the job quickly and easily.
First you need to know the current duration interval for the source file - there are several ways to do that, but the webpinfo from the same package is maybe the easiest - webpinfo source.webp the note the duration listed for the frames.
Then calculate your new desired frame rate - if the source animation had an FPS of 10, it would show a duration of 100. To change it to 25, divide 100ms duration by 2.5 (the multiplier to go from 10 to 25), which will get you a target duration of 40ms.
Finally run webpmux -duration 40 source.webp -o destination.webp to create a copy of the source animation with a changed interhframe duration.
ffmpeg can't decode animated WebP
See #4907: Support decoding animated WebP images.
Use another tool, such as anim_dump, to extract the WebP frames. See How can I convert an animated WebP to a WebM? for more info and examples.
Once you have the frames you can use ffmpeg.
Example
10 fps, half size:
ffmpeg -framerate 25 -i input_%03d.webp -vf "fps=10,scale=iw/2:-1" -quality 25 output.webp
To encode WebP, ffmpeg must be compiled with --enable-libwebp.
resize image size
Use the scale filter.
reduce quality (lossy compression)
Use the -quality option for the encoder libwebp. Range is 0-100. Default is 75.
Optionally, use the -preset option to match the content type.
See ffmpeg -h encoder=libwebp for more options and info.
reduce frame rate
Use the fps filter or the -r option.
After getting help from https://stackoverflow.com/a/40601020/6318164 on how to convert webm to mp4. The result avoiding losing the video ratio by setting the height resolution with -vf scale=-2:720.
I then came across another problem. I've found both width and height had to be supported for the video players, when I thought it was just the height that had to be specified.
After browsing around I found this script https://stackoverflow.com/a/35487394/6318164 were I can change the video's canvas to a common width and height standard. It shrinks the video to fit inside the center of specified canvas without losing the ratio while filling the empty space with black padding if I'm correct, which is the result I want.
However, although it solved the playback problems in all the players, I've found different video players show different resolution information of the same video.
I've modified the script here for Linux terminal use.
X=1280; Y=720; ffmpeg -i old.webm -t 5 -vf "scale=min(iw*$Y/ih\,$X):min($Y\,ih*$X/iw),pad=$X:$Y:($X-iw)/2:($Y-ih)/2" new.mp4
This is the research on the resolution differences I've found for value I set.
X=1280; Y=720;
webm -> mp4
=========================================================
1280x752 -> 1280x720 X-plore (Android)
Not supported -> 1339x720 Telegram (Android)
1338x752 -> 1340x720 GNOME MPlayer (Linux)
Not supported -> ???????? Built-in Video Player (Android)
The question is, I'm I doing anything wrong with the ffmpeg conversion to return incorrect resolutions for different players? I checked out some other videos I have and they show the correct resolutions except this converted one.
Edit
With the help of the accepted answer. This was my working output if anyone needs it:
X=1280; Y=720; ffmpeg -i input.webm -vf "scale='if(gt(a*sar,16/9),${X},${Y}*iw*sar/ih)':'if(gt(a*sar,16/9),${X}*ih/iw/sar,${Y})',pad=${X}:${Y}:(ow-iw)/2:(oh-ih)/2,setsar=1" output.mp4
Add setsar=1 after pad.
Also, your scale expression doesn't account for videos with non-square pixels. Use the expression in this answer.
I am studying on the source identification of video files especially about those from smartphones.
I got to know that the values in avcC box in .mp4 video files have the encoding options(h.264) which decoder must know when processing the encoded stream.
And I guess most of the smartphone uses the customized FFmpeg to encode the raw stream. I want to know if the values in the avcC box are affected only by the version of FFmpeg(if not customized version is used).
I didn't delve into this but think that the libavcodec.so in FFmpeg fill the values in avcC box when doing encoding(is this right?).
So what I want to ask is if two different smartphones use the same libavcodec.so(even in the case whether other .so files, .apk file used for the recording, etc are different) and two video files which have the same resolution were filmed from each smartphone, do the values in avcC box the same?
I think this question may equal to "are the values in avcC box affected by other FFmpeg library or other layers in overall Android framework"?
++ there is one more question! Is there any case that two videos which have same resolution from the same smartphone have different values in avcC box? (I suggest the the difference of encoding option originating from low-battery mode, execution conditions of other apps, etc and if any core developer customize FFmpeg for that.)
It would be a great help if anyone let me know the answer~!
the avcC box contains the out of band extradata for the AVC stream. This stores way more than just resolution, such as profile, level, entropy encoding mode, color space information, etc. This is a standard, ffmpeg just implements that standard. iPhones for example produce perfectly valid mp4 file and do not use libav* / ffmpeg. See exactly what is is the avcC box here Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream
I am right now using ffmpeg library to extract image from 1080i YUV 422 raw file. As i use interlaced data, it will drop some lines when i extracct image from one frame of video, Is it possible to merge two or three frame and make a single high definition image? Please guide me to move forward
i need to convert videos from .mp4 to .mp4 (only videos that are disproportionate between quality and size), I've tried with ffmpeg and mencoder, but can not play with fwplayer, any ideas??.
Try using MeGUI, it has presets for low quality exporting for Flash and such.