Friday, December 27, 2019

Interview Googleyness



https://www.paysa.com/blog/5-questions-to-study-for-your-google-interview/
They want to see you have “Googleyness”: a combination of work ethic, creative thinking and appetite for learning that shows you have what it takes to thrive in the fast-paced, highly analytical environment at Google

https://www.fastcompany.com/40458298/6-ex-googlers-share-how-they-landed-the-job
Googleyness is a reflection of your personality and has a number of elements, Miller says. “How easy are you to get along with? With the Google recruiting process, one question that you have to pass is every person who interviews you is asked, Would you want to work with this person every single day? Would you be happy if you sat next to this person every single day? Would you be able to do good work, and would you enjoy their company?” he says.
Look out for the phrase “Tell me a time when…” during your interview, Miller says. Interviewers use this phrase to ask questions like “‘Tell me a time when you overcame adversity’ to get you to talk about subject matters. For example, if you worked in marketing previously and talked about how you failed to get organic traffic to the website, they would ask about what you did when your boss came down on you.”

https://www.businessinsider.com/what-google-looks-for-in-employees-2015-4

Google want people with high "cognitive ability."

"If you hire someone who is bright, and curious, and can learn, they're more likely to come up with a new solution that the world hasn't seen before," Bock explained in a Google+ Q&A. "This looking for cognitive ability stems from wanting people who are going to reinvent the way their jobs are going to work rather than somebody who's going to come in and do what everybody else does. We recruit for aptitude, for the ability to learn new things and incorporate them." 

General Cognitive Ability Test / Problem Solving



https://www.glassdoor.com/Interview/Questions-focus-on-general-cognitive-ability-marketing-strategy-knowledge-and-experience-leadership-skills-and-Googleyne-QTN_2417143.htm
I have a google hangout interview coming up in a few days regarding General Cognitive Ability / Problem Solving. This interview is basically a non technical interview testing my problem solving skills. No answer is necessarily right or wrong, they just want to see what steps i take to solve a problem. The recruiter was nice and gave me some examples of what this 1st interview would be like. He gave me some examples on what the type of questions they will be asking:
  1. There are 2 million businesses on Apps/GSuite. Let's say you were tasked to design and
build a customer support operation for our Apps/GSuite customers. How would you
proceed?
2. What is your favorite Google Cloud product? ​What are some things you could do to
minimize the cost of support? How would you assess the success of your support
operations?
3. If you were the chief traffic officer of New York City and someone asked you to
reduce traffic gridlock, what would be your steps to solving this?
The method that they are preferring me to answer these questions are pretty basic.
  1. Identify the problem & prepare:​ Ask questions to get a better picture of what the interviewers want out of this issue that they are having. Gain as much information as possible especially data that can be used in my solution that i am suggesting they take.
  2. Recommendations/Solutions:​ ​Walk the interviewer through the few solutions you have to solve the problem. explain them in a granular level the pros and cons of each solution, how i can overcome them and based on the analysis and frame work you've put together and present your recommendation.'
  3. Monitoring your solution moving forward:​ How are you going to monitor the data/recommendations moving forward? Make sure to address this!


https://harver.com/blog/cognitive-ability-assessments/












lp - the Linux printing command



https://www.networkworld.com/article/3373502/printing-from-the-linux-command-line.html
The lpstat -p command displays the status of a printer while lpstat -p -d also lists available printers.
With the -n option, the lp command allows you to specify the number of copies of a printout you  want.
$ lp -n 11 agenda
To cancel a print job, you can use the cancel or lprm command. If you don't act quickly, you might see this:
$ cancel 229
cancel: cancel-job failed: Job #229 is already completed - can't cancel.
To print in landscape mode, you would use the landscape option with the lp command.
$ lp -o landscape penguin.jpg


