There is a function in R (trim) which removes the NODATA situated in the outer rim of a raster (entire external row or column made of nodata). It is realy simple but quite slow. I am looking for a similar function or algorithm in gdal to do that. Any idea?
This sounds like the equivalent of GIMP's "zealous crop"
This is doable with the -cutline option in gdal_translate, but then you need to create the vector representing the valid raster data extent yourself.
Postgres has the ST_MinConvexHull, taking the ST_Envelope of that would be equivalent to what you described. Sounds a bit like overkill, though.
An easier way is with SAGA's crop to data raster method, which is available via processing. That does both steps in one (and can also do multiple rasters in one go)