xref: /docs/en/application-dev/tools/mediatool.md (revision e41f4b71)
1# mediatool
2
3mediatool is a lightweight collection of command line utilities, by which you can manage media assets such as images and videos in the system gallery.
4
5## Prerequisites
6
7- The device is connected properly.
8- The developer mode is enabled.
9- You have run the **hdc shell** command to enter the command line execution mode.
10
11## Commands
12
13<!--Del-->
14
15### mediatool send
16  
17  ```shell
18  mediatool send <path-to-local-media-file> [-ts] [-tas] [-rf] [-urf]
19  ```
20  Sends images, audios, and videos in **\<path-to-local-media-file>** of the device to the media library for storage.  The original file names are used. If **\<path-to-local-media-file>** indicates a folder, all files in the folder are sent to the media library. After a file is successfully saved, the URI of the file is displayed.
21
22  By default, a thumbnail is generated in synchronous mode when a media file is being saved to the media library, and the source file in **\<path-to-local-media-file>** is deleted once the saving process is complete.
23   | Parameter              | Description            |
24  | ---- |--------------- |
25  | -ts | Creates a thumbnail in synchronous mode when an image or a video is being saved. The media file is displayed after the thumbnail is generated. However, the saving takes a longer time. This parameter is used by default.|
26  | -tas | Creates a thumbnail in asynchronous mode when an image or a video is being saved. This parameter conflicts with **-ts**. The media file is displayed before the thumbnail is generated, and the saving takes a shorter time.|
27  | -rf | Deletes the source file after a media file is saved. This parameter is used by default.|
28  | -urf | Retains the source file after a media file is saved. This parameter conflicts with **-rf**.|
29
30  **Example**
31  ```shell
32  > mediatool send /data/tmp/MyImage.jpg
33  file://media/Photo/3/IMG_1721381297_001/MyImage.jpg # The image is saved successfully, and the URI of the image is displayed.
34  ```
35
36### mediatool list
37  ```shell
38  mediatool list <resource-uri>
39  ```
40  Displays the information of a resource file specified by **\<resource-uri>** in the media library in CSV format.
41  For example, if the URI of image A in the media library is **file://media/Photo/3/IMG_1721381297_001/MyImage.jpg**, you can run **mediatool list file://media/Photo/3** or **mediatool list file://media/Photo/3/IMG_1721381297_001/MyImage.jpg** to display the resource information.
42
43  The following resource information is contained:
44  - uri: URI of the media resource.
45  - display_name: name of the media resource.
46  - data: path of the source file of the media resource on the device.
47
48  You can also set **\<resource-uri>** to **all**, which displays the information about all the resource files in the media library.
49
50  **Example**
51  ```shell
52  # Use a valid URI for query.
53  > mediatool list file://media/Photo/3
54  Table Name: Photos
55  uri, display_name, data
56  "file://media/Photo/3/IMG_1721381297_001/MyImage.jpg", "MyImage.jpg", "/storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg"
57
58  # Use an invalid URI for query.
59  > mediatool list file://media/Photo/
60  [FAIL] uri invalid. uri:file://media/Photo/
61  ```
62
63### mediatool recv
64
65```shell
66mediatool recv <resource-uri> <dest-path>
67```
68Exports the source file specified by **\<resource-uri>** in the media library to the device path specified by **\<dest-path>**. You can set **\<dest-path>** to the path of a file or folder. If it is set to a folder path, the file is exported to the folder and the source file name is used. If it is set to a file path, do not use the path of an existing file. In addition, **\<dest-path>** must be accessible. After the file is exported successfully, the path of the exported file is displayed.
69
70You can run **mediatool list all** or [mediatool query](#mediatool-query) to obtain the URI of a resource file in the media library.
71
72If **\<resource-uri>** is set to **all**, all resource files in the media library are exported. In this case, **\<dest-path>** must be a folder path.
73
74**Example**
75```shell
76> mediatool recv file://media/Photo/3 /data/out.jpg
77Table Name: Photos
78/data/out.jpg
79```
80
81### mediatool delete
82
83```shell
84mediatool delete <resource-uri>
85```
86
87Deletes a resource file specified by **\<resource-uri>** from the media library. Since the deleted resource cannot be recovered, exercise caution when use this command.
88
89You can run **mediatool list all** or **[mediatool query](#mediatool-query)** to obtain the URI of a resource file in the media library.
90
91If **\<resource-uri>** is set to **all**, all resource files in the media library are deleted and all data in the media library is reset.
92
93**Example**
94```shell
95> mediatool delete file://media/Photo/3
96[SUCCESS] delete success.
97
98> mediatool delete all # No information is displayed when the delete all command is executed successfully.
99```
100
101<!--DelEnd-->
102
103### mediatool query
104
105```shell
106mediatool query <display-name>
107```
108  Queries the path of a resource file specified by **\<display-name>** in the media library.
109  
110  **Example**
111
112  ```shell
113  # Query the media file that exists.
114  > mediatool query MyImage.jpg
115  find 1 result:
116  /storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg
117
118  # Query the media file that does not exist.
119  > mediatool query non_exist.jpg
120  The displayName you want to query do not exist!
121  find 0 result
122  
123  # Use an name in incorrect format for query.
124  > mediatool query IMG_001
125  The displayName format is not correct!
126  ```
127