https://www.cups.org/doc/man-lp.html
-o media=size
Sets the page size to size. Most printers support at least the size names "a4", "letter", and "legal".
-o number-up={2|4|6|9|16}
Prints 2, 4, 6, 9, or 16 document (input) pages on each output page.
-o orientation-requested=4
Prints the job in landscape (rotated 90 degrees counter-clockwise).
-o orientation-requested=5
Prints the job in landscape (rotated 90 degrees clockwise).
-o orientation-requested=6
Prints the job in reverse portrait (rotated 180 degrees).
-o print-quality=3
-o print-quality=4
-o print-quality=5
Specifies the output quality - draft (3), normal (4), or best (5).
-o sides=one-sided
Prints on one side of the paper.
-o sides=two-sided-long-edge
Prints on both sides of the paper for portrait output.
-o sides=two-sided-short-edge
Prints on both sides of the paper for landscape output.




-t "name"
Sets the job name.
-H hh:mm
-H hold
-H immediate
-H restart
-H resume
Specifies when the job should be printed. A value of immediate will print the file immediately, a value of hold will hold the job indefinitely, and a UTC time value (HH:MM) will hold the job until the specified UTC (not local) time. Use a value of resume with the -i option to resume a held job. Use a value of restart with the -i option to restart a completed job.

To print from command line we need, first of all, to know which printers are available for our system and how are named. To do that, we use following command:
$ lpstat -a


https://www.computerhope.com/unix/ulpstat.htm
-a [printer(s)]Shows the accepting state of printer queues. If no printers are specified then all printers are listed.
-lShows a long listing of printers, classes, or jobs.


lp -d <printername> -o ColorModel=CMYK <filename.extension>
Set your printer default to color
sudo lpoptions -p the_printer -o <name=value>

Example: To make banana-color print in color by default on your computer:

sudo lpoptions -p the_printer -o ColorModel=CMYK

To change back to black and white:

sudo lpoptions -p the_printer -o ColorModel=Gray

Note Option commands vary by printer and model. To see available options for a specific printer:

lpoptions -p printername -l

https://unix.stackexchange.com/questions/68830/how-to-force-lp-from-cups-to-print-in-grayscale/68844#68844
Maybe you are looking for lpoptions ?
Use lpoptions -l in order to know what's the name for your printer.
You can play it like thi (example with an HP Photosmart) :
lp -o scaling=//100// -oColorModel=KGray image.jpg

lpoptions -d the_printer -l | grep -i color

https://www.math.wisc.edu/wiki/index.php/Examples
        lp -d P file.pdf  (send file to printer P - e.g. P=5)
        lp -o sides=one-sided file.pdf  (to each page on one side only)
        lp -o ColorModel=color file.pdf    (print in color)
        lp -o sides=two-sided-short-edge  file.pdf  (duplex along short edge instead of long)
        lp -o page-ranges=1  (print just page 1)
        lp -o page-ranges=1-4,7,9-12

You can combine these commands, for example:
        lp -o sides=two-sided-short-edge -o ColorModel=color file.pdf  (useful for printing tri-fold brochures)
lpoptions
Use the lpoptions command to save these options for later use. For example, you might want to do color printing to the printer on another floor, reserving the printer on your own floor for the normal grayscale prints. This command will ensure that anything you send to the 5th floor printer will be printed in color:
        lpoptions -d 5  ColorModel=color
your lpoptions commands are saved in the file ~/.cups/lpoptions. Typing lpoptions by itself will show you what your current printer setup is.
Checking the queue and cancelling jobs
Use the lpstat command to check the status of a queue and cancel to cancel jobs
       lpstat -d5 -t   (checks jobs on queue 5)
       cancel  5-241   (deletes job 5-241 from queue 5)
You can also cancel jobs using the printer icon which will appear in the top right hand corner of your screen when you start your job. To do this, open the printer icon, right click on your job and select cancel (not delete).

lpoptions -d the_printer -o ColorModel=color

https://stackoverflow.com/questions/33977512/how-to-send-send-cups-a-print-only-in-black-ink-command
- not work
The setting to print color as grey (from the ppd) is valid an is processed.
HPPJLColorAsGray/Print Color as Gray: False HighQuality * BlackInkOnly 
But the settings from the actual printout "overwrite" the default values (what makes sense to me) and in case color is in an document an this is printed with default values -- the colour ink is used. This behaviour can be controlled in the print dialogue generally. E.g. in libreoffice you can use an option "print text in black ink" this would result in real black text (not mixed as black from colors).
In LaTeX you can use \usepackage[monochrome]{xcolor} to force all text to black an so the use of the black ink.
Im my case I wanted to directly print to the print queue even though the default was set in the ppd to use BlackInkOnly it was not the case. After I added this option additionally as parameter to my print command it worked as I want it to be: color is printed in gray and only the black ink is used.
lpr  -P<printqueue> -o HPPJLColorAsGray=BlackInkOnly ...


https://docs.oracle.com/cd/E19082-01/819-7761/gfjex/index.html
  1. Set the system's default printer.

    # lpadmin -d [printer-name]
    -d printer-name specifies the name of the printer you are assigning as the system's default printer. If you don't specify printer-name, the system is set up with no default printer.
  2. Check the system's default printer.

    # lpstat -d
https://docs.oracle.com/cd/E19455-01/805-7229/printadmin-55845/index.html
# lpadmin -d [printer-name]

-d printer-nameName of the printer you are assigning as the system's default printer. If you don't specify printer-name, the system is set up with no default printer.

https://alvinalexander.com/unix/edu/examples/lp.shtml
This command prints the ".profile" file to the printer named "Sales". The -d option specifies the destination.
lp -dSales file1 file2 file3
This command prints the three files "file1", "file2", and "file3" to the printer named "Sales".
lp -i Sales-101 -H hold
This command places the print request Sales-101 on hold.
lp -i Sales-101 -H resume
This command resumes the print request Sales-101. The print request starts printing from page one unless you instruct it otherwise.
lp -i Sales-101 -H resume -P 4-
This command resumes the print request Sales-101, starting with page 4 of the print job. Note that the final hyphen (following the "4") is required.
The "lp" command can also be used as part of a pipeline. For instance, the following command will print the output of the "ps -ef" command to the default printer:
ps -ef | lp
https://www.jdyoung.com/2018/01/12/youre-going-print-print-efficiently/
Save Ink– Use grayscale as the default print setting and only switch to full color on the final version or for client-facing documents.
Fonts Matter– In 2014, a teenager discovered the government could save more than $200 million a year by using Garamond instead of Times New Roman when printing documents. You probably won’t save that much, but using thinner and lighter fonts like Garamond or Evergreen can save on ink.
Start Selectively Printing

Pull, not push
Many enterprise printing systems now offer a 'pull-printing' option. Instead of sitting at your desk and sending documents to a remote printer, pull-printing requires the user to manually enter a security code on the printer itself. This provides greater security, reduces uncollected paper left in the printer - and might even make people think twice before pushing the 'Print' button.



Friday, November 15, 2019

Flutter



Flutter: How we're building a UI framework for tomorrow at Google" by Eric Seidel
Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.


https://flutter.dev/
 flutter precache
 flutter doctor
Open plugin preferences (Preferences > Plugins on macOS, File > Settings > Plugins on Windows & Linux).
Select Marketplace, select the Flutter plugin and click Install.

  1. In the target selector, select an Android device for running the app. If none are listed as available, select Tools> Android > AVD Manager and create one there. For details, see Managing AVDs.
dart:ui:1: Error: Not found: dart:ui. flutter/dart:
When running the app, you will find 2 main.dart Choose the one with the flutter icon beside it enter image description here

Magically if you add:
import 'package:flutter/widgets.dart';
at the top of that file, and delete the existing configuration, it will run as flutter instead of dart.
https://github.com/flutter/flutter/issues/27826

https://flutter.dev/docs/get-started/codelab


  • This example creates a Material app. Material is a visual design language that is standard on mobile and the web. Flutter offers a rich set of Material widgets.
  • The main() method uses arrow (=>) notation. Use arrow notation for one-line functions or methods.
  • The app extends StatelessWidget which makes the app itself a widget. In Flutter, almost everything is a widget, including alignment, padding, and layout.
  • The Scaffold widget, from the Material library, provides a default app bar, title, and a body property that holds the widget tree for the home screen. The widget subtree can be quite complex.
  • A widget’s main job is to provide a build() method that describes how to display the widget in terms of other, lower level widgets.
  • The body for this example consists of a Center widget containing a Text child widget. The Center widget aligns its widget subtree to the center of the screen.

The pubspec file manages the assets and dependencies for a Flutter app. In pubspec.yaml
  1. While viewing the pubspec in Android Studio’s editor view, click Packages get. This pulls the package into your project. You should see the following in the console:

    $ flutter pub get
    Running "flutter pub get" in startup_namer...
    Process finished with exit code 0
    
    Performing Packages get also auto-generates the pubspec.lock file with a list of all packages pulled into the project and their version numbers.
source code:
https://github.com/flutter/codelabs/tree/master/startup_namer
If you would like to extend this app, proceed to part 2 on the Google Developers Codelabs site
https://codelabs.developers.google.com/


Thursday, September 12, 2019

Parameter order



https://softwareengineering.stackexchange.com/questions/101346/what-is-best-practice-on-ordering-parameters-in-a-function
 I don't over-think it, except for public API design.

Selection Funnel

  1. Semantics
  2. Importance / Relevance
  3. Frequency of Use
  4. I/O Concerns

1. Semantics First

Especially in OOP, pick parameters based on their semantical significance for the action or message. The signature of a well-named method with a well-named parameter should:
  • feel natural to call,
  • be self-descriptive in terms of intent and behavior.
(For these reasons, sometimes using custom types or aliases instead of primitives might increase the expressiveness of your signature.)

2. Then Importance

The most "significant" parameter comes first (or next...)

3. Then Frequency

The frequency matters as well, especially in a language where you don't have named parameters but can have default values on positional parameters. That implies that the order of the parameters doesn't vary, and that obviously you cannot set the N + 1 parameters if you want to force the default value of the Nth parameter (except if your language has a concept of a place-holder parameter).
The good news for you is that usually, frequency relates to importance, so that goes hand in hand with the previous point. And then it's probably up to you to craft your API for it to have the appropriate semantics.

4. Let's Not Forget I/O

if your method/function takes some input and produces an output, and the latter is not to be "returned" (via a return statement) or "thrown" (using an exception system), then you're left with the option to pass values back to the caller using your other parameters (or the input parameter). That relates to semantics, and in most cases it will make sense to have the first parameters define the output, and the last parameters receive the output.
Additionally, an other approach to have less parameters and maximise semantics would be to use a functional approach, or to define a Builder pattern, so you can clearly stack up your inputs, define your outputs, and retrieve them when need be.
  • If a language allows default values for parameters (such as C++, Sybase stored procedures), you obviously leave the optional parameters to be the last, and the less likely the parameter is to be specified with a value, the later in the list it should go.
  • Otherwise, order them in whatever logical grouping is most readable/maintainable.
    This may be a bit subjective - e.g. next/previous weight/height can be ordered next_weight,next_height, prev_weight, prev_height or next_weight, prev_weight, next_height, prev_height equally validly. Again, the 3 main considerations are readability/logicaleness for you, and ease of maintenance.
    As far as readability, you can order them by type, or by meaning.
    As far as "logicalness", you can order them by meaning (e.g. group all "next" together, or all heights together), OR by some order imposed elsewhere - for example, column order in a corresponding database table, or field order in a GUI (worse, as it's likely to change).
    As far as maintenance, if no obvious meaningful order crystallizes, alphanumeric order is the best since it allows VERY easy way to find a parameter by scanning and especially to decide where to insert a new parameter.

 group arguments of similar origin together

Saturday, September 7, 2019

Javadoc Best Practice



https://blog.codefx.org/java/new-javadoc-tags/
* @apiNote This method was added after the interface was released in
*          version 1.0. It is defined as a default method for compatibility
*          reasons. From version 2.0 on, the method will be abstract and
*          all implementations of this interface have to provide their own
*          implementation of the method.
* @implSpec The default implementation will consider each player a winner
*           and return them in an unspecified order.
* @implNote This implementation has linear runtime and does not filter out
*           null players.



https://stackoverflow.com/questions/11671989/best-practice-for-javadocs-interface-implementation-or-both?lq=1
If the implementing method doesn't provide its own Javadoc, there will still be a link to the interface method's docs. I never understood why Eclipse inserts /* (non-Javadoc) @see ... */ as the Javadocs will automatically reference the interface's docs.
The interface should have all the information about the contract, basically what the method does, the description of parameters, return values and so on.
Unless there's some extra information that isn't clear from the interface description (there rarely is), the implementation documentation should then simply link to the interface method

https://engdoc.corp.google.com/eng/doc/devguide/java/style/index.md?cl=head#s7-javadoc
Each paragraph except the first has <p> immediately before the first word, with no space after it
new paragraphs both be introduced with a blank line and be prefixed with <p>.

https://blog.joda.org/2012/11/javadoc-coding-standards.html
Do not use '**/' at the end of the Javadoc.
Use simple HTML tags, not valid XHTML

Define a punchy first sentence
The first sentence, typically ended by a dot, is used in the next-level higher Javadoc. As such, it has the responsibility of summing up the method or class to readers scanning the class or package. To achieve this, the first sentence should be clear and punchy, and generally short.
While not required, it is recommended that the first sentence is a paragraph to itself. This helps retain the punchiness for readers of the source code.
It is recommended to use the third person form at the start. For example, "Gets the foo", "Sets the "bar" or "Consumes the baz". Avoid the second person form, such as "Get the foo".

Use "this" to refer to an instance of the class
When referring to an instance of the class being documented, use "this" to reference it. For example, "Returns a copy of this foo with the bar value updated".
Aim for short single line sentences

Use @link and @code wisely
Many Javadoc descriptions reference other methods and classes. This can be achieved most effectively using the @link and @code features.
The @link feature creates a visible hyperlink in generated Javadoc to the target. The @link target is one of the following forms:
  /**
   * First paragraph.
   * <p>
   * Link to a class named 'Foo': {@link Foo}.
   * Link to a method 'bar' on a class named 'Foo': {@link Foo#bar}.
   * Link to a method 'baz' on this class: {@link #baz}.
   * Link specifying text of the hyperlink after a space: {@link Foo the Foo class}.
   * Link to a method handling method overload {@link Foo#bar(String,int)}.
   */
  public ...
The @code feature provides a section of fixed-width font, ideal for references to methods and class names. While @link references are checked by the Javadoc compiler, @code references are not.
Only use @link on the first reference to a specific class or method. Use @code for subsequent references. This avoids excessive hyperlinks cluttering up the Javadoc.

Define null-handling for all parameters and return types
Whether a method accepts null on input, or can return null is critical information for building large systems. All non-primitive methods should define their null-tolerance in the @param or @return. Some standard forms expressing this should be used wherever possible:
  • "not null" means that null is not accepted and passing in null will probably throw an exception , typically NullPointerException
  • "may be null" means that null may be passed in. In general the behaviour of the passed in null should be defined
  • "null treated as xxx" means that a null input is equivalent to the specified value
  • "null returns xxx" means that a null input always returns the specified value
When defined in this way, there should not be an @throws for NullPointerException.
  /**
   * Javadoc text.
   * 
   * @param foo  the foo parameter, not null
   * @param bar  the bar parameter, null returns null
   * @return the baz content, null if not processed
   */
  public String process(String foo, String bar) {...}





Sunday, September 1, 2019

How to Reduce Data Usage




3. See which apps are using the most data

Curious to know which apps are consuming the most data? Go to Settings > Cellularand you can see how much data you've used in the current billing period and below that you'll see a list of your apps. 

4. Disable Wi-Fi Assist

Wi-Fi Assist is a great feature where your iPhone hands off a weak Wi-Fi signal to your cellular network to prevent pages from loading slowly (or not at all) as it clings to the last remnants of a Wi-Fi signal. If you sit on the edge of a Wi-Fi network at work, say, then your cellular network may be assisting more than you'd like and running up data charges.
To disable Wi-Fi Assist, go to Settings > Cellular and scroll all the way to the bottom to turn off Wi-Fi Assist.

5. Download music, don't stream

For Apple Music, go to Settings > Music. In the Streaming & Downloads section, you'll see two settings if the first is enabled. The first, Use Cellular Data, lets you disable streaming via a cellular connection entirely. If that's too drastic a measure for you, then you can leave that setting enabled and turn off High Quality on Cellular to stream songs at a lower bitrate when you aren't on Wi-Fi.
For the Podcasts app, go to Settings > Podcasts and turn off Cellular Data. You can also enable Only Download on Wi-Fi to prevent podcast downloads from adding to your data usage.

7. Use Safari's Reading List

You can queue up articles while you're using Wi-Fi to read later when you're on a cellular connection or out of range completely. When you add a page to Safari's Reading List, Safari downloads it for offline viewing. To add an article to the Reading List, tap the Share button at the center of the bottom navigation bar and then tap Add to Reading List. If you use iCloud, then it will share your Reading List with your other iOS devices, but you can stop it from sharing via a cellular connection by going to Settings > Safari and scrolling down to the bottom and toggling off Use Cellular Datafor the Reading List feature.





https://www.telegraph.co.uk/technology/2016/04/10/how-to-reduce-your-android-or-iphone-data-usage/

4. Disable background app refresh
This is one for iPhone users only, but turning off background app refresh by entering Settings > General > and either turning off refresh altogether or going through and selecting individual apps will not only help to cut down on your data usage, it has the added bonus of helping to preserve your battery life. Win win!

Friday, August 30, 2019

A guide to ffmpeg



https://www.tecmint.com/ffmpeg-commands-for-video-audio-and-image-conversion-in-linux/
12. Increase/Reduce Video Playback Speed
To increase video play back speed, run this command. The -vf option sets the video filters that helps to adjust the speed.

$ ffmpeg -i video.mpg -vf "setpts=0.5*PTS" highspeed.mpg

ou can also reduce video speed as follows:

$ ffmpeg -i video.mpg -vf "setpts=4.0*PTS" lowerspeed.mpg -hide_banner

https://opensource.com/article/17/6/ffmpeg-convert-media-file-formats
FFmpeg to the rescue! You can select the codecs needed by using the -c flag.
This flag lets you set the different codec to use for each stream. For example, to set the audio stream to be Vorbis, you would use the following command:
ffmpeg -i input.mp3 -c:a libvorbis output.ogg
The same can be done to change the video as well as the audio stream:
ffmpeg -i input.mp4 -c:v vp9 -c:a libvorbis output.mkv
This will make a Matroska container with a VP9 video stream and a Vorbis audio stream, essentially the same as the WebM we made earlier.
The command ffmpeg -codecs will print every codec FFmpeg knows about.

Changing a single stream

More often than you'd like, the file you have is partially correct with only a single stream in the wrong format. It can be very time consuming to re-encode the correct stream. FFmpeg can help with this situation:
ffmpeg -i input.webm -c:v copy -c:a flac output.mkv
This command copies the video stream from input.webm into output.mkv and encodes the Vorbis audio stream into a FLAC. The -c flag is really powerful.

Changing a container

The prior example can be applied to both the audio and video streams, allowing you to convert from one container format to another without having to do any additional stream encoding:
ffmpeg -i input.webm -c:av copy output.mkv
Change the quality
ffmpeg -i input.webm -c:a copy -c:v vp9 -b:v 1M output.mkv
This will copy the audio (-c:a copy) from input.webm and convert the video to a VP9 codec (-c:v vp9) with a bit rate of 1M/s (-b:v), all bundled up in a Matroska container (output.mkv).
Another way we can impact quality is to adjust the frame rate of the video using the -roption:
ffmpeg -i input.webm -c:a copy -c:v vp9 -r 30 output.mkv
This creates a new Matroska with the audio stream copied over and the video stream's frame rate forced to 30 frames per second, instead of using the frame rate from the input (-r 30).
You can also adjust the dimensions of your video using FFmpeg. The simplest way is to use a predetermined video size:
ffmpeg -i input.mkv -c:a copy -s hd720 output.mkv
This modifies the video to 1280x720 in the output, but you can set the width and height manually if you want:
ffmpeg -i input.mkv -c:a copy -s 1280x720 output.mkv
This produces the exact same output as the earlier command. If you want to set custom sizes in FFmpeg, please remember that the width parameter (1280) comes before height (720).






https://catswhocode.com/ffmpeg-commands/

Get File Information From a Video File
ffmpeg -i video.avi

Convert Images To a Video Sequence
This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

ffmpeg -f image2 -i image%d.jpg video.mpg
Convert a Video to X Images
This command will generate imagess named image1.jpg, image2.jpg, etc, from a given video file. The following image formats are available: PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

ffmpeg -i video.mpg image%d.jpg
Crop a Video File
Cropping is a very common operation in video editing. FFmpeg provides a crop filter for this specific purpose:

ffmpeg -i input.mp4 -filter:v "crop=out_w:out_h:x:y" output.mp4
The options are as follows:

out_w is the width of the output rectangle
out_h is the height of the output rectangle
x and y specify the top left corner of the output rectangle
output.mp4 is the output file
Resize a Video
Using the -vf scale filter, it is possible to resize videos to a desired size:

ffmpeg -i input.avi -vf scale=320:240 output.avi
The same works with images as well:

ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png
Extract a Portion of a Video
Another very common operation on video files is to extract a specific portion of a given video. This can be done super easily:

ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
In the example above, we are cutting out a part starting at 00:00:30 into the original file with a 5 seconds length. -ss indicates the starting time, and -t indicates the duration.

Encode a Video Sequence for the iPod/iPhone
You can easily convert a video for iPhones and older iPods using this command:

ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4
Explanations :

Source : source_video.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Extract Sound From a Video, And Save It in Mp3 Format
Creating an audio file from a video is an easy task:

ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 sound.mp3
Explanations :

Source video : source_video.avi
Audio bitrate : 192kb/s
output: mp3 format
Generated sound : sound.mp3
Convert a Wav File to Mp3
FFmpeg isn’t only for videos, there’s a lot you can do with audio files as well. This example will convert a .wav file to mp3 format.

ffmpeg -i input_sound.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 output_sound.mp3


Image Overlay on a Video
Let’s finish this round-up with an advanced command. Here we are applying an overlay image to an existing video:

ffmpeg -i input.mp4 -i image.png -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4
Some explanations:

overlay=25:25: The image will be positioned 25px to the right and 25px down, originating from the top left corner (0:0).
enable='between(t,0,20)': The overlay image will be shown from 00:00:00 to 00:00:20
Youtube-dl is a nifty little tool you can use to grab videos from YouTube and several other video-streaming services. It's super straightforward to use:
youtube-dl https://www.youtube.com/watch?v=2m5nW9CQLJ0
https://medium.com/@dernis/ffmpeg-tips-tricks-and-and-lessons-learned-a6f3c1187085
https://gist.github.com/revolunet/57a84ae4353615561b0a



https://www.ffmpeg.org/
https://www.ffmpeg.org/ffmpeg.html
As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file. Exceptions from this rule are the global options (e.g. verbosity level), which should be specified first.
Do not mix input and output files – first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.
  • To set the video bitrate of the output file to 64 kbit/s:
    ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi
    
  • To force the frame rate of the output file to 24 fps:
    ffmpeg -i input.avi -r 24 output.avi
    
  • To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:
    ffmpeg -r 1 -i input.m2v -r 24 output.avi
    


https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg
Calculate the bitrate you need by dividing 1 GB by the video length in seconds. So, for a video of length 16:40 (1000 seconds), use a bitrate of 1000000 bytes/sec:
ffmpeg -i input.mp4 -b 1000000 output.mp4
Additional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24 — the lower, the higher the bitrate.
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4

Second command, using -crf 24 took a 255.3MB video I had and reduced it to 72.7MB without lowering the quality noticeably.
https://tutorials.technology/tutorials/52-How-to-convert-mkv-to-mp4-on-macOS.html
brew install ffmpeg
for f in *.mkv;do ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k -strict -2 "${f%mkv}mp4";done
https://unix.stackexchange.com/questions/35746/encode-with-ffmpeg-using-avi-to-mp4
for f in *.avi;do ffmpeg -i "$f"  -strict -2 "${f%avi}mp4";done
The command -strict -2 is necessitated by the AAC codec which is experimental, but works (libaac), if you add those two parameters. The output file is high-quality by default.
ffmpeg -i input.avi -strict -2 output.mp4
https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg


https://askubuntu.com/questions/19322/how-to-convert-rmvb-to-mp4-or-why-ffmpeg-doesnt-work


Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts